diff options
author | Michael Pavone <pavone@retrodev.com> | 2019-01-25 14:30:55 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2019-01-25 14:30:55 -0800 |
commit | b802ec327873dd0bf3875efe13b178e10134b159 (patch) | |
tree | 407db312624f9c952d8cb45da404528e4d1fa7f2 | |
parent | 719b1c2d59c31fd210f4754d69e717e6332dde25 (diff) |
Output tables in order specified by the extra_tables field so the user can deal with dependencies between tables
-rwxr-xr-x | cpu_dsl.py | 52 |
1 files changed, 30 insertions, 22 deletions
@@ -953,14 +953,12 @@ class Program: hFile.write('\n#endif //{0}_'.format(macro)) hFile.write('\n') hFile.close() - def build(self, otype): - body = [] + + def _buildTable(self, otype, table, body): pieces = [] - for include in self.includes: - body.append('#include "{0}"\n'.format(include)) - for table in self.instructions: - opmap = [None] * (1 << self.opsize) - bodymap = {} + opmap = [None] * (1 << self.opsize) + bodymap = {} + if table in self.instructions: instructions = self.instructions[table] instructions.sort() for inst in instructions: @@ -973,17 +971,31 @@ class Program: self.lastOp = None opmap[val] = inst.generateName(val) bodymap[val] = inst.generateBody(val, self, otype) - - pieces.append('\ntypedef void (*impl_fun)({pre}context *context);'.format(pre=self.prefix)) - pieces.append('\nstatic impl_fun impl_{name}[{sz}] = {{'.format(name = table, sz=len(opmap))) - for inst in range(0, len(opmap)): - op = opmap[inst] - if op is None: - pieces.append('\n\tunimplemented,') - else: - pieces.append('\n\t' + op + ',') - body.append(bodymap[inst]) - pieces.append('\n};') + + pieces.append('\ntypedef void (*impl_fun)({pre}context *context);'.format(pre=self.prefix)) + pieces.append('\nstatic impl_fun impl_{name}[{sz}] = {{'.format(name = table, sz=len(opmap))) + for inst in range(0, len(opmap)): + op = opmap[inst] + if op is None: + pieces.append('\n\tunimplemented,') + else: + pieces.append('\n\t' + op + ',') + body.append(bodymap[inst]) + pieces.append('\n};') + body.extend(pieces) + + def build(self, otype): + body = [] + pieces = [] + for include in self.includes: + body.append('#include "{0}"\n'.format(include)) + body.append('\nstatic void unimplemented({pre}context *context)'.format(pre = self.prefix)) + body.append('\n{') + body.append('\n\tfatal_error("Unimplemented instruction");') + body.append('\n}\n') + for table in self.extra_tables: + self._buildTable(otype, table, body) + self._buildTable(otype, 'main', body) if self.body in self.subroutines: pieces.append('\nvoid {pre}execute({type} *context, uint32_t target_cycle)'.format(pre = self.prefix, type = self.context_type)) pieces.append('\n{') @@ -994,10 +1006,6 @@ class Program: self.subroutines[self.body].inline(self, [], pieces, otype, None) pieces.append('\n\t}') pieces.append('\n}') - body.append('\nstatic void unimplemented({pre}context *context)'.format(pre = self.prefix)) - body.append('\n{') - body.append('\n\tfatal_error("Unimplemented instruction");') - body.append('\n}\n') return ''.join(body) + ''.join(pieces) def checkBool(self, name): |