source: git/kernel/p_Procs_Generate.cc @ 68349d

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