add 'no' output to --with-system-ffi
[python/dscho.git] / Python / makeopcodetargets.py
blob5d8e5a9a461c3d9006734af9fbc0bc14cc204c52
1 #! /usr/bin/env python
2 """Generate C code for the jump table of the threaded code interpreter
3 (for compilers supporting computed gotos or "labels-as-values", such as gcc).
4 """
6 # This code should stay compatible with Python 2.3, at least while
7 # some of the buildbots have Python 2.3 as their system Python.
9 import imp
10 import os
13 def find_module(modname):
14 """Finds and returns a module in the local dist/checkout.
15 """
16 modpath = os.path.join(
17 os.path.dirname(os.path.dirname(__file__)), "Lib")
18 return imp.load_module(modname, *imp.find_module(modname, [modpath]))
20 def write_contents(f):
21 """Write C code contents to the target file object.
22 """
23 opcode = find_module("opcode")
24 targets = ['_unknown_opcode'] * 256
25 for opname, op in opcode.opmap.items():
26 if opname == "STOP_CODE":
27 # XXX opcode not implemented
28 continue
29 targets[op] = "TARGET_%s" % opname
30 f.write("static void *opcode_targets[256] = {\n")
31 f.write(",\n".join([" &&%s" % s for s in targets]))
32 f.write("\n};\n")
35 if __name__ == "__main__":
36 import sys
37 assert len(sys.argv) < 3, "Too many arguments"
38 if len(sys.argv) == 2:
39 target = sys.argv[1]
40 else:
41 target = "Python/opcode_targets.h"
42 f = open(target, "w")
43 try:
44 write_contents(f)
45 finally:
46 f.close()