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