Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ regen-limited-abi: all
# Regenerate all generated files

.PHONY: regen-all
regen-all: regen-cases regen-opcode regen-opcode-targets regen-typeslots \
regen-all: regen-cases regen-opcode regen-typeslots \
regen-token regen-ast regen-keyword regen-sre regen-frozen clinic \
regen-pegen-metaparser regen-pegen regen-test-frozenmain \
regen-test-levenshtein regen-global-objects
Expand Down Expand Up @@ -1428,8 +1428,10 @@ regen-opcode:
$(srcdir)/Lib/opcode.py \
$(srcdir)/Lib/_opcode_metadata.py \
$(srcdir)/Include/opcode.h.new \
$(srcdir)/Python/opcode_targets.h.new \
$(srcdir)/Include/internal/pycore_opcode.h.new
$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new
$(UPDATE_FILE) $(srcdir)/Include/internal/pycore_opcode.h $(srcdir)/Include/internal/pycore_opcode.h.new

.PHONY: regen-token
Expand Down Expand Up @@ -1531,13 +1533,6 @@ Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h
Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h

.PHONY: regen-opcode-targets
regen-opcode-targets:
# Regenerate Python/opcode_targets.h from Lib/opcode.py
# using Python/makeopcodetargets.py
$(PYTHON_FOR_REGEN) $(srcdir)/Python/makeopcodetargets.py \
$(srcdir)/Python/opcode_targets.h.new
$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new

.PHONY: regen-cases
regen-cases:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove the make target ``regen-opcode-targets``, merge its work into ``regen-opcode`` which repeats most of the calculation. This simplifies the code for the build and reduces code duplication.
4 changes: 1 addition & 3 deletions PCbuild/regen.targets
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
Inputs="@(_OpcodeSources)" Outputs="@(_OpcodeOutputs)"
DependsOnTargets="FindPythonForBuild">
<Message Text="Regenerate @(_OpcodeOutputs->'%(Filename)%(Extension)',' ')" Importance="high" />
<Exec Command="$(PythonForBuild) Tools\build\generate_opcode_h.py Lib\opcode.py Lib\_opcode_metadata.py Include\opcode.h Include\internal\pycore_opcode.h Include\internal\pycore_intrinsics.h"
WorkingDirectory="$(PySourcePath)" />
<Exec Command="$(PythonForBuild) Python\makeopcodetargets.py Python\opcode_targets.h"
<Exec Command="$(PythonForBuild) Tools\build\generate_opcode_h.py Lib\opcode.py Lib\_opcode_metadata.py Include\opcode.h Python/opcode_targets.h Include\internal\pycore_opcode.h Include\internal\pycore_intrinsics.h"
WorkingDirectory="$(PySourcePath)" />
</Target>

Expand Down
56 changes: 0 additions & 56 deletions Python/makeopcodetargets.py

This file was deleted.

12 changes: 11 additions & 1 deletion Tools/build/generate_opcode_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def get_python_module_dict(filename):
def main(opcode_py,
_opcode_metadata_py='Lib/_opcode_metadata.py',
outfile='Include/opcode.h',
opcode_targets_h='Python/opcode_targets.h',
internaloutfile='Include/internal/pycore_opcode.h'):

_opcode_metadata = get_python_module_dict(_opcode_metadata_py)
Expand Down Expand Up @@ -161,9 +162,18 @@ def main(opcode_py,
fobj.write(footer)
iobj.write(internal_footer)

with open(opcode_targets_h, "w") as f:
targets = ["_unknown_opcode"] * 256
for op, name in enumerate(opname_including_specialized):
if op < 256 and not name.startswith("<"):
targets[op] = f"TARGET_{name}"

f.write("static void *opcode_targets[256] = {\n")
f.write(",\n".join([f" &&{s}" for s in targets]))
f.write("\n};\n")

print(f"{outfile} regenerated from {opcode_py}")


if __name__ == '__main__':
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])