1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /*************************************************************** |
---|
5 | * File: p_ProcsGenerate.cc |
---|
6 | * Purpose: generate p_Procs*.inc at compile |
---|
7 | * Note: this file is included by p_Procs.cc |
---|
8 | * Author: obachman (Olaf Bachmann) |
---|
9 | * Created: 8/00 |
---|
10 | * Version: $Id: p_Procs_Generate.cc,v 1.4 2000-12-31 15:14:39 obachman Exp $ |
---|
11 | *******************************************************************/ |
---|
12 | |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <stdlib.h> |
---|
16 | |
---|
17 | #include "mod2.h" |
---|
18 | #include "dError.c" |
---|
19 | |
---|
20 | #ifdef p_Procs_Static |
---|
21 | #include "p_Procs_Static.h" |
---|
22 | #else |
---|
23 | #include "p_Procs_Dynamic.h" |
---|
24 | #endif |
---|
25 | |
---|
26 | #include "p_Procs_Impl.h" |
---|
27 | |
---|
28 | #ifndef p_Procs_Static |
---|
29 | int FieldGeneralProcs = 0, |
---|
30 | FieldIndepProcs = 0, |
---|
31 | FieldZpProcs = 0, |
---|
32 | FieldQProcs = 0, |
---|
33 | KernelProcs = 0, |
---|
34 | UnknownProcs = 0; |
---|
35 | |
---|
36 | // returns 1, if proc should go into kernel, 0 otherwise |
---|
37 | int IsKernelProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
38 | { |
---|
39 | // general procs go into kernel |
---|
40 | if (field == FieldGeneral && length == LengthGeneral && ord == OrdGeneral) |
---|
41 | return 1; |
---|
42 | |
---|
43 | // plus procs with FieldZp |
---|
44 | if ((field == FieldZp || field == FieldQ) && |
---|
45 | // which are not general in length or ord |
---|
46 | !((length == LengthGeneral && p_ProcDependsOn_Length(proc)) || |
---|
47 | (ord == OrdGeneral && p_ProcDependsOn_Ord(proc))) && |
---|
48 | // and whose length is smaller than five |
---|
49 | (!p_ProcDependsOn_Length(proc) || (length >= LengthFour))) |
---|
50 | return 1; |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | return 0; |
---|
55 | } |
---|
56 | |
---|
57 | #endif |
---|
58 | |
---|
59 | #define DoSetProc(what, field, length, ord) \ |
---|
60 | GenerateProc(#what, what##_Proc, field, length, ord) |
---|
61 | |
---|
62 | char*** generated_p_procs; |
---|
63 | |
---|
64 | inline int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
65 | { |
---|
66 | return (generated_p_procs[proc])[index(proc, field, length, ord)] != 0; |
---|
67 | } |
---|
68 | |
---|
69 | const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", NULL}; |
---|
70 | |
---|
71 | const char* macros_length[] = |
---|
72 | {"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL}; |
---|
73 | |
---|
74 | const char* macros_length_ord[] = {"p_MemCmp", NULL}; |
---|
75 | int DummyProcs = 0; |
---|
76 | |
---|
77 | int NumberOfHaveProcs = 0; |
---|
78 | |
---|
79 | void AddProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
80 | { |
---|
81 | NumberOfHaveProcs++; |
---|
82 | int i; |
---|
83 | const char* s_length = p_LengthEnum_2_String(length); |
---|
84 | const char* s_ord = p_OrdEnum_2_String(ord); |
---|
85 | const char* s_field = p_FieldEnum_2_String(field); |
---|
86 | char* s_full_proc_name = (char*) malloc(200); |
---|
87 | |
---|
88 | sprintf(s_full_proc_name, "%s__%s_%s_%s", s_what, s_field, s_length, s_ord); |
---|
89 | |
---|
90 | (generated_p_procs[proc])[index(proc, field, length, ord)] = s_full_proc_name; |
---|
91 | // define all macros |
---|
92 | printf("\n// definition of %s\n", s_full_proc_name); |
---|
93 | #ifndef p_Procs_Static |
---|
94 | if (IsKernelProc(proc, field, length, ord)) |
---|
95 | { |
---|
96 | KernelProcs++; |
---|
97 | printf("#ifdef p_Procs_Kernel\n"); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | const char* module = p_ProcField_2_Module(proc, field); |
---|
102 | if (strcmp(module, "FieldGeneral") == 0) |
---|
103 | FieldGeneralProcs++; |
---|
104 | else if (strcmp(module, "FieldIndep") == 0) |
---|
105 | FieldIndepProcs++; |
---|
106 | else if (strcmp(module, "FieldZp") == 0) |
---|
107 | FieldZpProcs++; |
---|
108 | else if (strcmp(module, "FieldQ") == 0) |
---|
109 | FieldQProcs++; |
---|
110 | else |
---|
111 | UnknownProcs++; |
---|
112 | |
---|
113 | printf("#ifdef p_Procs_%s\n", module); |
---|
114 | } |
---|
115 | #endif |
---|
116 | i = 0; |
---|
117 | while (macros_field[i] != NULL) |
---|
118 | { |
---|
119 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
120 | macros_field[i], macros_field[i], macros_field[i], s_field); |
---|
121 | i++; |
---|
122 | } |
---|
123 | i = 0; |
---|
124 | while (macros_length[i] != NULL) |
---|
125 | { |
---|
126 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
127 | macros_length[i], macros_length[i], macros_length[i], s_length); |
---|
128 | i++; |
---|
129 | } |
---|
130 | i = 0; |
---|
131 | while (macros_length_ord[i] != NULL) |
---|
132 | { |
---|
133 | printf("#undef %s\n#define %s\t%s_%s_%s\n", |
---|
134 | macros_length_ord[i], macros_length_ord[i], macros_length_ord[i], s_length, s_ord); |
---|
135 | i++; |
---|
136 | } |
---|
137 | |
---|
138 | // define DECLARE_LENGTH |
---|
139 | printf("#undef DECLARE_LENGTH\n"); |
---|
140 | printf("#undef p_MemAddAdjust\n"); |
---|
141 | if (length != LengthGeneral) |
---|
142 | { |
---|
143 | printf("#define DECLARE_LENGTH(what) ((void)0)\n"); |
---|
144 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | printf("#define DECLARE_LENGTH(what) what\n"); |
---|
149 | if (proc != pp_Mult_Coeff_mm_DivSelectMult_Proc) |
---|
150 | printf("#define p_MemAddAdjust(p, r) p_MemAdd_NegWeightAdjust(p, r)\n"); |
---|
151 | else |
---|
152 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
153 | } |
---|
154 | |
---|
155 | // define DECLARE_ORDSGN |
---|
156 | printf("#undef DECLARE_ORDSGN\n"); |
---|
157 | if (ord != OrdGeneral) |
---|
158 | printf("#define DECLARE_ORDSGN(what) ((void)0)\n"); |
---|
159 | else |
---|
160 | printf("#define DECLARE_ORDSGN(what) what\n"); |
---|
161 | |
---|
162 | if (proc == pp_Mult_Coeff_mm_DivSelectMult_Proc) |
---|
163 | { |
---|
164 | printf("#undef DECLARE_LENGTH_2\n"); |
---|
165 | printf("#undef p_MemCmp_Bitmask_2\n"); |
---|
166 | if (length != LengthGeneral) |
---|
167 | { |
---|
168 | printf("#define DECLARE_LENGTH_2(what) ((void)0)\n"); |
---|
169 | if (length < LengthTwo) |
---|
170 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_%s\n", p_LengthEnum_2_String((p_Length) ((int) length + 2))); |
---|
171 | else |
---|
172 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthZero\n"); |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | printf("#define DECLARE_LENGTH_2(what) what \n"); |
---|
177 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthGeneral\n"); |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | printf("#undef p_MemAddAdjust\n"); |
---|
182 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
183 | } |
---|
184 | |
---|
185 | printf("#undef %s\n#define %s %s\n", s_what, s_what, s_full_proc_name); |
---|
186 | printf("#include \"%s__Template.cc\"\n", s_what); |
---|
187 | printf("#undef %s\n", s_what); |
---|
188 | #ifndef p_Procs_Static |
---|
189 | printf("#endif // p_Procs_[Kernel|Field*]\n"); |
---|
190 | #endif |
---|
191 | } |
---|
192 | |
---|
193 | void GenerateProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
194 | { |
---|
195 | if (! AlreadyHaveProc(proc, field, length, ord)) |
---|
196 | AddProc(s_what, proc, field, length, ord); |
---|
197 | } |
---|
198 | |
---|
199 | int main() |
---|
200 | { |
---|
201 | int field = FieldGeneral; |
---|
202 | int length = LengthGeneral; |
---|
203 | int ord = OrdGeneral; |
---|
204 | int i; |
---|
205 | |
---|
206 | |
---|
207 | printf("/* -*-c++-*- */ |
---|
208 | /*************************************************************** |
---|
209 | * This file was generated automatically by p_ProcsGenerate.cc: DO NOT EDIT |
---|
210 | * |
---|
211 | * This file provides the needed implementation of p_Procs for |
---|
212 | * %s |
---|
213 | * See the end for a summary. |
---|
214 | *******************************************************************/\n", |
---|
215 | |
---|
216 | #if defined(p_Procs_Static) |
---|
217 | "p_Procs_Static" |
---|
218 | #else |
---|
219 | "p_Procs_Dynamic" |
---|
220 | #endif |
---|
221 | ); |
---|
222 | |
---|
223 | generated_p_procs = (char***) malloc(p_Unknown_Proc*sizeof(char**)); |
---|
224 | for (i=0; i<p_Unknown_Proc; i++) |
---|
225 | { |
---|
226 | generated_p_procs[i] = |
---|
227 | (char**) calloc(index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown), sizeof(char*)); |
---|
228 | } |
---|
229 | |
---|
230 | // set default procs |
---|
231 | for (field = 0; field < (int) FieldUnknown; field++) |
---|
232 | { |
---|
233 | for (length=0; length < (int) LengthUnknown; length++) |
---|
234 | { |
---|
235 | for (ord=0; ord < (int)OrdUnknown; ord++) |
---|
236 | { |
---|
237 | if (IsValidSpec((p_Field) field, (p_Length) length, (p_Ord) ord)) |
---|
238 | SetProcs((p_Field) field, (p_Length) length, (p_Ord) ord); |
---|
239 | } |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | // we only need lookup tables for p_Procs_Static |
---|
244 | #ifdef p_Procs_Static |
---|
245 | int j; |
---|
246 | printf(" |
---|
247 | /*************************************************************** |
---|
248 | Names of procs for RDEBUG */ |
---|
249 | #ifdef RDEBUG\n"); |
---|
250 | |
---|
251 | for (i=0; i<p_Unknown_Proc; i++) |
---|
252 | { |
---|
253 | printf("static const char* %s_names[] = {", p_ProcEnum_2_String((p_Proc)i)); |
---|
254 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
255 | { |
---|
256 | char* s = (generated_p_procs[i])[j]; |
---|
257 | if (s != 0) |
---|
258 | { |
---|
259 | printf("\n\"%s\",", s); |
---|
260 | } |
---|
261 | else |
---|
262 | printf("0,"); |
---|
263 | |
---|
264 | } |
---|
265 | printf("\n};\n"); |
---|
266 | } |
---|
267 | printf(" |
---|
268 | #endif // RDEBUG |
---|
269 | |
---|
270 | |
---|
271 | /***************************************************************/ |
---|
272 | /* Tables for lookup of procedures: */\n"); |
---|
273 | |
---|
274 | for (i=0; i<p_Unknown_Proc; i++) |
---|
275 | { |
---|
276 | printf("static const %s_Ptr %s_funcs[] = {", p_ProcEnum_2_String((p_Proc)i), p_ProcEnum_2_String((p_Proc)i)); |
---|
277 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
278 | { |
---|
279 | char* s = (generated_p_procs[i])[j]; |
---|
280 | if (s != 0) |
---|
281 | { |
---|
282 | printf("\n%s,", s); |
---|
283 | } |
---|
284 | else |
---|
285 | printf("0,"); |
---|
286 | |
---|
287 | } |
---|
288 | printf("\n};\n"); |
---|
289 | } |
---|
290 | #endif |
---|
291 | |
---|
292 | printf(" |
---|
293 | /*************************************************************** |
---|
294 | * Summary: |
---|
295 | * HAVE_FAST_P_PROCS = %d, |
---|
296 | * HAVE_FAST_FIELD = %d, |
---|
297 | * HAVE_FAST_LENGTH = %d, |
---|
298 | * HAVE_FAST_ORD = %d, |
---|
299 | * HAVE_FAST_ZERO_ORD = %d |
---|
300 | * |
---|
301 | * Generated PolyProcs= %d\n", |
---|
302 | HAVE_FAST_P_PROCS, HAVE_FAST_FIELD, HAVE_FAST_LENGTH, HAVE_FAST_ORD, |
---|
303 | HAVE_FAST_ZERO_ORD, NumberOfHaveProcs); |
---|
304 | |
---|
305 | #ifndef p_Procs_Static |
---|
306 | printf(" * |
---|
307 | * KernelProcs = %d |
---|
308 | * FieldIndepProcs = %d |
---|
309 | * FieldZpProcs = %d |
---|
310 | * FieldQProcs = %d |
---|
311 | * FieldGeneralProcs = %d |
---|
312 | * FieldUnknownProcs = %d\n", |
---|
313 | KernelProcs, FieldIndepProcs, FieldZpProcs,FieldQProcs, |
---|
314 | FieldGeneralProcs, UnknownProcs); |
---|
315 | #endif |
---|
316 | |
---|
317 | printf(" * |
---|
318 | *******************************************************************/\n"); |
---|
319 | } |
---|
320 | |
---|
321 | |
---|