def EmitEnumsC(fout): for cls, info in CLASSES.items(): if info[0] is UNSUPPORTED: continue if info[0] is FLAG: cgen.RenderEnumToStringMapFlag(cgen.NameValues(cls), cls.__name__, fout) cgen.RenderEnumToStringFun(cls.__name__, fout) elif info[1] in {8, 16}: cgen.RenderEnumToStringMap(cgen.NameValues(cls), cls.__name__, fout) cgen.RenderEnumToStringFun(cls.__name__, fout) elif info[1] == 32: for n, first in enumerate(info[2]): if first == -1: continue last = info[2][n + 1] cgen.RenderEnumToStringMap(_EnumGenerator(cls, first, last), f"{cls.__name__ }_{first:x}", fout, first) if __name__ == "__main__": import sys if len(sys.argv) <= 1: EmitEnumsH(sys.stdout) elif sys.argv[1] == "gen_h": cgen.ReplaceContent(EmitEnumsH, sys.stdin, sys.stdout) elif sys.argv[1] == "gen_c": cgen.ReplaceContent(EmitEnumsC, sys.stdin, sys.stdout)
cgen.RenderEnumToStringMap(cgen.NameValues(IMM_KIND), "IMM_KIND", fout) cgen.RenderEnumToStringFun("IMM_KIND", fout) def _DumpCodeSelTable(): for i in range(256): patterns = Pattern.Table.get(i) if patterns is None: continue opcode = o.Opcode.TableByNo[i] print(f"{opcode.name} [{' '.join([k.name for k in opcode.operand_kinds])}]") for pat in patterns: print(f" [{' '.join([o.name if o else '*' for o in pat.constraints])}]") for opcode, operands in pat.emit: ops = [str(x) if isinstance(x, int) else x.name for x in operands] print(f" {opcode.name} [{' '.join(ops)}]") if __name__ == "__main__": import sys if len(sys.argv) > 1: if sys.argv[1] == "documentation": pass elif sys.argv[1] == "gen_h": cgen.ReplaceContent(_EmitCodeH, sys.stdin, sys.stdout) elif sys.argv[1] == "gen_c": cgen.ReplaceContent(_EmitCodeC, sys.stdin, sys.stdout) else: _DumpCodeSelTable()
last += 1 emit_one(o) print("};\n") def Dump(): last = None for opc in Opcode.Table.values(): if opc.kind != last: print() last = opc.kind ops = [_render_operand_desc(a, b, c) for a, b, c in zip(opc.purpose, opc.operand_kinds, opc.constraints)] print(f"{opc.kind.name} {opc.name} {' '.join(ops)}") print("total opcodes: %d" % len(Opcode.Table)) if __name__ == "__main__": import sys if len(sys.argv) > 1: if sys.argv[1] == "documentation": cgen.ReplaceContent(_render_documentation, sys.stdin, sys.stdout) elif sys.argv[1] == "gen_h": cgen.ReplaceContent(_render_h, sys.stdin, sys.stdout) elif sys.argv[1] == "gen_c": cgen.ReplaceContent(_render_c, sys.stdin, sys.stdout) else: Dump()