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 | import apiutil
|
---|
8 |
|
---|
9 |
|
---|
10 | apiutil.CopyrightC()
|
---|
11 |
|
---|
12 | print """
|
---|
13 |
|
---|
14 | /* DO NOT EDIT - THIS FILE AUTOMATICALLY GENERATED BY dispatch.py SCRIPT */
|
---|
15 |
|
---|
16 | #include "cr_spu.h"
|
---|
17 | #include "cr_string.h"
|
---|
18 | #include "cr_error.h"
|
---|
19 |
|
---|
20 |
|
---|
21 | static SPUGenericFunction __findFunc( char *name, SPU *spu )
|
---|
22 | {
|
---|
23 | SPUNamedFunctionTable *temp;
|
---|
24 |
|
---|
25 | if (spu == NULL)
|
---|
26 | return NULL;
|
---|
27 |
|
---|
28 | for (temp = spu->function_table->table ; temp->name != NULL ; temp++)
|
---|
29 | {
|
---|
30 | if (!crStrcmp( name, temp->name ) )
|
---|
31 | {
|
---|
32 | return temp->fn;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | return __findFunc( name, spu->superSPU );
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | /*
|
---|
40 | * This function is not public outside the loader SPU.
|
---|
41 | */
|
---|
42 | extern void __buildDispatch( SPU *spu );
|
---|
43 |
|
---|
44 | void __buildDispatch( SPU *spu )
|
---|
45 | {"""
|
---|
46 |
|
---|
47 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
48 | for func_name in keys:
|
---|
49 | print '\tspu->dispatch_table.%s = (%sFunc_t) __findFunc( "%s", spu );' % (func_name,func_name,func_name)
|
---|
50 | print '}'
|
---|
51 |
|
---|
52 |
|
---|
53 | print """
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * Public function:
|
---|
57 | * Search a SPU named function table for a specific function. Return
|
---|
58 | * a pointer to it or NULL if not found.
|
---|
59 | */
|
---|
60 | SPUGenericFunction crSPUFindFunction( const SPUNamedFunctionTable *table, const char *fname )
|
---|
61 | {
|
---|
62 | const SPUNamedFunctionTable *temp;
|
---|
63 |
|
---|
64 | for (temp = table ; temp->name != NULL ; temp++)
|
---|
65 | {
|
---|
66 | if (!crStrcmp( fname, temp->name ) )
|
---|
67 | {
|
---|
68 | return temp->fn;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | return NULL;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * Public function:
|
---|
77 | * Initializes the pointers in an SPUDispatchTable by looking for functions
|
---|
78 | * in an SPUNamedFunctionTable.
|
---|
79 | * It doesn't know anything about SPUs and SPU inheritance.
|
---|
80 | */
|
---|
81 | void crSPUInitDispatch( SPUDispatchTable *dispatch, const SPUNamedFunctionTable *table )
|
---|
82 | {"""
|
---|
83 |
|
---|
84 | for func_name in keys:
|
---|
85 | print '\tdispatch->%s = (%sFunc_t) crSPUFindFunction(table, "%s");' % (func_name, func_name, func_name)
|
---|
86 | print '}'
|
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 | print """
|
---|
91 | /*
|
---|
92 | * Generic no-op function
|
---|
93 | */
|
---|
94 | static int NopFunction(void)
|
---|
95 | {
|
---|
96 | /*
|
---|
97 | crWarning("Calling generic no-op function in dispatch.c");
|
---|
98 | */
|
---|
99 | return 0;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /*
|
---|
104 | * Scan the given dispatch table for NULL pointers. Hook in the generic
|
---|
105 | * no-op function wherever we find a NULL pointer.
|
---|
106 | */
|
---|
107 | void crSPUInitDispatchNops(SPUDispatchTable *table)
|
---|
108 | {
|
---|
109 | /*
|
---|
110 | * This is a bit tricky. We walk over all the function pointers in
|
---|
111 | * the SPUDispatchTable struct, checking for NULL and setting NULL
|
---|
112 | * pointers to point to NopFunction().
|
---|
113 | * But we have to stop when we get to the copyList pointer!
|
---|
114 | */
|
---|
115 | const int numEntries = (void **) &(table->copyList) - (void **) &(table->Accum);
|
---|
116 | void **ptr = (void **) table;
|
---|
117 | int i;
|
---|
118 | for (i = 0; i < numEntries; i++) {
|
---|
119 | if (ptr[i] == NULL) {
|
---|
120 | /*printf("!!!!!!!Warning entry[%d] = NULL\n", i);*/
|
---|
121 | ptr[i] = (void *)NopFunction;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 | """
|
---|