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.2 2000-12-12 08:44:50 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 && |
---|
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 | return 0; |
---|
53 | } |
---|
54 | |
---|
55 | #endif |
---|
56 | |
---|
57 | #define DoSetProc(what, field, length, ord) \ |
---|
58 | GenerateProc(#what, what##_Proc, field, length, ord) |
---|
59 | |
---|
60 | char*** generated_p_procs; |
---|
61 | |
---|
62 | inline int AlreadyHaveProc(p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
63 | { |
---|
64 | return (generated_p_procs[proc])[index(proc, field, length, ord)] != 0; |
---|
65 | } |
---|
66 | |
---|
67 | const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", NULL}; |
---|
68 | |
---|
69 | const char* macros_length[] = |
---|
70 | {"p_MemCopy", "p_MemAdd", "p_MemSum", NULL}; |
---|
71 | |
---|
72 | const char* macros_length_ord[] = {"p_MemCmp", NULL}; |
---|
73 | int DummyProcs = 0; |
---|
74 | |
---|
75 | int NumberOfHaveProcs = 0; |
---|
76 | |
---|
77 | void AddProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
78 | { |
---|
79 | NumberOfHaveProcs++; |
---|
80 | int i; |
---|
81 | const char* s_length = p_LengthEnum_2_String(length); |
---|
82 | const char* s_ord = p_OrdEnum_2_String(ord); |
---|
83 | const char* s_field = p_FieldEnum_2_String(field); |
---|
84 | char* s_full_proc_name = (char*) malloc(200); |
---|
85 | |
---|
86 | sprintf(s_full_proc_name, "%s__%s_%s_%s", s_what, s_field, s_length, s_ord); |
---|
87 | |
---|
88 | (generated_p_procs[proc])[index(proc, field, length, ord)] = s_full_proc_name; |
---|
89 | // define all macros |
---|
90 | printf("\n// definition of %s\n", s_full_proc_name); |
---|
91 | #ifndef p_Procs_Static |
---|
92 | if (IsKernelProc(proc, field, length, ord)) |
---|
93 | { |
---|
94 | KernelProcs++; |
---|
95 | printf("#ifdef p_Procs_Kernel\n"); |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | const char* module = p_ProcField_2_Module(proc, field); |
---|
100 | if (strcmp(module, "FieldGeneral") == 0) |
---|
101 | FieldGeneralProcs++; |
---|
102 | else if (strcmp(module, "FieldIndep") == 0) |
---|
103 | FieldIndepProcs++; |
---|
104 | else if (strcmp(module, "FieldZp") == 0) |
---|
105 | FieldZpProcs++; |
---|
106 | else if (strcmp(module, "FieldQ") == 0) |
---|
107 | FieldQProcs++; |
---|
108 | else |
---|
109 | UnknownProcs++; |
---|
110 | |
---|
111 | printf("#ifdef p_Procs_%s\n", module); |
---|
112 | } |
---|
113 | #endif |
---|
114 | i = 0; |
---|
115 | while (macros_field[i] != NULL) |
---|
116 | { |
---|
117 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
118 | macros_field[i], macros_field[i], macros_field[i], s_field); |
---|
119 | i++; |
---|
120 | } |
---|
121 | i = 0; |
---|
122 | while (macros_length[i] != NULL) |
---|
123 | { |
---|
124 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
125 | macros_length[i], macros_length[i], macros_length[i], s_length); |
---|
126 | i++; |
---|
127 | } |
---|
128 | i = 0; |
---|
129 | while (macros_length_ord[i] != NULL) |
---|
130 | { |
---|
131 | printf("#undef %s\n#define %s\t%s_%s_%s\n", |
---|
132 | macros_length_ord[i], macros_length_ord[i], macros_length_ord[i], s_length, s_ord); |
---|
133 | i++; |
---|
134 | } |
---|
135 | |
---|
136 | // define DECLARE_LENGTH |
---|
137 | printf("#undef DECLARE_LENGTH\n"); |
---|
138 | printf("#undef p_MemAddAdjust\n"); |
---|
139 | if (length != LengthGeneral) |
---|
140 | { |
---|
141 | printf("#define DECLARE_LENGTH(what) ((void)0)\n"); |
---|
142 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | printf("#define DECLARE_LENGTH(what) what\n"); |
---|
147 | printf("#define p_MemAddAdjust(p, r) p_MemAdd_NegWeightAdjust(p, r)\n"); |
---|
148 | } |
---|
149 | |
---|
150 | // define DECLARE_ORDSGN |
---|
151 | printf("#undef DECLARE_ORDSGN\n"); |
---|
152 | if (ord != OrdGeneral) |
---|
153 | printf("#define DECLARE_ORDSGN(what) ((void)0)\n"); |
---|
154 | else |
---|
155 | printf("#define DECLARE_ORDSGN(what) what\n"); |
---|
156 | |
---|
157 | printf("#undef %s\n#define %s %s\n", s_what, s_what, s_full_proc_name); |
---|
158 | printf("#include \"%s__Template.cc\"\n", s_what); |
---|
159 | printf("#undef %s\n", s_what); |
---|
160 | #ifndef p_Procs_Static |
---|
161 | printf("#endif // p_Procs_[Kernel|Field*]\n"); |
---|
162 | #endif |
---|
163 | } |
---|
164 | |
---|
165 | void GenerateProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
166 | { |
---|
167 | if (! AlreadyHaveProc(proc, field, length, ord)) |
---|
168 | AddProc(s_what, proc, field, length, ord); |
---|
169 | } |
---|
170 | |
---|
171 | int main() |
---|
172 | { |
---|
173 | int field = FieldGeneral; |
---|
174 | int length = LengthGeneral; |
---|
175 | int ord = OrdGeneral; |
---|
176 | int i; |
---|
177 | |
---|
178 | |
---|
179 | printf("/* -*-c++-*- */ |
---|
180 | /*************************************************************** |
---|
181 | * This file was generated automatically by p_ProcsGenerate.cc: DO NOT EDIT |
---|
182 | * |
---|
183 | * This file provides the needed implementation of p_Procs for |
---|
184 | * %s |
---|
185 | * See the end for a summary. |
---|
186 | *******************************************************************/\n", |
---|
187 | |
---|
188 | #if defined(p_Procs_Static) |
---|
189 | "p_Procs_Static" |
---|
190 | #else |
---|
191 | "p_Procs_Dynamic" |
---|
192 | #endif |
---|
193 | ); |
---|
194 | |
---|
195 | generated_p_procs = (char***) malloc(p_Unknown_Proc*sizeof(char**)); |
---|
196 | for (i=0; i<p_Unknown_Proc; i++) |
---|
197 | { |
---|
198 | generated_p_procs[i] = |
---|
199 | (char**) calloc(index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown), sizeof(char*)); |
---|
200 | } |
---|
201 | |
---|
202 | // set default procs |
---|
203 | for (field = 0; field < (int) FieldUnknown; field++) |
---|
204 | { |
---|
205 | for (length=0; length < (int) LengthUnknown; length++) |
---|
206 | { |
---|
207 | for (ord=0; ord < (int)OrdUnknown; ord++) |
---|
208 | { |
---|
209 | if (IsValidSpec((p_Field) field, (p_Length) length, (p_Ord) ord)) |
---|
210 | SetProcs((p_Field) field, (p_Length) length, (p_Ord) ord); |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | // we only need lookup tables for p_Procs_Static |
---|
216 | #ifdef p_Procs_Static |
---|
217 | int j; |
---|
218 | printf(" |
---|
219 | /*************************************************************** |
---|
220 | Names of procs for RDEBUG */ |
---|
221 | #ifdef RDEBUG\n"); |
---|
222 | |
---|
223 | for (i=0; i<p_Unknown_Proc; i++) |
---|
224 | { |
---|
225 | printf("static const char* %s_names[] = {", p_ProcEnum_2_String((p_Proc)i)); |
---|
226 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
227 | { |
---|
228 | char* s = (generated_p_procs[i])[j]; |
---|
229 | if (s != 0) |
---|
230 | { |
---|
231 | printf("\n\"%s\",", s); |
---|
232 | } |
---|
233 | else |
---|
234 | printf("0,"); |
---|
235 | |
---|
236 | } |
---|
237 | printf("\n};\n"); |
---|
238 | } |
---|
239 | printf(" |
---|
240 | #endif // RDEBUG |
---|
241 | |
---|
242 | |
---|
243 | /***************************************************************/ |
---|
244 | /* Tables for lookup of procedures: */\n"); |
---|
245 | |
---|
246 | for (i=0; i<p_Unknown_Proc; i++) |
---|
247 | { |
---|
248 | printf("static const %s_Ptr %s_funcs[] = {", p_ProcEnum_2_String((p_Proc)i), p_ProcEnum_2_String((p_Proc)i)); |
---|
249 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
250 | { |
---|
251 | char* s = (generated_p_procs[i])[j]; |
---|
252 | if (s != 0) |
---|
253 | { |
---|
254 | printf("\n%s,", s); |
---|
255 | } |
---|
256 | else |
---|
257 | printf("0,"); |
---|
258 | |
---|
259 | } |
---|
260 | printf("\n};\n"); |
---|
261 | } |
---|
262 | #endif |
---|
263 | |
---|
264 | printf(" |
---|
265 | /*************************************************************** |
---|
266 | * Summary: |
---|
267 | * HAVE_FAST_P_PROCS = %d, |
---|
268 | * HAVE_FAST_FIELD = %d, |
---|
269 | * HAVE_FAST_LENGTH = %d, |
---|
270 | * HAVE_FAST_ORD = %d, |
---|
271 | * HAVE_FAST_ZERO_ORD = %d |
---|
272 | * |
---|
273 | * Generated PolyProcs= %d\n", |
---|
274 | HAVE_FAST_P_PROCS, HAVE_FAST_FIELD, HAVE_FAST_LENGTH, HAVE_FAST_ORD, |
---|
275 | HAVE_FAST_ZERO_ORD, NumberOfHaveProcs); |
---|
276 | |
---|
277 | #ifndef p_Procs_Static |
---|
278 | printf(" * |
---|
279 | * KernelProcs = %d |
---|
280 | * FieldIndepProcs = %d |
---|
281 | * FieldZpProcs = %d |
---|
282 | * FieldQProcs = %d |
---|
283 | * FieldGeneralProcs = %d |
---|
284 | * FieldUnknownProcs = %d\n", |
---|
285 | KernelProcs, FieldIndepProcs, FieldZpProcs,FieldQProcs, |
---|
286 | FieldGeneralProcs, UnknownProcs); |
---|
287 | #endif |
---|
288 | |
---|
289 | printf(" * |
---|
290 | *******************************************************************/\n"); |
---|
291 | } |
---|
292 | |
---|
293 | |
---|