|
1 /* |
|
2 * LIBOIL - Library of Optimized Inner Loops |
|
3 * Copyright (c) 2004 David A. Schleef <ds@schleef.org> |
|
4 * All rights reserved. |
|
5 * |
|
6 * Redistribution and use in source and binary forms, with or without |
|
7 * modification, are permitted provided that the following conditions |
|
8 * are met: |
|
9 * 1. Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * 2. Redistributions in binary form must reproduce the above copyright |
|
12 * notice, this list of conditions and the following disclaimer in the |
|
13 * documentation and/or other materials provided with the distribution. |
|
14 * |
|
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
|
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
|
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
|
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
|
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
25 * POSSIBILITY OF SUCH DAMAGE. |
|
26 */ |
|
27 |
|
28 |
|
29 #include <stdio.h> |
|
30 #include <liboil/liboil.h> |
|
31 #include <ctype.h> |
|
32 #include <stdlib.h> |
|
33 #include <string.h> |
|
34 |
|
35 #include <liboil/liboilprototype.h> |
|
36 |
|
37 void print_header (void); |
|
38 void print_footer (void); |
|
39 void add_pointer_mask (unsigned int mask); |
|
40 |
|
41 unsigned int proto_masks[1000]; |
|
42 int n_for_mask[1000]; |
|
43 int n_proto_masks; |
|
44 |
|
45 int main (int argc, char *argv[]) |
|
46 { |
|
47 OilFunctionClass *klass; |
|
48 OilPrototype *proto; |
|
49 int i; |
|
50 int j; |
|
51 int n; |
|
52 unsigned int pointer_mask; |
|
53 |
|
54 oil_init_no_optimize (); |
|
55 |
|
56 print_header (); |
|
57 |
|
58 n = oil_class_get_n_classes (); |
|
59 for (i=0;i<n; i++ ){ |
|
60 klass = oil_class_get_by_index (i); |
|
61 |
|
62 if(klass->prototype) { |
|
63 proto = oil_prototype_from_string (klass->prototype); |
|
64 if (proto) { |
|
65 pointer_mask = 1; |
|
66 |
|
67 for (j=0;j<proto->n_params;j++){ |
|
68 pointer_mask <<= 1; |
|
69 if (proto->params[j].is_pointer) pointer_mask |= 1; |
|
70 } |
|
71 |
|
72 add_pointer_mask (pointer_mask); |
|
73 |
|
74 oil_prototype_free (proto); |
|
75 } else { |
|
76 printf("/* ERROR: could not parse %s(%s) */\n", klass->name, klass->prototype); |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 for(i=0;i<n_proto_masks;i++){ |
|
82 unsigned int bit; |
|
83 unsigned int hibit; |
|
84 |
|
85 pointer_mask = proto_masks[i]; |
|
86 for(hibit=1;hibit<=pointer_mask;hibit<<=1); |
|
87 hibit>>=2; |
|
88 |
|
89 printf(" case 0x%04x:\n", pointer_mask); |
|
90 printf(" oil_profile_start (prof);\n"); |
|
91 printf(" ((void (*)("); |
|
92 if(hibit == 0) { |
|
93 printf("void"); |
|
94 } else { |
|
95 for(bit=hibit;bit;bit >>= 1) { |
|
96 if (pointer_mask & bit) { |
|
97 printf("void *"); |
|
98 } else { |
|
99 printf("int"); |
|
100 } |
|
101 if (bit > 1) { |
|
102 printf(","); |
|
103 } |
|
104 } |
|
105 } |
|
106 printf("))func)\n"); |
|
107 printf(" ("); |
|
108 j=0; |
|
109 for(bit=hibit;bit;bit >>= 1) { |
|
110 if (pointer_mask & bit) { |
|
111 printf("(void *)args[%d]", j); |
|
112 } else { |
|
113 printf("(int)args[%d]", j); |
|
114 } |
|
115 if (bit > 1) { |
|
116 printf(","); |
|
117 } |
|
118 j++; |
|
119 } |
|
120 printf(");\n"); |
|
121 printf(" oil_profile_stop (prof);\n"); |
|
122 printf(" break;\n"); |
|
123 } |
|
124 |
|
125 print_footer (); |
|
126 |
|
127 return 0; |
|
128 } |
|
129 |
|
130 void |
|
131 add_pointer_mask (unsigned int mask) |
|
132 { |
|
133 int i; |
|
134 for(i=0;i<n_proto_masks;i++){ |
|
135 if (proto_masks[i] == mask) { |
|
136 n_for_mask[i]++; |
|
137 return; |
|
138 } |
|
139 } |
|
140 proto_masks[n_proto_masks] = mask; |
|
141 n_for_mask[n_proto_masks]++; |
|
142 n_proto_masks++; |
|
143 } |
|
144 |
|
145 void print_header (void) |
|
146 { |
|
147 printf ("/*\n"); |
|
148 printf (" * LIBOIL - Library of Optimized Inner Loops\n"); |
|
149 printf (" * Copyright (c) 2004 David A. Schleef <ds@schleef.org>\n"); |
|
150 printf (" * All rights reserved.\n"); |
|
151 printf (" *\n"); |
|
152 printf (" * Redistribution and use in source and binary forms, with or without\n"); |
|
153 printf (" * modification, are permitted provided that the following conditions\n"); |
|
154 printf (" * are met:\n"); |
|
155 printf (" * 1. Redistributions of source code must retain the above copyright\n"); |
|
156 printf (" * notice, this list of conditions and the following disclaimer.\n"); |
|
157 printf (" * 2. Redistributions in binary form must reproduce the above copyright\n"); |
|
158 printf (" * notice, this list of conditions and the following disclaimer in the\n"); |
|
159 printf (" * documentation and/or other materials provided with the distribution.\n"); |
|
160 printf (" * \n"); |
|
161 printf (" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n"); |
|
162 printf (" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n"); |
|
163 printf (" * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"); |
|
164 printf (" * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\n"); |
|
165 printf (" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n"); |
|
166 printf (" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"); |
|
167 printf (" * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"); |
|
168 printf (" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n"); |
|
169 printf (" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n"); |
|
170 printf (" * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n"); |
|
171 printf (" * POSSIBILITY OF SUCH DAMAGE.\n"); |
|
172 printf (" */\n"); |
|
173 printf ("\n"); |
|
174 printf ("/* This file is automatically generated. Do not edit. */\n"); |
|
175 printf ("\n"); |
|
176 printf ("#ifdef HAVE_CONFIG_H\n"); |
|
177 printf ("#include <config.h>\n"); |
|
178 printf ("#endif\n"); |
|
179 printf ("\n"); |
|
180 printf ("#include <liboil/liboiltest.h>\n"); |
|
181 printf ("#include <liboil/liboildebug.h>\n"); |
|
182 printf ("#include <liboil/liboilprofile.h>\n"); |
|
183 printf ("\n"); |
|
184 printf ("void\n"); |
|
185 printf ("_oil_test_marshal_function (void *func, unsigned long *args, int n_args,\n"); |
|
186 printf (" unsigned int pointer_mask, OilProfile *prof)\n"); |
|
187 printf ("{\n"); |
|
188 printf (" switch (pointer_mask) {\n"); |
|
189 } |
|
190 |
|
191 void print_footer (void) |
|
192 { |
|
193 printf (" default:\n"); |
|
194 printf (" OIL_ERROR (\"unhandled marshal case\");\n"); |
|
195 printf (" }\n"); |
|
196 printf ("}\n"); |
|
197 printf ("\n"); |
|
198 } |
|
199 |