source: git/libpolys/polys/templates/p_Procs_Generate.cc @ 14a0ca

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