1 | # Copyright (c) 2001, Stanford University
|
---|
2 | # All rights reserved.
|
---|
3 | #
|
---|
4 | # See the file LICENSE.txt for information on redistributing this software.
|
---|
5 |
|
---|
6 | # This script generates include/cr_opcodes.h from the gl_header.parsed file.
|
---|
7 |
|
---|
8 | import sys;
|
---|
9 | import cPickle;
|
---|
10 | import string;
|
---|
11 | import re;
|
---|
12 |
|
---|
13 | import apiutil
|
---|
14 |
|
---|
15 | apiutil.CopyrightC()
|
---|
16 |
|
---|
17 | print ""
|
---|
18 | print "/* DO NOT EDIT - THIS FILE GENERATED BY THE opcodes.py SCRIPT */"
|
---|
19 | print ""
|
---|
20 | print "#ifndef CR_OPCODES_H"
|
---|
21 | print "#define CR_OPCODES_H"
|
---|
22 | print ""
|
---|
23 |
|
---|
24 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
25 | assert len(keys) > 0
|
---|
26 |
|
---|
27 | print "/* Functions with no return value and input-only parameters */"
|
---|
28 | print "typedef enum {"
|
---|
29 |
|
---|
30 | enum_index = 0
|
---|
31 | for func in keys:
|
---|
32 | if "pack" in apiutil.ChromiumProps(func):
|
---|
33 | print "\t%s = %d," % ( apiutil.OpcodeName(func), enum_index )
|
---|
34 | enum_index = enum_index + 1
|
---|
35 |
|
---|
36 | if enum_index > 255:
|
---|
37 | # This would have saved Mike some grief if it had been here earlier.
|
---|
38 | print >> sys.stderr, "You have more than 255 opcodes! You've been adding functions to"
|
---|
39 | print >> sys.stderr, "glapi_parser/APIspec! Each new function you add"
|
---|
40 | print >> sys.stderr, "gets an opcode assigned to it. Fortunately for you, we have"
|
---|
41 | print >> sys.stderr, "an ``extend'' opcode. Please mark the function as"
|
---|
42 | print >> sys.stderr, "'extpack' in APIspec so as to keep the main opcode pool"
|
---|
43 | print >> sys.stderr, "less than 255! THIS IS A CATASTROPHIC FAILURE, and I WILL NOT CONTINUE!"
|
---|
44 | print >> sys.stderr, "I'm putting an error in the generated header file so you won't miss"
|
---|
45 | print >> sys.stderr, "this even if you're doing a 'make -k.'"
|
---|
46 | print "#error -- more than 255 opcodes!"
|
---|
47 | sys.exit(-1)
|
---|
48 | print "\tCR_EXTEND_OPCODE=%d" % enum_index
|
---|
49 | print "} CROpcode;\n"
|
---|
50 |
|
---|
51 | # count up number of extended opcode commands
|
---|
52 | num_extends = 0
|
---|
53 | num_auto_codes = 0
|
---|
54 | for func in keys:
|
---|
55 | if "extpack" in apiutil.ChromiumProps(func):
|
---|
56 | num_extends += 1
|
---|
57 | if apiutil.ChromiumRelOpCode(func) < 0:
|
---|
58 | num_auto_codes += 1
|
---|
59 |
|
---|
60 | # sanity check for compatibility breakage
|
---|
61 | # we currently have 304
|
---|
62 | if num_auto_codes != 304:
|
---|
63 | print >> sys.stderr, "number of auto-generated op-codes should be 304, but is " + str(num_auto_codes)
|
---|
64 | print >> sys.stderr, "which breaks backwards compatibility"
|
---|
65 | print >> sys.stderr, "if this is really what you want to do, please adjust this script"
|
---|
66 | print >> sys.stderr, "to handle a new auto-generated opcodes count"
|
---|
67 | print "#error -- num_auto_codes should be 304, but is " + str(num_auto_codes)
|
---|
68 | sys.exit(-1)
|
---|
69 |
|
---|
70 | print "/* Functions with a return value or output parameters */"
|
---|
71 | print "typedef enum {"
|
---|
72 |
|
---|
73 | opcode_index = 0
|
---|
74 | enum_index = 0
|
---|
75 | chrelopcodes = {}
|
---|
76 | for func in keys:
|
---|
77 | if "extpack" in apiutil.ChromiumProps(func):
|
---|
78 | opcodeName = apiutil.ExtendedOpcodeName(func)
|
---|
79 | chrelopcode = apiutil.ChromiumRelOpCode(func)
|
---|
80 | opcode = -1
|
---|
81 | if chrelopcode >= 0:
|
---|
82 | if not chrelopcode in chrelopcodes.keys():
|
---|
83 | chrelopcodes[chrelopcode] = chrelopcode
|
---|
84 | else:
|
---|
85 | print >> sys.stderr, "non-unique chrelopcode: " + str(chrelopcode)
|
---|
86 | print "#error -- non-unique chrelopcode: " + str(num_auto_codes)
|
---|
87 | sys.exit(-1)
|
---|
88 | opcode = num_auto_codes + chrelopcode
|
---|
89 | else:
|
---|
90 | opcode = opcode_index
|
---|
91 | opcode_index = opcode_index + 1
|
---|
92 |
|
---|
93 | if enum_index != num_extends-1:
|
---|
94 | print "\t%s = %d," % (opcodeName, opcode )
|
---|
95 | else:
|
---|
96 | print "\t%s = %d" % (opcodeName, opcode )
|
---|
97 | enum_index = enum_index + 1
|
---|
98 | print "} CRExtendOpcode;\n"
|
---|
99 | print "#endif /* CR_OPCODES_H */"
|
---|