MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / main

Function main

tools/python-3.11.9-amd64/Tools/scripts/generate_opcode_h.py:73–173  ·  view source on GitHub ↗
(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h')

Source from the content-addressed store, hash-verified

71 out.write(f"}};\n")
72
73def main(opcode_py, outfile='Include/opcode.h', internaloutfile='Include/internal/pycore_opcode.h'):
74 opcode = {}
75 if hasattr(tokenize, 'open'):
76 fp = tokenize.open(opcode_py) # Python 3.2+
77 else:
78 fp = open(opcode_py) # Python 2.7
79 with fp:
80 code = fp.read()
81 exec(code, opcode)
82 opmap = opcode['opmap']
83 opname = opcode['opname']
84 hasconst = opcode['hasconst']
85 hasjrel = opcode['hasjrel']
86 hasjabs = opcode['hasjabs']
87 used = [ False ] * 256
88 next_op = 1
89
90 for name, op in opmap.items():
91 used[op] = True
92
93 specialized_opmap = {}
94 opname_including_specialized = opname.copy()
95 for name in opcode['_specialized_instructions']:
96 while used[next_op]:
97 next_op += 1
98 specialized_opmap[name] = next_op
99 opname_including_specialized[next_op] = name
100 used[next_op] = True
101 specialized_opmap['DO_TRACING'] = 255
102 opname_including_specialized[255] = 'DO_TRACING'
103 used[255] = True
104
105 with open(outfile, 'w') as fobj, open(internaloutfile, 'w') as iobj:
106 fobj.write(header)
107 iobj.write(internal_header)
108
109 for name in opname:
110 if name in opmap:
111 fobj.write(DEFINE.format(name, opmap[name]))
112 if name == 'POP_EXCEPT': # Special entry for HAVE_ARGUMENT
113 fobj.write(DEFINE.format("HAVE_ARGUMENT", opcode["HAVE_ARGUMENT"]))
114
115 for name, op in specialized_opmap.items():
116 fobj.write(DEFINE.format(name, op))
117
118 iobj.write("\nextern const uint8_t _PyOpcode_Caches[256];\n")
119 iobj.write("\nextern const uint8_t _PyOpcode_Deopt[256];\n")
120 iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")
121 write_int_array_from_ops("_PyOpcode_RelativeJump", opcode['hasjrel'], iobj)
122 write_int_array_from_ops("_PyOpcode_Jump", opcode['hasjrel'] + opcode['hasjabs'], iobj)
123
124 iobj.write("\nconst uint8_t _PyOpcode_Caches[256] = {\n")
125 for i, entries in enumerate(opcode["_inline_cache_entries"]):
126 if entries:
127 iobj.write(f" [{opname[i]}] = {entries},\n")
128 iobj.write("};\n")
129
130 deoptcodes = {}

Callers 1

Calls 11

write_int_array_from_opsFunction · 0.85
enumerateFunction · 0.85
sortedFunction · 0.85
openFunction · 0.50
printFunction · 0.50
openMethod · 0.45
readMethod · 0.45
itemsMethod · 0.45
copyMethod · 0.45
writeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected