def _generate_table(table, out): """Generates the implementation of a single table.""" out.block_comment( 'Implementation of table %s.' % table.name, 'Specified by: %s.' % table.citation ) out.enter_block('static inline const ClassDecoder &decode_%s(' 'const Instruction insn, const DecoderState *state)' % table.name) optimized = dgen_opt.optimize_rows(table.rows) print ("Table %s: %d rows minimized to %d" % (table.name, len(table.rows), len(optimized))) for row in sorted(optimized): exprs = ["(%s)" % p.to_c_expr('insn') for p in row.patterns] out.enter_block('if (%s)' % ' && '.join(exprs)) if row.action.startswith('='): _generate_terminal(row.action[1:], out) elif row.action.startswith('->'): _generate_table_change(row.action[2:], out) else: raise Exception('Bad table action: %s' % row.action) out.exit_block() out.line() _generate_safety_net(table, out) out.exit_block()
def _generate_table(table, out): """Generates the implementation of a single table.""" out.block_comment('Implementation of table %s.' % table.name, 'Specified by: %s.' % table.citation) out.enter_block('static inline const ClassDecoder &decode_%s(' 'const Instruction insn, const DecoderState *state)' % table.name) optimized = dgen_opt.optimize_rows(table.rows) print("Table %s: %d rows minimized to %d" % (table.name, len(table.rows), len(optimized))) for row in sorted(optimized): exprs = ["(%s)" % p.to_c_expr('insn') for p in row.patterns] out.enter_block('if (%s)' % ' && '.join(exprs)) if row.action.startswith('='): _generate_terminal(row.action[1:], out) elif row.action.startswith('->'): _generate_table_change(row.action[2:], out) else: raise Exception('Bad table action: %s' % row.action) out.exit_block() out.line() _generate_safety_net(table, out) out.exit_block()
def _generate_methods(decoder, values, out): global _cl_args for table in decoder.tables(): # Add the default row as the last in the optimized row, so that # it is applied if all other rows do not. opt_rows = sorted(dgen_opt.optimize_rows(table.rows(False))) if table.default_row: opt_rows.append(table.default_row) opt_rows = table.add_column_to_rows(opt_rows) print("Table %s: %d rows minimized to %d" % (table.name, len(table.rows()), len(opt_rows))) values['table_name'] = table.name values['citation'] = table.citation out.write(METHOD_HEADER % values) if _cl_args.get('trace') == 'True': out.write(METHOD_HEADER_TRACE % values) # Add message to stop compilation warnings if this table # doesn't require subtables to select a class decoder. if not table.methods(): out.write("\n UNREFERENCED_PARAMETER(inst);") count = 0 for row in opt_rows: count = count + 1 # Each row consists of a set of bit patterns defining if the row # is applicable. Convert this into a sequence of anded C test # expressions. For example, convert the following pair of bit # patterns: # # xxxx1010xxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxx0101 # # Each instruction is masked to get the the bits, and then # tested against the corresponding expected bits. Hence, the # above example is converted to: # # ((inst & 0x0F000000) != 0x0C000000) && # ((inst & 0x0000000F) != 0x00000005) out.write(METHOD_DISPATCH_BEGIN % row.patterns[0].to_commented_bool()) for p in row.patterns[1:]: out.write(METHOD_DISPATCH_CONTINUE % p.to_commented_bool()) out.write(METHOD_DISPATCH_END) if _cl_args.get('trace') == 'True': out.write(METHOD_DISPATCH_TRACE % count) if row.action.__class__.__name__ == 'DecoderAction': values['decoder'] = row.action.actual() out.write(METHOD_DISPATCH_CLASS_DECODER % values) elif row.action.__class__.__name__ == 'DecoderMethod': values['subtable_name'] = row.action.name out.write(METHOD_DISPATCH_SUBMETHOD % values) else: raise Exception('Bad table action: %s' % repr(row.action)) out.write(METHOD_DISPATCH_CLOSE % values) values['not_implemented'] = decoder.get_value( 'NotImplemented').actual() out.write(METHOD_FOOTER % values)
def _generate_methods(decoder, values, out): global _cl_args for table in decoder.tables(): # Add the default row as the last in the optimized row, so that # it is applied if all other rows do not. opt_rows = sorted(dgen_opt.optimize_rows(table.rows(False))) if table.default_row: opt_rows.append(table.default_row) opt_rows = table.add_column_to_rows(opt_rows) print ("Table %s: %d rows minimized to %d" % (table.name, len(table.rows()), len(opt_rows))) values['table_name'] = table.name values['citation'] = table.citation out.write(METHOD_HEADER % values) if _cl_args.get('trace') == 'True': out.write(METHOD_HEADER_TRACE % values) # Add message to stop compilation warnings if this table # doesn't require subtables to select a class decoder. if not table.methods(): out.write("\n UNREFERENCED_PARAMETER(inst);") count = 0 for row in opt_rows: count = count + 1 # Each row consists of a set of bit patterns defining if the row # is applicable. Convert this into a sequence of anded C test # expressions. For example, convert the following pair of bit # patterns: # # xxxx1010xxxxxxxxxxxxxxxxxxxxxxxx # xxxxxxxxxxxxxxxxxxxxxxxxxxxx0101 # # Each instruction is masked to get the the bits, and then # tested against the corresponding expected bits. Hence, the # above example is converted to: # # ((inst & 0x0F000000) != 0x0C000000) && # ((inst & 0x0000000F) != 0x00000005) out.write(METHOD_DISPATCH_BEGIN % row.patterns[0].to_commented_bool()) for p in row.patterns[1:]: out.write(METHOD_DISPATCH_CONTINUE % p.to_commented_bool()) out.write(METHOD_DISPATCH_END) if _cl_args.get('trace') == 'True': out.write(METHOD_DISPATCH_TRACE % count) if row.action.__class__.__name__ == 'DecoderAction': values['decoder'] = row.action.actual() out.write(METHOD_DISPATCH_CLASS_DECODER % values) elif row.action.__class__.__name__ == 'DecoderMethod': values['subtable_name'] = row.action.name out.write(METHOD_DISPATCH_SUBMETHOD % values) else: raise Exception('Bad table action: %s' % repr(row.action)) out.write(METHOD_DISPATCH_CLOSE % values) values['not_implemented'] = decoder.get_value('NotImplemented').actual() out.write(METHOD_FOOTER % values)
def _generate_table(t, out): rows = dgen_opt.optimize_rows(t.rows) print("Table %s: %d rows minimized to %d." % (t.name, len(t.rows), len(rows))) out.write("\n") out.write("-- %s (%s)\n" % (t.name, t.citation)) num_cols = len(rows[0].patterns) headers = ["pat%- 31s" % (str(n) + "(31:0)") for n in range(0, num_cols)] out.write("".join(headers)) out.write("\n") for row in rows: out.write("".join(["%- 34s" % p for p in row.patterns])) out.write(row.action) if row.arch: out.write("(%s)" % row.arch) out.write("\n")
def _generate_table(t, out): rows = dgen_opt.optimize_rows(t.rows) print('Table %s: %d rows minimized to %d.' % (t.name, len(t.rows), len(rows))) out.write('\n') out.write('-- %s (%s)\n' % (t.name, t.citation)) num_cols = len(rows[0].patterns) headers = ['pat%- 31s' % (str(n) + '(31:0)') for n in range(0, num_cols)] out.write(''.join(headers)) out.write('\n') for row in rows: out.write(''.join(['%- 34s' % p for p in row.patterns])) out.write(row.action) if row.arch: out.write('(%s)' % row.arch) out.write('\n')
def _generate_table(t, out): rows = dgen_opt.optimize_rows(t.rows) print ('Table %s: %d rows minimized to %d.' % (t.name, len(t.rows), len(rows))) out.write('\n') out.write('-- %s (%s)\n' % (t.name, t.citation)) num_cols = len(rows[0].patterns) headers = ['pat%- 31s' % (str(n) + '(31:0)') for n in range(0, num_cols)] out.write(''.join(headers)) out.write('\n') for row in rows: out.write(''.join(['%- 34s' % p for p in row.patterns])) out.write(row.action) if row.arch: out.write('(%s)' % row.arch) out.write('\n')