[7e5a38] | 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 |
---|
[50cbdc] | 10 | * Version: $Id: p_Procs_Generate.cc,v 1.5 2001-08-27 14:47:28 Singular Exp $ |
---|
[7e5a38] | 11 | *******************************************************************/ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | #include <stdio.h> |
---|
| 15 | #include <stdlib.h> |
---|
[50cbdc] | 16 | #include <string.h> |
---|
[7e5a38] | 17 | |
---|
| 18 | #include "mod2.h" |
---|
| 19 | #include "dError.c" |
---|
| 20 | |
---|
| 21 | #ifdef p_Procs_Static |
---|
| 22 | #include "p_Procs_Static.h" |
---|
[6b32990] | 23 | #else |
---|
[7e5a38] | 24 | #include "p_Procs_Dynamic.h" |
---|
| 25 | #endif |
---|
| 26 | |
---|
| 27 | #include "p_Procs_Impl.h" |
---|
| 28 | |
---|
[6b32990] | 29 | #ifndef p_Procs_Static |
---|
| 30 | int 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 |
---|
| 38 | int 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; |
---|
[50cbdc] | 43 | |
---|
[6b32990] | 44 | // plus procs with FieldZp |
---|
[50cbdc] | 45 | if ((field == FieldZp || field == FieldQ) && |
---|
[6b32990] | 46 | // which are not general in length or ord |
---|
| 47 | !((length == LengthGeneral && p_ProcDependsOn_Length(proc)) || |
---|
| 48 | (ord == OrdGeneral && p_ProcDependsOn_Ord(proc))) && |
---|
[50cbdc] | 49 | // and whose length is smaller than five |
---|
[6b32990] | 50 | (!p_ProcDependsOn_Length(proc) || (length >= LengthFour))) |
---|
| 51 | return 1; |
---|
[bfbc32] | 52 | |
---|
[6b32990] | 53 | return 0; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | #endif |
---|
| 57 | |
---|
[7e5a38] | 58 | #define DoSetProc(what, field, length, ord) \ |
---|
| 59 | GenerateProc(#what, what##_Proc, field, length, ord) |
---|
| 60 | |
---|
| 61 | char*** generated_p_procs; |
---|
| 62 | |
---|
| 63 | inline 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 | |
---|
| 68 | const char* macros_field[] = {"n_Copy","n_Delete", "n_Mult", "n_Add", "n_Sub", "n_IsZero", "n_Equal" , "n_Neg", NULL}; |
---|
| 69 | |
---|
| 70 | const char* macros_length[] = |
---|
[2f436b] | 71 | {"p_MemCopy", "p_MemAdd", "p_MemSum", "p_MemDiff", NULL}; |
---|
[7e5a38] | 72 | |
---|
| 73 | const char* macros_length_ord[] = {"p_MemCmp", NULL}; |
---|
| 74 | int DummyProcs = 0; |
---|
| 75 | |
---|
| 76 | int NumberOfHaveProcs = 0; |
---|
| 77 | |
---|
| 78 | void 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); |
---|
[50cbdc] | 86 | |
---|
[7e5a38] | 87 | sprintf(s_full_proc_name, "%s__%s_%s_%s", s_what, s_field, s_length, s_ord); |
---|
[50cbdc] | 88 | |
---|
[7e5a38] | 89 | (generated_p_procs[proc])[index(proc, field, length, ord)] = s_full_proc_name; |
---|
[50cbdc] | 90 | // define all macros |
---|
[7e5a38] | 91 | printf("\n// definition of %s\n", s_full_proc_name); |
---|
[6b32990] | 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 | } |
---|
[50cbdc] | 114 | #endif |
---|
[7e5a38] | 115 | i = 0; |
---|
| 116 | while (macros_field[i] != NULL) |
---|
| 117 | { |
---|
[50cbdc] | 118 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
[7e5a38] | 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 | { |
---|
[50cbdc] | 125 | printf("#undef %s\n#define %s\t%s_%s\n", |
---|
[7e5a38] | 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 | { |
---|
[50cbdc] | 132 | printf("#undef %s\n#define %s\t%s_%s_%s\n", |
---|
[7e5a38] | 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"); |
---|
[2f436b] | 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"); |
---|
[7e5a38] | 152 | } |
---|
[50cbdc] | 153 | |
---|
[7e5a38] | 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 | |
---|
[2f436b] | 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 | } |
---|
[50cbdc] | 178 | |
---|
| 179 | |
---|
[2f436b] | 180 | printf("#undef p_MemAddAdjust\n"); |
---|
| 181 | printf("#define p_MemAddAdjust(p, r) ((void)0)\n"); |
---|
| 182 | } |
---|
| 183 | |
---|
[7e5a38] | 184 | printf("#undef %s\n#define %s %s\n", s_what, s_what, s_full_proc_name); |
---|
[50cbdc] | 185 | printf("#include \"%s__T.cc\"\n", s_what); |
---|
[7e5a38] | 186 | printf("#undef %s\n", s_what); |
---|
[6b32990] | 187 | #ifndef p_Procs_Static |
---|
| 188 | printf("#endif // p_Procs_[Kernel|Field*]\n"); |
---|
| 189 | #endif |
---|
[7e5a38] | 190 | } |
---|
| 191 | |
---|
| 192 | void GenerateProc(const char* s_what, p_Proc proc, p_Field field, p_Length length, p_Ord ord) |
---|
| 193 | { |
---|
[6b32990] | 194 | if (! AlreadyHaveProc(proc, field, length, ord)) |
---|
[7e5a38] | 195 | AddProc(s_what, proc, field, length, ord); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | int main() |
---|
| 199 | { |
---|
| 200 | int field = FieldGeneral; |
---|
| 201 | int length = LengthGeneral; |
---|
| 202 | int ord = OrdGeneral; |
---|
| 203 | int i; |
---|
| 204 | |
---|
[50cbdc] | 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", |
---|
[6b32990] | 212 | #if defined(p_Procs_Static) |
---|
| 213 | "p_Procs_Static" |
---|
[7e5a38] | 214 | #else |
---|
[6b32990] | 215 | "p_Procs_Dynamic" |
---|
[7e5a38] | 216 | #endif |
---|
[50cbdc] | 217 | ); |
---|
| 218 | printf(" * See the end for a summary.\n"); |
---|
| 219 | printf(" *******************************************************************/\n"); |
---|
| 220 | |
---|
[7e5a38] | 221 | |
---|
| 222 | generated_p_procs = (char***) malloc(p_Unknown_Proc*sizeof(char**)); |
---|
| 223 | for (i=0; i<p_Unknown_Proc; i++) |
---|
| 224 | { |
---|
[50cbdc] | 225 | generated_p_procs[i] = |
---|
[7e5a38] | 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(" |
---|
| 246 | /*************************************************************** |
---|
| 247 | Names of procs for RDEBUG */ |
---|
| 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,"); |
---|
[50cbdc] | 262 | |
---|
[7e5a38] | 263 | } |
---|
| 264 | printf("\n};\n"); |
---|
| 265 | } |
---|
| 266 | printf(" |
---|
| 267 | #endif // RDEBUG |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | /***************************************************************/ |
---|
| 271 | /* Tables for lookup of procedures: */\n"); |
---|
| 272 | |
---|
| 273 | for (i=0; i<p_Unknown_Proc; i++) |
---|
| 274 | { |
---|
| 275 | printf("static const %s_Ptr %s_funcs[] = {", p_ProcEnum_2_String((p_Proc)i), p_ProcEnum_2_String((p_Proc)i)); |
---|
| 276 | for (j=0;j<index((p_Proc)i, FieldUnknown, LengthUnknown, OrdUnknown); j++) |
---|
| 277 | { |
---|
| 278 | char* s = (generated_p_procs[i])[j]; |
---|
| 279 | if (s != 0) |
---|
| 280 | { |
---|
| 281 | printf("\n%s,", s); |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | printf("0,"); |
---|
[50cbdc] | 285 | |
---|
[7e5a38] | 286 | } |
---|
| 287 | printf("\n};\n"); |
---|
| 288 | } |
---|
| 289 | #endif |
---|
| 290 | |
---|
[50cbdc] | 291 | printf("\n/***************************************************************"); |
---|
| 292 | printf("* Summary:\n"); |
---|
| 293 | printf("* HAVE_FAST_P_PROCS = %d,\n",HAVE_FAST_P_PROCS); |
---|
| 294 | printf("* HAVE_FAST_FIELD = %d,\n",HAVE_FAST_FIELD); |
---|
| 295 | printf("* HAVE_FAST_LENGTH = %d,\n",HAVE_FAST_LENGTH); |
---|
| 296 | printf("* HAVE_FAST_ORD = %d,\n",HAVE_FAST_ORD); |
---|
| 297 | printf("* HAVE_FAST_ZERO_ORD = %d\n",HAVE_FAST_ZERO_ORD); |
---|
| 298 | printf("*\n"); |
---|
| 299 | printf("* Generated PolyProcs= %d\n",NumberOfHaveProcs); |
---|
[6b32990] | 300 | |
---|
| 301 | #ifndef p_Procs_Static |
---|
[50cbdc] | 302 | printf(" *\n"); |
---|
| 303 | printf("* KernelProcs = %d\n",KernelProcs); |
---|
| 304 | printf("* FieldIndepProcs = %d\n",FieldIndepProcs); |
---|
| 305 | printf("* FieldZpProcs = %d\n",FieldZpProcs); |
---|
| 306 | printf("* FieldQProcs = %d\n",FieldQProcs); |
---|
| 307 | printf("* FieldGeneralProcs = %d\n",FieldGeneralProcs); |
---|
| 308 | printf("* FieldUnknownProcs = %d\n",UnknownProcs); |
---|
| 309 | #endif |
---|
| 310 | |
---|
| 311 | printf("*\n"); |
---|
| 312 | printf("*******************************************************************/\n"); |
---|
[7e5a38] | 313 | } |
---|
| 314 | |
---|
| 315 | |
---|