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 | import sys
|
---|
7 |
|
---|
8 | import apiutil
|
---|
9 |
|
---|
10 |
|
---|
11 | apiutil.CopyrightC()
|
---|
12 |
|
---|
13 | print """/* DO NOT EDIT! THIS CODE IS AUTOGENERATED BY unpack.py */
|
---|
14 |
|
---|
15 | #include "unpacker.h"
|
---|
16 | #include "cr_opcodes.h"
|
---|
17 | #include "cr_error.h"
|
---|
18 | #include "cr_mem.h"
|
---|
19 | #include "cr_spu.h"
|
---|
20 | #include "unpack_extend.h"
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <memory.h>
|
---|
23 |
|
---|
24 | #include <iprt/cdefs.h>
|
---|
25 |
|
---|
26 | DECLEXPORT(const unsigned char *) cr_unpackData = NULL;
|
---|
27 | SPUDispatchTable cr_unpackDispatch;
|
---|
28 |
|
---|
29 | static void crUnpackExtend(void);
|
---|
30 | static void crUnpackExtendDbg(void);
|
---|
31 |
|
---|
32 | /*#define CR_UNPACK_DEBUG_OPCODES*/
|
---|
33 | /*#define CR_UNPACK_DEBUG_LAST_OPCODES*/
|
---|
34 | """
|
---|
35 |
|
---|
36 | nodebug_opcodes = [
|
---|
37 | "CR_MULTITEXCOORD2FARB_OPCODE",
|
---|
38 | "CR_VERTEX3F_OPCODE",
|
---|
39 | "CR_NORMAL3F_OPCODE",
|
---|
40 | "CR_COLOR4UB_OPCODE",
|
---|
41 | "CR_LOADIDENTITY_OPCODE",
|
---|
42 | "CR_MATRIXMODE_OPCODE",
|
---|
43 | "CR_LOADMATRIXF_OPCODE",
|
---|
44 | "CR_DISABLE_OPCODE",
|
---|
45 | "CR_COLOR4F_OPCODE",
|
---|
46 | "CR_ENABLE_OPCODE",
|
---|
47 | "CR_BEGIN_OPCODE",
|
---|
48 | "CR_END_OPCODE",
|
---|
49 | "CR_SECONDARYCOLOR3FEXT_OPCODE"
|
---|
50 | ]
|
---|
51 |
|
---|
52 | nodebug_extopcodes = [
|
---|
53 | "CR_ACTIVETEXTUREARB_EXTEND_OPCODE"
|
---|
54 | ]
|
---|
55 |
|
---|
56 | #
|
---|
57 | # Useful functions
|
---|
58 | #
|
---|
59 |
|
---|
60 | def ReadData( offset, arg_type ):
|
---|
61 | """Emit a READ_DOUBLE or READ_DATA call for pulling a GL function
|
---|
62 | argument out of the buffer's operand area."""
|
---|
63 | if arg_type == "GLdouble" or arg_type == "GLclampd":
|
---|
64 | retval = "READ_DOUBLE( %d )" % offset
|
---|
65 | else:
|
---|
66 | retval = "READ_DATA( %d, %s )" % (offset, arg_type)
|
---|
67 | return retval
|
---|
68 |
|
---|
69 |
|
---|
70 | def FindReturnPointer( return_type, params ):
|
---|
71 | """For GL functions that return values (either as the return value or
|
---|
72 | through a pointer parameter) emit a SET_RETURN_PTR call."""
|
---|
73 | arg_len = apiutil.PacketLength( params )
|
---|
74 | if (return_type != 'void'):
|
---|
75 | print '\tSET_RETURN_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
|
---|
76 | else:
|
---|
77 | paramList = [ ('foo', 'void *', 0) ]
|
---|
78 | print '\tSET_RETURN_PTR( %d );' % (arg_len + 8 - apiutil.PacketLength(paramList))
|
---|
79 |
|
---|
80 |
|
---|
81 | def FindWritebackPointer( return_type, params ):
|
---|
82 | """Emit a SET_WRITEBACK_PTR call."""
|
---|
83 | arg_len = apiutil.PacketLength( params )
|
---|
84 | if return_type != 'void':
|
---|
85 | paramList = [ ('foo', 'void *', 0) ]
|
---|
86 | arg_len += apiutil.PacketLength( paramList )
|
---|
87 |
|
---|
88 | print '\tSET_WRITEBACK_PTR( %d );' % (arg_len + 8) # extended opcode plus packet length
|
---|
89 |
|
---|
90 |
|
---|
91 | def MakeNormalCall( return_type, func_name, params, counter_init = 0 ):
|
---|
92 | counter = counter_init
|
---|
93 | copy_of_params = params[:]
|
---|
94 |
|
---|
95 | for i in range( 0, len(params) ):
|
---|
96 | (name, type, vecSize) = params[i]
|
---|
97 | if apiutil.IsPointer(copy_of_params[i][1]):
|
---|
98 | params[i] = ('NULL', type, vecSize)
|
---|
99 | copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
|
---|
100 | if not "get" in apiutil.Properties(func_name):
|
---|
101 | print '\tcrError( "%s needs to be special cased!" );' % func_name
|
---|
102 | else:
|
---|
103 | print "\t%s %s = %s;" % ( copy_of_params[i][1], name, ReadData( counter, copy_of_params[i][1] ) )
|
---|
104 | counter += apiutil.sizeof(copy_of_params[i][1])
|
---|
105 |
|
---|
106 | if ("get" in apiutil.Properties(func_name)):
|
---|
107 | FindReturnPointer( return_type, params )
|
---|
108 | FindWritebackPointer( return_type, params )
|
---|
109 |
|
---|
110 | if return_type != "void":
|
---|
111 | print "\t(void)",
|
---|
112 | else:
|
---|
113 | print "\t",
|
---|
114 | print "cr_unpackDispatch.%s( %s );" % (func_name, apiutil.MakeCallString(params))
|
---|
115 |
|
---|
116 |
|
---|
117 | def MakeVectorCall( return_type, func_name, arg_type ):
|
---|
118 | """Convert a call like glVertex3f to glVertex3fv."""
|
---|
119 | vec_func = apiutil.VectorFunction(func_name)
|
---|
120 | params = apiutil.Parameters(vec_func)
|
---|
121 | assert len(params) == 1
|
---|
122 | (arg_name, vecType, vecSize) = params[0]
|
---|
123 |
|
---|
124 | if arg_type == "GLdouble" or arg_type == "GLclampd":
|
---|
125 | print "#ifdef CR_UNALIGNED_ACCESS_OKAY"
|
---|
126 | print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
|
---|
127 | print "#else"
|
---|
128 | for index in range(0, vecSize):
|
---|
129 | print "\tGLdouble v" + `index` + " = READ_DOUBLE(", `index * 8`, ");"
|
---|
130 | if return_type != "void":
|
---|
131 | print "\t(void) cr_unpackDispatch.%s(" % func_name,
|
---|
132 | else:
|
---|
133 | print "\tcr_unpackDispatch.%s(" % func_name,
|
---|
134 | for index in range(0, vecSize):
|
---|
135 | print "v" + `index`,
|
---|
136 | if index != vecSize - 1:
|
---|
137 | print ",",
|
---|
138 | print ");"
|
---|
139 | print "#endif"
|
---|
140 | else:
|
---|
141 | print "\tcr_unpackDispatch.%s((%s) cr_unpackData);" % (vec_func, vecType)
|
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
146 |
|
---|
147 |
|
---|
148 | #
|
---|
149 | # Generate unpack functions for all the simple functions.
|
---|
150 | #
|
---|
151 | for func_name in keys:
|
---|
152 | if (not "pack" in apiutil.ChromiumProps(func_name) or
|
---|
153 | apiutil.FindSpecial( "unpacker", func_name )):
|
---|
154 | continue
|
---|
155 |
|
---|
156 | params = apiutil.Parameters(func_name)
|
---|
157 | return_type = apiutil.ReturnType(func_name)
|
---|
158 |
|
---|
159 | print "static void crUnpack%s(void)" % func_name
|
---|
160 | print "{"
|
---|
161 |
|
---|
162 | vector_func = apiutil.VectorFunction(func_name)
|
---|
163 | if (vector_func and len(apiutil.Parameters(vector_func)) == 1):
|
---|
164 | MakeVectorCall( return_type, func_name, params[0][1] )
|
---|
165 | else:
|
---|
166 | MakeNormalCall( return_type, func_name, params )
|
---|
167 | packet_length = apiutil.PacketLength( params )
|
---|
168 | if packet_length == 0:
|
---|
169 | print "\tINCR_DATA_PTR_NO_ARGS( );"
|
---|
170 | else:
|
---|
171 | print "\tINCR_DATA_PTR( %d );" % packet_length
|
---|
172 | print "}\n"
|
---|
173 |
|
---|
174 |
|
---|
175 | #
|
---|
176 | # Emit some code
|
---|
177 | #
|
---|
178 | print """
|
---|
179 | typedef struct __dispatchNode {
|
---|
180 | const unsigned char *unpackData;
|
---|
181 | struct __dispatchNode *next;
|
---|
182 | } DispatchNode;
|
---|
183 |
|
---|
184 | static DispatchNode *unpackStack = NULL;
|
---|
185 |
|
---|
186 | static SPUDispatchTable *cr_lastDispatch = NULL;
|
---|
187 |
|
---|
188 | void crUnpackPush(void)
|
---|
189 | {
|
---|
190 | DispatchNode *node = (DispatchNode*)crAlloc( sizeof( *node ) );
|
---|
191 | node->next = unpackStack;
|
---|
192 | unpackStack = node;
|
---|
193 | node->unpackData = cr_unpackData;
|
---|
194 | }
|
---|
195 |
|
---|
196 | void crUnpackPop(void)
|
---|
197 | {
|
---|
198 | DispatchNode *node = unpackStack;
|
---|
199 |
|
---|
200 | if (!node)
|
---|
201 | {
|
---|
202 | crError( "crUnpackPop called with an empty stack!" );
|
---|
203 | }
|
---|
204 | unpackStack = node->next;
|
---|
205 | cr_unpackData = node->unpackData;
|
---|
206 | crFree( node );
|
---|
207 | }
|
---|
208 |
|
---|
209 | void crUnpack( const void *data, const void *opcodes,
|
---|
210 | unsigned int num_opcodes, SPUDispatchTable *table )
|
---|
211 | {
|
---|
212 | unsigned int i;
|
---|
213 | const unsigned char *unpack_opcodes;
|
---|
214 | if (table != cr_lastDispatch)
|
---|
215 | {
|
---|
216 | crSPUCopyDispatchTable( &cr_unpackDispatch, table );
|
---|
217 | cr_lastDispatch = table;
|
---|
218 | }
|
---|
219 |
|
---|
220 | unpack_opcodes = (const unsigned char *)opcodes;
|
---|
221 | cr_unpackData = (const unsigned char *)data;
|
---|
222 |
|
---|
223 | #if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
|
---|
224 | crDebug("crUnpack: %d opcodes", num_opcodes);
|
---|
225 | #endif
|
---|
226 |
|
---|
227 | for (i = 0 ; i < num_opcodes ; i++)
|
---|
228 | {
|
---|
229 | /*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
|
---|
230 | switch( *unpack_opcodes )
|
---|
231 | {"""
|
---|
232 |
|
---|
233 | #
|
---|
234 | # Emit switch cases for all unextended opcodes
|
---|
235 | #
|
---|
236 | for func_name in keys:
|
---|
237 | if "pack" in apiutil.ChromiumProps(func_name):
|
---|
238 | print '\t\t\tcase %s:' % apiutil.OpcodeName( func_name )
|
---|
239 | if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
|
---|
240 | print """
|
---|
241 | #ifdef CR_UNPACK_DEBUG_LAST_OPCODES
|
---|
242 | if (i==(num_opcodes-1))
|
---|
243 | #endif
|
---|
244 | #if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
|
---|
245 | crDebug("Unpack: %s");
|
---|
246 | #endif """ % apiutil.OpcodeName(func_name)
|
---|
247 | print '\t\t\t\tcrUnpack%s(); \n\t\t\t\tbreak;' % func_name
|
---|
248 |
|
---|
249 | print """
|
---|
250 | case CR_EXTEND_OPCODE:
|
---|
251 | #ifdef CR_UNPACK_DEBUG_OPCODES
|
---|
252 | crUnpackExtendDbg();
|
---|
253 | #else
|
---|
254 | # ifdef CR_UNPACK_DEBUG_LAST_OPCODES
|
---|
255 | if (i==(num_opcodes-1)) crUnpackExtendDbg();
|
---|
256 | else
|
---|
257 | # endif
|
---|
258 | crUnpackExtend();
|
---|
259 | #endif
|
---|
260 | break;
|
---|
261 | default:
|
---|
262 | crError( "Unknown opcode: %d", *unpack_opcodes );
|
---|
263 | break;
|
---|
264 | }
|
---|
265 | unpack_opcodes--;
|
---|
266 | }
|
---|
267 | }"""
|
---|
268 |
|
---|
269 |
|
---|
270 | #
|
---|
271 | # Emit unpack functions for extended opcodes, non-special functions only.
|
---|
272 | #
|
---|
273 | for func_name in keys:
|
---|
274 | if ("extpack" in apiutil.ChromiumProps(func_name)
|
---|
275 | and not apiutil.FindSpecial("unpacker", func_name)):
|
---|
276 | return_type = apiutil.ReturnType(func_name)
|
---|
277 | params = apiutil.Parameters(func_name)
|
---|
278 | print 'static void crUnpackExtend%s(void)' % func_name
|
---|
279 | print '{'
|
---|
280 | MakeNormalCall( return_type, func_name, params, 8 )
|
---|
281 | print '}\n'
|
---|
282 |
|
---|
283 | print 'static void crUnpackExtend(void)'
|
---|
284 | print '{'
|
---|
285 | print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
|
---|
286 | print ''
|
---|
287 | print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
|
---|
288 | print '\tswitch( extend_opcode )'
|
---|
289 | print '\t{'
|
---|
290 |
|
---|
291 |
|
---|
292 | #
|
---|
293 | # Emit switch statement for extended opcodes
|
---|
294 | #
|
---|
295 | for func_name in keys:
|
---|
296 | if "extpack" in apiutil.ChromiumProps(func_name):
|
---|
297 | print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
|
---|
298 | # print '\t\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
|
---|
299 | print '\t\t\tcrUnpackExtend%s( );' % func_name
|
---|
300 | print '\t\t\tbreak;'
|
---|
301 |
|
---|
302 | print """ default:
|
---|
303 | crError( "Unknown extended opcode: %d", (int) extend_opcode );
|
---|
304 | break;
|
---|
305 | }
|
---|
306 | INCR_VAR_PTR();
|
---|
307 | }"""
|
---|
308 |
|
---|
309 | print 'static void crUnpackExtendDbg(void)'
|
---|
310 | print '{'
|
---|
311 | print '\tGLenum extend_opcode = %s;' % ReadData( 4, 'GLenum' );
|
---|
312 | print ''
|
---|
313 | print '\t/*crDebug(\"Unpacking extended opcode \%d", extend_opcode);*/'
|
---|
314 | print '\tswitch( extend_opcode )'
|
---|
315 | print '\t{'
|
---|
316 |
|
---|
317 |
|
---|
318 | #
|
---|
319 | # Emit switch statement for extended opcodes
|
---|
320 | #
|
---|
321 | for func_name in keys:
|
---|
322 | if "extpack" in apiutil.ChromiumProps(func_name):
|
---|
323 | print '\t\tcase %s:' % apiutil.ExtendedOpcodeName( func_name )
|
---|
324 | if not apiutil.ExtendedOpcodeName(func_name) in nodebug_extopcodes:
|
---|
325 | print '\t\t\tcrDebug("Unpack: %s");' % apiutil.ExtendedOpcodeName( func_name )
|
---|
326 | print '\t\t\tcrUnpackExtend%s( );' % func_name
|
---|
327 | print '\t\t\tbreak;'
|
---|
328 |
|
---|
329 | print """ default:
|
---|
330 | crError( "Unknown extended opcode: %d", (int) extend_opcode );
|
---|
331 | break;
|
---|
332 | }
|
---|
333 | INCR_VAR_PTR();
|
---|
334 | }"""
|
---|