1313
1414from __future__ import print_function
1515
16+ import sys
1617
1718_py_flags = ['AN' , 'AZ' , 'AC' , 'AV' , 'AVS' , 'BN' , 'BIS' , 'BUS' , 'BVS' , 'BZ' ]
1819
2425def parse_pydgin_inst (line ):
2526 """Parse a single line of a Pydgin trace.
2627 Keep the original line for debugging purposes.
27-
28- >>> i0 = parse_pydgin_inst(' 0 00002ce8 bcond32 0 AN=False')
29- >>> ex0 = {'AN': False, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'pc': 0}
30- >>> i0 == ex0
31- True
32-
33- >>> i1 = parse_pydgin_inst(' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300')
34- >>> ex1 = {'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300', 'mem': [(760, 0)], 'pc': 176, 'reg': [768]}
35- >>> i1 == ex1
36- True
3728 """
3829 inst = dict ()
3930 if (line .startswith ('NOTE:' ) or line .startswith ('sparse' ) or
40- line .startswith ('DONE!' ) or line .startswith ('Instructions' )):
31+ line .startswith ('DONE!' ) or line .startswith ('Instructions' )):
4132 return None
4233 tokens = line .split ()
4334 if not tokens :
@@ -85,16 +76,6 @@ def parse_pydgin_inst(line):
8576def parse_esim_inst (line ):
8677 """Parse a single line of an e-sim trace.
8778 Keep the original line for debugging purposes.
88-
89- >>> i0 = parse_esim_inst('0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0')
90- >>> ex0 = {'AN': False, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'pc': 0}
91- >>> i0 == ex0
92- True
93-
94- >>> i1 = parse_esim_inst('0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300')
95- >>> ex1 = {'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300', 'mem': [(760, 0), (764, 0)], 'pc': 176, 'reg': [768]}
96- >>> i1 == ex1
97- True
9879 """
9980 inst = dict ()
10081 tokens = line .split ()
@@ -160,7 +141,7 @@ def diff_files(trace0, trace1):
160141 if len (py_trace ) == 0 :
161142 print ('Revelation trace is empty' )
162143 return
163- for num , (py_inst , e_inst ) in enumerate (zip (py_trace , e_trace )):
144+ for _ , (py_inst , e_inst ) in enumerate (zip (py_trace , e_trace )):
164145 diff = compare_instructions (py_inst , e_inst )
165146 if diff is not None :
166147 print ('Semantics of instruction at {0} differ:' .format (hex (e_inst ['pc' ])))
@@ -179,19 +160,6 @@ def compare_instructions(py_inst, e_inst):
179160 at each block of 4 bytes. For example, where the Pydgin trace would say:
180161 "WR.MEM[000002f8] = 00000000", the e-sim would write out:
181162 "memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0,"
182-
183- >>> e_inst0 = {'pc': 0, 'line': '0x000000 b.l 0x0000000000000058 - pc <- 0x58 - nbit <- 0x0', 'AN': False}
184- >>> e_inst1 = {'mem': [(760, 0), (764, 0)], 'pc': 176, 'line': '0x0000b0 --- _epiphany_star strd r2,[r0],+0x1 - memaddr <- 0x2f8, memory <- 0x0, memaddr <- 0x2fc, memory <- 0x0, registers <- 0x300', 'reg': [768]}
185- >>> py_inst0 = {'pc': 0, 'line': ' 0 00002ce8 bcond32 0 AN=False', 'AN': False}
186- >>> py_inst1 = {'mem': [(760, 0), (764, 0)], 'pc': 176, 'line': ' b0 020040fc ldstrpmd32 13 :: RD.RF[0 ] = 000002f8 :: :: WR.MEM[000002f8] = 00000000 :: WR.RF[0 ] = 00000300', 'reg': [768]}
187- >>> compare_instructions(py_inst0, e_inst0) is None
188- True
189- >>> compare_instructions(py_inst1, e_inst1) is None
190- True
191- >>> compare_instructions(py_inst0, e_inst1)
192- 'Program counters differ. Revelation: 0x0, e-sim: 0xb0'
193- >>> compare_instructions(py_inst1, e_inst0)
194- 'Program counters differ. Revelation: 0xb0, e-sim: 0x0'
195163 """
196164 if py_inst ['pc' ] != e_inst ['pc' ]:
197165 return ('Program counters differ. ' +
@@ -225,8 +193,8 @@ def compare_instructions(py_inst, e_inst):
225193 for flag in _py_flags :
226194 # e-sim only prints flags if they have been updated.
227195 if (flag in py_inst and
228- flag in e_inst and
229- not (py_inst [flag ] == e_inst [flag ])):
196+ flag in e_inst and
197+ not (py_inst [flag ] == e_inst [flag ])):
230198 return ('Flags differ. Revelation: {0}<-{1} ' +
231199 'e-sim: {2}<-{3}' ).format (flag , str (py_inst [flag ]),
232200 flag , str (e_inst [flag ]))
@@ -241,7 +209,6 @@ def print_usage():
241209
242210
243211if __name__ == '__main__' :
244- import sys
245212 if sys .argv [1 ] == '-h' or sys .argv [1 ] == '--help' :
246213 print_usage ()
247214 sys .exit (0 )
0 commit comments