summaryrefslogtreecommitdiff
path: root/helper/convert-artix7.py
blob: 5a4871a46b7f7881445efa7216046c6ea3c35184 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
print('DEF XC7A200TFBG484 IC 0 40 Y Y 17 F N')
print('F0 "U" -410 -910 60 H V L BNN')
print('F1 "" 0 0 60 H V C CNN')
print('F2 "" 0 0 60 H V C CNN')
print('F3 "" 0 0 60 H V C CNN')
print('DRAW')

def print_rec(r):
    for i in range(len(r)):
        ri = r[i]
        if i > 0: print(' ', end='')
        print(ri, end='')
        
    print("\n", end='')

SKIP_REC_TYPES = ['#', 'F0', 'F1', 'F2', 'F3', 'DRAW', 'ENDDRAW', 'ENDDEF']

with open('artix7.old', 'r') as f_rd:
    f_rd_lines = f_rd.readlines()
    
    for f_rd_line in f_rd_lines:
        rd_line = f_rd_line.strip()
        
        #if rd_line.startswith('#'): continue
        #if rd_line.startswith('DEF '): continue
        #if rd_line.startswith('ENDDEF'): continue
        #if rd_line.startswith('DRAW'): continue
        #if rd_line.startswith('ENDDRAW'): continue
        
        rec = rd_line.split(' ')
        rec_type = rec[0]
    
        #
        # DEF
        #
        if rec_type == "DEF":
            unit = rec[1].split('_')[1]
            continue

        #
        # T
        #
        if rec_type == "T":
            rec[6] = unit
            print_rec(rec)
            continue
        
        #
        # P
        #
        if rec_type == "P":
            rec[2] = unit
            print_rec(rec)
            continue
        
        #
        # X
        #
        if rec_type == "X":
            rec[-3] = unit
            print_rec(rec)
            continue

        if rec_type in SKIP_REC_TYPES: continue
        else: raise RuntimeError("rec_type == '%s'" % rec_type)    
    
        print(rd_line)
        

print('ENDDRAW')
print('ENDDEF')