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 | print "\tCR_EXTEND_OPCODE=%d," % enum_index
|
---|
37 | enum_index = enum_index + 1
|
---|
38 | print "\tCR_CMDBLOCKBEGIN_OPCODE=%d," % enum_index
|
---|
39 | enum_index = enum_index + 1
|
---|
40 | print "\tCR_CMDBLOCKEND_OPCODE=%d," % enum_index
|
---|
41 | enum_index = enum_index + 1
|
---|
42 | print "\tCR_CMDBLOCKFLUSH_OPCODE=%d," % enum_index
|
---|
43 | print "\tCR_NOP_OPCODE=255"
|
---|
44 | if enum_index > 254:
|
---|
45 | # This would have saved Mike some grief if it had been here earlier.
|
---|
46 | print >> sys.stderr, "You have more than 255 opcodes! You've been adding functions to"
|
---|
47 | print >> sys.stderr, "glapi_parser/APIspec! Each new function you add"
|
---|
48 | print >> sys.stderr, "gets an opcode assigned to it. Fortunately for you, we have"
|
---|
49 | print >> sys.stderr, "an ``extend'' opcode. Please mark the function as"
|
---|
50 | print >> sys.stderr, "'extpack' in APIspec so as to keep the main opcode pool"
|
---|
51 | print >> sys.stderr, "less than 255! THIS IS A CATASTROPHIC FAILURE, and I WILL NOT CONTINUE!"
|
---|
52 | print >> sys.stderr, "I'm putting an error in the generated header file so you won't miss"
|
---|
53 | print >> sys.stderr, "this even if you're doing a 'make -k.'"
|
---|
54 | print "#error -- more than 255 opcodes!"
|
---|
55 | sys.exit(-1)
|
---|
56 | print "} CROpcode;\n"
|
---|
57 |
|
---|
58 | # count up number of extended opcode commands
|
---|
59 | num_extends = 0
|
---|
60 | num_auto_codes = 0
|
---|
61 | for func in keys:
|
---|
62 | if "extpack" in apiutil.ChromiumProps(func):
|
---|
63 | num_extends += 1
|
---|
64 | if apiutil.ChromiumRelOpCode(func) < 0:
|
---|
65 | num_auto_codes += 1
|
---|
66 |
|
---|
67 | # sanity check for compatibility breakage
|
---|
68 | # we currently have 304
|
---|
69 | if num_auto_codes != 304:
|
---|
70 | print >> sys.stderr, "number of auto-generated op-codes should be 304, but is " + str(num_auto_codes)
|
---|
71 | print >> sys.stderr, "which breaks backwards compatibility"
|
---|
72 | print >> sys.stderr, "if this is really what you want to do, please adjust this script"
|
---|
73 | print >> sys.stderr, "to handle a new auto-generated opcodes count"
|
---|
74 | print "#error -- num_auto_codes should be 304, but is " + str(num_auto_codes)
|
---|
75 | sys.exit(-1)
|
---|
76 |
|
---|
77 | print "/* Functions with a return value or output parameters */"
|
---|
78 | print "typedef enum {"
|
---|
79 |
|
---|
80 | opcode_index = 0
|
---|
81 | enum_index = 0
|
---|
82 | chrelopcodes = {}
|
---|
83 | for func in keys:
|
---|
84 | if "extpack" in apiutil.ChromiumProps(func):
|
---|
85 | opcodeName = apiutil.ExtendedOpcodeName(func)
|
---|
86 | chrelopcode = apiutil.ChromiumRelOpCode(func)
|
---|
87 | opcode = -1
|
---|
88 | if chrelopcode >= 0:
|
---|
89 | if not chrelopcode in chrelopcodes.keys():
|
---|
90 | chrelopcodes[chrelopcode] = chrelopcode
|
---|
91 | else:
|
---|
92 | print >> sys.stderr, "non-unique chrelopcode: " + str(chrelopcode)
|
---|
93 | print "#error -- non-unique chrelopcode: " + str(num_auto_codes)
|
---|
94 | sys.exit(-1)
|
---|
95 | opcode = num_auto_codes + chrelopcode
|
---|
96 | else:
|
---|
97 | opcode = opcode_index
|
---|
98 | opcode_index = opcode_index + 1
|
---|
99 |
|
---|
100 | if enum_index != num_extends-1:
|
---|
101 | print "\t%s = %d," % (opcodeName, opcode )
|
---|
102 | else:
|
---|
103 | print "\t%s = %d" % (opcodeName, opcode )
|
---|
104 | enum_index = enum_index + 1
|
---|
105 | print "} CRExtendOpcode;\n"
|
---|
106 | print "#endif /* CR_OPCODES_H */"
|
---|