[35aab3] | 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 |
---|
[e8a0aa] | 10 | * Version: $Id: p_Procs_Generate.cc,v 1.4 2008-08-06 13:55:42 Singular Exp $ |
---|
[35aab3] | 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 |
---|
| 30 | int FieldGeneralProcs = 0, |
---|
| 31 | FieldIndepProcs = 0, |
---|
| 32 | FieldZpProcs = 0, |
---|
| 33 | FieldQProcs = 0, |
---|
[009d80] | 34 | #ifdef HAVE_RINGS |
---|
| 35 | RingGeneralProcs = 0, |
---|
| 36 | #endif |
---|
[35aab3] | 37 | KernelProcs = 0, |
---|
| 38 | UnknownProcs = 0; |
---|
| 39 | |
---|
| 40 | // returns 1, if proc should go into kernel, 0 otherwise |
---|
| 41 | int 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 | |
---|
| 64 | char*** generated_p_procs; |
---|
| 65 | |
---|
| 66 | inline 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 | |
---|
[e8a0aa] | 71 | 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}; |
---|
[35aab3] | 72 | |
---|
| 73 | const char* macros_length[] = |
---|
| 74 | {"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL}; |
---|
| 75 | |
---|
| 76 | const char* macros_length_ord[] = {"p_MemCmp", NULL}; |
---|
| 77 | int DummyProcs = 0; |
---|
| 78 | |
---|
| 79 | int NumberOfHaveProcs = 0; |
---|
| 80 | |
---|
| 81 | void 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++; |
---|
[009d80] | 112 | #ifdef HAVE_RINGS |
---|
| 113 | else if (strcmp(module, "RingGeneral") == 0) |
---|
| 114 | RingGeneralProcs++; |
---|
| 115 | #endif |
---|
[35aab3] | 116 | else |
---|
| 117 | UnknownProcs++; |
---|
| 118 | |
---|
| 119 | printf("#ifdef p_Procs_%s\n", module); |
---|
| 120 | } |
---|
[009d80] | 121 | #endif |
---|
| 122 | #ifdef HAVE_RINGS |
---|
| 123 | if (strcmp(s_field, "RingGeneral") == 0) |
---|
| 124 | printf("#define HAVE_ZERODIVISORS\n"); |
---|
[35aab3] | 125 | #endif |
---|
| 126 | i = 0; |
---|
| 127 | while (macros_field[i] != NULL) |
---|
| 128 | { |
---|
| 129 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
| 130 | macros_field[i], macros_field[i], macros_field[i], s_field); |
---|
| 131 | i++; |
---|
| 132 | } |
---|
| 133 | i = 0; |
---|
| 134 | while (macros_length[i] != NULL) |
---|
| 135 | { |
---|
| 136 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
| 137 | macros_length[i], macros_length[i], macros_length[i], s_length); |
---|
| 138 | i++; |
---|
| 139 | } |
---|
| 140 | i = 0; |
---|
| 141 | while (macros_length_ord[i] != NULL) |
---|
| 142 | { |
---|
| 143 | printf("#undef %s\n#define %s\t%s_%s_%s\n", |
---|
| 144 | macros_length_ord[i], macros_length_ord[i], macros_length_ord[i], s_length, s_ord); |
---|
| 145 | i++; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | // define DECLARE_LENGTH |
---|
| 149 | printf("#undef DECLARE_LENGTH\n"); |
---|
| 150 | printf("#undef p_MemAddAdjust\n"); |
---|
| 151 | if (length != LengthGeneral) |
---|
| 152 | { |
---|
| 153 | printf("#define DECLARE_LENGTH(what) ((void)0)\n"); |
---|
| 154 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | printf("#define DECLARE_LENGTH(what) what\n"); |
---|
| 159 | if (proc != pp_Mult_Coeff_mm_DivSelectMult_Proc) |
---|
| 160 | printf("#define p_MemAddAdjust(p, r) p_MemAdd_NegWeightAdjust(p, r)\n"); |
---|
| 161 | else |
---|
| 162 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | // define DECLARE_ORDSGN |
---|
| 166 | printf("#undef DECLARE_ORDSGN\n"); |
---|
| 167 | if (ord != OrdGeneral) |
---|
| 168 | printf("#define DECLARE_ORDSGN(what) ((void)0)\n"); |
---|
| 169 | else |
---|
| 170 | printf("#define DECLARE_ORDSGN(what) what\n"); |
---|
| 171 | |
---|
| 172 | if (proc == pp_Mult_Coeff_mm_DivSelectMult_Proc) |
---|
| 173 | { |
---|
| 174 | printf("#undef DECLARE_LENGTH_2\n"); |
---|
| 175 | printf("#undef p_MemCmp_Bitmask_2\n"); |
---|
| 176 | if (length != LengthGeneral) |
---|
| 177 | { |
---|
| 178 | printf("#define DECLARE_LENGTH_2(what) ((void)0)\n"); |
---|
| 179 | if (length < LengthTwo) |
---|
| 180 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_%s\n", p_LengthEnum_2_String((p_Length) ((int) length + 2))); |
---|
| 181 | else |
---|
| 182 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthZero\n"); |
---|
| 183 | } |
---|
| 184 | else |
---|
| 185 | { |
---|
| 186 | printf("#define DECLARE_LENGTH_2(what) what \n"); |
---|
| 187 | printf("#define p_MemCmp_Bitmask_2 p_MemCmp_Bitmask_LengthGeneral\n"); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | printf("#undef p_MemAddAdjust\n"); |
---|
| 192 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | printf("#undef %s\n#define %s %s\n", s_what, s_what, s_full_proc_name); |
---|
| 196 | printf("#include \"%s__T.cc\"\n", s_what); |
---|
| 197 | printf("#undef %s\n", s_what); |
---|
[009d80] | 198 | #ifdef HAVE_RINGS |
---|
| 199 | if (strcmp(s_field, "RingGeneral") == 0) |
---|
| 200 | printf("#undef HAVE_ZERODIVISORS\n"); |
---|
| 201 | #endif |
---|
[35aab3] | 202 | #ifndef p_Procs_Static |
---|
| 203 | printf("#endif // p_Procs_[Kernel|Field*]\n"); |
---|
| 204 | #endif |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | void GenerateProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
| 208 | { |
---|
| 209 | if (! AlreadyHaveProc(proc, field, length, ord)) |
---|
| 210 | AddProc(s_what, proc, field, length, ord); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | int main() |
---|
| 214 | { |
---|
| 215 | int field = FieldGeneral; |
---|
| 216 | int length = LengthGeneral; |
---|
| 217 | int ord = OrdGeneral; |
---|
| 218 | int i; |
---|
| 219 | |
---|
| 220 | |
---|
| 221 | printf("/* -*-c++-*- */\n"); |
---|
| 222 | printf("/***************************************************************\n"); |
---|
| 223 | printf(" * This file was generated automatically by p_ProcsGenerate.cc: DO NOT EDIT\n"); |
---|
| 224 | printf(" *\n"); |
---|
| 225 | printf(" * This file provides the needed implementation of p_Procs for\n"); |
---|
| 226 | printf(" * %s\n", |
---|
| 227 | #if defined(p_Procs_Static) |
---|
| 228 | "p_Procs_Static" |
---|
| 229 | #else |
---|
| 230 | "p_Procs_Dynamic" |
---|
| 231 | #endif |
---|
| 232 | ); |
---|
| 233 | printf(" * See the end for a summary.\n"); |
---|
| 234 | printf(" *******************************************************************/\n"); |
---|
| 235 | |
---|
| 236 | |
---|
| 237 | generated_p_procs = (char***) malloc(p_Unknown_Proc*sizeof(char**)); |
---|
| 238 | for (i=0; i<p_Unknown_Proc; i++) |
---|
| 239 | { |
---|
| 240 | generated_p_procs[i] = |
---|
| 241 | (char**) calloc(index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown), sizeof(char*)); |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | // set default procs |
---|
| 245 | for (field = 0; field < (int) FieldUnknown; field++) |
---|
| 246 | { |
---|
| 247 | for (length=0; length < (int) LengthUnknown; length++) |
---|
| 248 | { |
---|
| 249 | for (ord=0; ord < (int)OrdUnknown; ord++) |
---|
| 250 | { |
---|
| 251 | if (IsValidSpec((p_Field) field, (p_Length) length, (p_Ord) ord)) |
---|
| 252 | SetProcs((p_Field) field, (p_Length) length, (p_Ord) ord); |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | // we only need lookup tables for p_Procs_Static |
---|
| 258 | #ifdef p_Procs_Static |
---|
| 259 | int j; |
---|
| 260 | printf("\n" |
---|
| 261 | "/***************************************************************\n" |
---|
| 262 | "Names of procs for RDEBUG */\n" |
---|
| 263 | "#ifdef RDEBUG\n"); |
---|
| 264 | |
---|
| 265 | for (i=0; i<p_Unknown_Proc; i++) |
---|
| 266 | { |
---|
| 267 | printf("static const char* %s_names[] = {", p_ProcEnum_2_String((p_Proc)i)); |
---|
| 268 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
| 269 | { |
---|
| 270 | char* s = (generated_p_procs[i])[j]; |
---|
| 271 | if (s != 0) |
---|
| 272 | { |
---|
| 273 | printf("\n\"%s\",", s); |
---|
| 274 | } |
---|
| 275 | else |
---|
| 276 | printf("0,"); |
---|
| 277 | |
---|
| 278 | } |
---|
| 279 | printf("\n};\n"); |
---|
| 280 | } |
---|
| 281 | printf("\n #endif // RDEBUG\n\n" |
---|
| 282 | "/***************************************************************/\n" |
---|
| 283 | "/* Tables for lookup of procedures: */\n"); |
---|
| 284 | |
---|
| 285 | for (i=0; i<p_Unknown_Proc; i++) |
---|
| 286 | { |
---|
| 287 | printf("static const %s_Ptr %s_funcs[] = {", p_ProcEnum_2_String((p_Proc)i), p_ProcEnum_2_String((p_Proc)i)); |
---|
| 288 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
| 289 | { |
---|
| 290 | char* s = (generated_p_procs[i])[j]; |
---|
| 291 | if (s != 0) |
---|
| 292 | { |
---|
| 293 | printf("\n%s,", s); |
---|
| 294 | } |
---|
| 295 | else |
---|
| 296 | printf("0,"); |
---|
| 297 | } |
---|
| 298 | printf("\n};\n"); |
---|
| 299 | } |
---|
| 300 | #endif |
---|
| 301 | |
---|
| 302 | printf("\n/***************************************************************"); |
---|
| 303 | printf("* Summary:\n"); |
---|
| 304 | printf("* HAVE_FAST_P_PROCS = %d,\n",HAVE_FAST_P_PROCS); |
---|
| 305 | printf("* HAVE_FAST_FIELD = %d,\n",HAVE_FAST_FIELD); |
---|
| 306 | printf("* HAVE_FAST_LENGTH = %d,\n",HAVE_FAST_LENGTH); |
---|
| 307 | printf("* HAVE_FAST_ORD = %d,\n",HAVE_FAST_ORD); |
---|
| 308 | printf("* HAVE_FAST_ZERO_ORD = %d\n",HAVE_FAST_ZERO_ORD); |
---|
| 309 | printf("*\n"); |
---|
| 310 | printf("* Generated PolyProcs= %d\n",NumberOfHaveProcs); |
---|
| 311 | |
---|
| 312 | #ifndef p_Procs_Static |
---|
| 313 | printf(" *\n"); |
---|
| 314 | printf("* KernelProcs = %d\n",KernelProcs); |
---|
| 315 | printf("* FieldIndepProcs = %d\n",FieldIndepProcs); |
---|
| 316 | printf("* FieldZpProcs = %d\n",FieldZpProcs); |
---|
| 317 | printf("* FieldQProcs = %d\n",FieldQProcs); |
---|
| 318 | printf("* FieldGeneralProcs = %d\n",FieldGeneralProcs); |
---|
| 319 | printf("* FieldUnknownProcs = %d\n",UnknownProcs); |
---|
| 320 | #endif |
---|
| 321 | |
---|
| 322 | printf("*\n"); |
---|
| 323 | printf("*******************************************************************/\n"); |
---|
| 324 | } |
---|
| 325 | |
---|
| 326 | |
---|