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