source: git/kernel/p_Procs_Generate.cc @ 2f6ca63

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