File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ from .model import Model , Memory
2+
3+ import struct
4+
5+ class Simulator :
6+ def __init__ (self , model ):
7+ self .model = model
8+ self .program = []
9+
10+ def load_program (self , program , * , address = 0 ):
11+ self .program = [i for i in program ]
12+
13+ def load_data (self , data = "" , * , address = 0 ):
14+ mem = self .model .state .memory .memory
15+ for a in range (int (len (data )/ 4 )):
16+ mem [a ] = struct .unpack ("<L" , data [a * 4 :(a + 1 )* 4 ])[0 ]
17+
18+ def run (self , * , pc = 0 ):
19+ self .model .reset (pc = pc )
20+ while True :
21+ try :
22+ self .model .issue (self .program [int (self .model .state .pc )>> 2 ])
23+ except IndexError as e :
24+ return
25+
26+ def dump_data (self , * , address = 0 , size = None ):
27+ data = b""
28+ mem = self .model .state .memory .memory
29+ for a in mem :
30+ if a >= address and (size is None or a < address + size ):
31+ data += struct .pack ("<L" , mem [a ])
32+ return data
You can’t perform that action at this time.
0 commit comments