comparison cpu_dsl.py @ 1748:48a43dff4dc0

Added init functions to z80_util.c so new Z80 core is closer to a drop in replacement for the old one
author Michael Pavone <pavone@retrodev.com>
date Thu, 07 Feb 2019 09:43:25 -0800
parents 89ddf41a50bb
children e4fe5a450d05
comparison
equal deleted inserted replaced
1747:89ddf41a50bb 1748:48a43dff4dc0
1279 self.carryFlowDst = None 1279 self.carryFlowDst = None
1280 self.lastA = None 1280 self.lastA = None
1281 self.lastB = None 1281 self.lastB = None
1282 self.lastBFlow = None 1282 self.lastBFlow = None
1283 self.conditional = False 1283 self.conditional = False
1284 self.declares = []
1284 1285
1285 def __str__(self): 1286 def __str__(self):
1286 pieces = [] 1287 pieces = []
1287 for reg in self.regs: 1288 for reg in self.regs:
1288 pieces.append(str(self.regs[reg])) 1289 pieces.append(str(self.regs[reg]))
1306 hFile.write('\n\tuint32_t cycles;') 1307 hFile.write('\n\tuint32_t cycles;')
1307 self.regs.writeHeader(otype, hFile) 1308 self.regs.writeHeader(otype, hFile)
1308 hFile.write('\n}} {0}context;'.format(self.prefix)) 1309 hFile.write('\n}} {0}context;'.format(self.prefix))
1309 hFile.write('\n') 1310 hFile.write('\n')
1310 hFile.write('\nvoid {pre}execute({type} *context, uint32_t target_cycle);'.format(pre = self.prefix, type = self.context_type)) 1311 hFile.write('\nvoid {pre}execute({type} *context, uint32_t target_cycle);'.format(pre = self.prefix, type = self.context_type))
1312 for decl in self.declares:
1313 hFile.write('\n' + decl)
1311 hFile.write('\n#endif //{0}_'.format(macro)) 1314 hFile.write('\n#endif //{0}_'.format(macro))
1312 hFile.write('\n') 1315 hFile.write('\n')
1313 hFile.close() 1316 hFile.close()
1314 1317
1315 def _buildTable(self, otype, table, body): 1318 def _buildTable(self, otype, table, body):
1489 def parse(f): 1492 def parse(f):
1490 instructions = {} 1493 instructions = {}
1491 subroutines = {} 1494 subroutines = {}
1492 registers = None 1495 registers = None
1493 flags = None 1496 flags = None
1497 declares = []
1494 errors = [] 1498 errors = []
1495 info = {} 1499 info = {}
1496 line_num = 0 1500 line_num = 0
1497 cur_object = None 1501 cur_object = None
1498 for line in f: 1502 for line in f:
1503 if line[0].isspace(): 1507 if line[0].isspace():
1504 if not cur_object is None: 1508 if not cur_object is None:
1505 parts = [el.strip() for el in line.split(' ')] 1509 parts = [el.strip() for el in line.split(' ')]
1506 if type(cur_object) is dict: 1510 if type(cur_object) is dict:
1507 cur_object[parts[0]] = parts[1:] 1511 cur_object[parts[0]] = parts[1:]
1512 elif type(cur_object) is list:
1513 cur_object.append(line.strip())
1508 else: 1514 else:
1509 cur_object = cur_object.processLine(parts) 1515 cur_object = cur_object.processLine(parts)
1510 1516
1511 # if type(cur_object) is Registers: 1517 # if type(cur_object) is Registers:
1512 # if len(parts) > 2: 1518 # if len(parts) > 2:
1560 cur_object = info 1566 cur_object = info
1561 elif line.strip() == 'flags': 1567 elif line.strip() == 'flags':
1562 if flags is None: 1568 if flags is None:
1563 flags = Flags() 1569 flags = Flags()
1564 cur_object = flags 1570 cur_object = flags
1571 elif line.strip() == 'declare':
1572 cur_object = declares
1565 else: 1573 else:
1566 cur_object = SubRoutine(line.strip()) 1574 cur_object = SubRoutine(line.strip())
1567 subroutines[cur_object.name] = cur_object 1575 subroutines[cur_object.name] = cur_object
1568 if errors: 1576 if errors:
1569 print(errors) 1577 print(errors)
1570 else: 1578 else:
1571 p = Program(registers, instructions, subroutines, info, flags) 1579 p = Program(registers, instructions, subroutines, info, flags)
1580 p.declares = declares
1572 p.booleans['dynarec'] = False 1581 p.booleans['dynarec'] = False
1573 p.booleans['interp'] = True 1582 p.booleans['interp'] = True
1574 1583
1575 if 'header' in info: 1584 if 'header' in info:
1576 print('#include "{0}"'.format(info['header'][0])) 1585 print('#include "{0}"'.format(info['header'][0]))