4 from os
.path
import dirname
, join
6 from collections
import OrderedDict
9 def find_wiki_file(name
):
10 filedir
= os
.path
.dirname(os
.path
.abspath(__file__
))
11 tabledir
= join(filedir
, 'isatables')
12 file_path
= join(tabledir
, name
)
16 file_path
= find_wiki_file(name
)
17 with
open(file_path
, 'r') as csvfile
:
18 reader
= csv
.DictReader(csvfile
)
22 #for v in row.values():
23 # if 'SPR' in v: # skip all SPRs
25 for v
in row
.values():
31 keycolumns
= ['in1', 'in2', 'in3', 'out', 'CR in', 'CR out',
32 'ldst len'] # don't think we need these: , 'rc', 'lk']
37 for key
in keycolumns
:
39 if key
in ['in1', 'in2', 'in3']:
40 # TODO: replace this with a counter row['in']
41 # will need row['in'] initialising to 0 *outside* of the for-loop
42 if row
[key
].startswith('R'):
48 if row
[key
].startswith('R'):
53 if key
.startswith('CR'):
54 if row
[key
].startswith('NONE'):
59 if key
.startswith('ldst'):
60 if row
[key
].startswith('NONE'):
65 if key
in ['rc', 'lk']:
68 elif row
[key
] == 'NONE':
79 for k
, v
in d
.items():
80 res
.append("%s: %s" % (k
, v
))
84 return ' | '.join(d
) + "|"
91 dictkeys
= OrderedDict()
93 pth
= find_wiki_file("*.csv")
94 for fname
in glob(pth
):
102 csvname
= os
.path
.split(fname
)[1]
108 dkey
= create_key(row
)
109 key
= tuple(dkey
.values())
114 bykey
[key
].append((csvname
, row
['opcode'], row
['comment'],
115 row
['form'].upper() + '-Form'))
117 primarykeys
= list(primarykeys
)
122 print ('[[!table data="""')
123 print (tformat(keycolumns
)) # TODO use alternative here which has
124 # 'in' rather than in1, in2, in3
126 for key
in primarykeys
:
127 print (tformat(dictkeys
[key
].values()))
131 for key
in primarykeys
:
132 print ("## ", dformat(dictkeys
[key
]))
134 print ('[[!table data="""')
135 print (tformat(['CSV', 'opcode', 'asm', 'form']))
144 for fname
, csv
in csvs
.items():
147 if __name__
== '__main__':