00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "reg_gen.h"
00043
00044 static const char * const reg_descript[]= {
00045 "/* ====================================================================",
00046 " * ====================================================================",
00047 " *",
00048 " * Description:",
00049 " *",
00050 " * A description of the ISA registers. The description exports",
00051 " * the following:",
00052 " *",
00053 " * typedef (enum) ISA_REGISTER_CLASS",
00054 " * An enumeration of the register classes.",
00055 " *",
00056 " * typedef mISA_REGISTER_CLASS",
00057 " * The most compact (integral) representation that can hold",
00058 " * all values of ISA_REGISTER_CLASS",
00059 " *",
00060 " * typedef (struct) ISA_REGISTER_CLASS_INFO",
00061 " * Describes a particular register class. The contents are private.",
00062 " *",
00063 " * const INT ISA_REGISTER_CLASS_UNDEFINED",
00064 " * A special register class that is out-of-range of valid",
00065 " * register clases.",
00066 " *",
00067 " * const INT ISA_REGISTER_CLASS_MIN",
00068 " * The first register class. The range of register classes",
00069 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00070 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED). * ",
00071 " * const INT ISA_REGISTER_CLASS_MAX",
00072 " * The last register class. The range of register classes",
00073 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00074 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED). * ",
00075 " * const INT ISA_REGISTER_CLASS_COUNT",
00076 " * The number of register classes. The range of register classes",
00077 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00078 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED). * ",
00079 " * (macro) FOR_ALL_ISA_REGISTER_CLASS(cl)",
00080 " * Iterate over all the register class values using the",
00081 " * ISA_REGISTER_CLASS variable <cl>.",
00082 " *",
00083 " * (macro) FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl)",
00084 " * Iterate over all the register class values in reverse order using",
00085 " * the ISA_REGISTER_CLASS variable <cl>.",
00086 " *",
00087 " * const INT ISA_REGISTER_MAX",
00088 " * The maximum (highest) register number of all classes.",
00089 " * NOTE: the lowest number register is implicitly 0.",
00090 " *",
00091 " * typedef (enum) ISA_REGISTER_SUBCLASS",
00092 " * An enumeration of the register subclasses.",
00093 " *",
00094 " * typedef mISA_REGISTER_SUBCLASS",
00095 " * The most compact (integral) representation that can hold",
00096 " * all values of ISA_REGISTER_SUBCLASS",
00097 " *",
00098 " * typedef (struct) ISA_REGISTER_SUBCLASS_INFO",
00099 " * Describes a particular register subclass. The contents are private.",
00100 " *",
00101 " * const INT ISA_REGISTER_SUBCLASS_UNDEFINED",
00102 " * A special register subclass that is out-of-range of valid",
00103 " * register subclases.",
00104 " *",
00105 " * const INT ISA_REGISTER_SUBCLASS_MIN",
00106 " * The first register subclass. The range of register subclasses",
00107 " * is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00108 " * ",
00109 " * const INT ISA_REGISTER_SUBCLASS_MAX",
00110 " * The last register subclass. The range of register subclasses",
00111 " * is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00112 " * ",
00113 " * const INT ISA_REGISTER_SUBCLASS_COUNT",
00114 " * The number of register subclasses.",
00115 " * ",
00116 " * (macro) FOR_ALL_ISA_REGISTER_SUBCLASS(sc)",
00117 " * Iterate over all the register subclass values using the",
00118 " * the ISA_REGISTER_SUBCLASS variable <sc>.",
00119 " *",
00120 " * const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(",
00121 " * ISA_REGISTER_CLASS rc",
00122 " * )",
00123 " * Return a pointer to the register class info for class 'rc'.",
00124 " *",
00125 " * INT ISA_REGISTER_CLASS_INFO_First_Reg(",
00126 " * const ISA_REGISTER_CLASS_INFO *info",
00127 " * )",
00128 " * Get the first (lowest numbered) register for the class",
00129 " * described by 'info'.",
00130 " *",
00131 " * INT ISA_REGISTER_CLASS_INFO_Last_Reg(",
00132 " * const ISA_REGISTER_CLASS_INFO *info",
00133 " * )",
00134 " * Get the last (highest numbered) register for the class",
00135 " * described by 'info'.",
00136 " *",
00137 " * INT ISA_REGISTER_CLASS_INFO_Bit_Size(",
00138 " * const ISA_REGISTER_CLASS_INFO *info",
00139 " * )",
00140 " * Get the size, in bits, of the register in the class",
00141 " * described by 'info'.",
00142 " *",
00143 " * BOOL ISA_REGISTER_CLASS_INFO_Can_Store(",
00144 " * const ISA_REGISTER_CLASS_INFO *info",
00145 " * )",
00146 " * Return a flag that indicates if the registers in the class",
00147 " * described by 'info' can be stored to memory, i.e. there",
00148 " * is a store instruction for the registers in the class.",
00149 " *",
00150 " * BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(",
00151 " * const ISA_REGISTER_CLASS_INFO *info",
00152 " * )",
00153 " * Return a flag that indicates if the registers in the class",
00154 " * described by 'info' can be saved and restore to memory in",
00155 " * multiples, i.e. as a group.",
00156 " *",
00157 " * const char *ISA_REGISTER_CLASS_INFO_Name(",
00158 " * const ISA_REGISTER_CLASS_INFO *info",
00159 " * )",
00160 " * Return the name of the class described by 'info'.",
00161 " *",
00162 " * const char *ISA_REGISTER_CLASS_INFO_Reg_Name(",
00163 " * const ISA_REGISTER_CLASS_INFO *info,",
00164 " * INT reg_index",
00165 " * )",
00166 " * Return the name of the 'reg_index'th register in the",
00167 " * class described by 'info'. NOTE: reg_index==0 corresponds",
00168 " * to the first register of the class.",
00169 " *",
00170 " * const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(",
00171 " * ISA_REGISTER_SUBCLASS sc",
00172 " * )",
00173 " *",
00174 " * Return a pointer to the register subclass info for the",
00175 " * subclass 'sc'.",
00176 " *",
00177 " * const char *ISA_REGISTER_SUBCLASS_INFO_Name(",
00178 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00179 " * )",
00180 " *",
00181 " * Return the name of the subclass described by 'info'.",
00182 " *",
00183 " * ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(",
00184 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00185 " * )",
00186 " *",
00187 " * Return the base register class for the subclass described",
00188 " * by 'info'.",
00189 " *",
00190 " * INT ISA_REGISTER_SUBCLASS_INFO_Count(",
00191 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00192 " * )",
00193 " *",
00194 " * Return the number of registers in the subclass described",
00195 " * by 'info'.",
00196 " *",
00197 " * UINT ISA_REGISTER_SUBCLASS_INFO_Member(",
00198 " * const ISA_REGISTER_SUBCLASS_INFO *info,",
00199 " * INT n",
00200 " * )",
00201 " *",
00202 " * Return the 'n'th member (register) of the subclass described",
00203 " * by 'info'. The order of the registers returned is arbitrary.",
00204 " *",
00205 " * const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(",
00206 " * const ISA_REGISTER_SUBCLASS_INFO *info,",
00207 " * INT index",
00208 " * )",
00209 " *",
00210 " * Return the 'n'th member's register name of the subclass",
00211 " * described by 'info'. If the member does not have a subclass",
00212 " * specific name, NULL is returned.",
00213 " *",
00214 " * void ISA_REGISTER_Initialize(void)",
00215 " * Initialize the register package for use with the ISA specified",
00216 " * by ISA_SUBSET_Value.",
00217 " *",
00218 " * ====================================================================",
00219 " * ====================================================================",
00220 " */", NULL};
00221
00222
00223 static const char reg_class_iter[]= "\
00224 typedef mUINT8 mISA_REGISTER_CLASS;\n\
00225 \n\
00226 #define FOR_ALL_ISA_REGISTER_CLASS(cl) \\\n\
00227 for (cl = ISA_REGISTER_CLASS_MIN; \\\n\
00228 cl <= ISA_REGISTER_CLASS_MAX; \\\n\
00229 cl = (ISA_REGISTER_CLASS)(cl + 1))\n\
00230 \n\
00231 #define FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl) \\\n\
00232 for (cl = ISA_REGISTER_CLASS_MAX; \\\n\
00233 cl >= ISA_REGISTER_CLASS_MIN; \\\n\
00234 cl = (ISA_REGISTER_CLASS)(cl - 1))\n\
00235 \n\
00236 typedef struct {\n\
00237 mUINT8 isa_mask;\n\
00238 mUINT8 min_regnum;\n\
00239 mUINT8 max_regnum;\n\
00240 mUINT8 bit_size;\n\
00241 mBOOL can_store;\n\
00242 mBOOL multiple_save;\n\
00243 const char *name;\n\
00244 const char *reg_name[ISA_REGISTER_MAX+1];\n\
00245 } ISA_REGISTER_CLASS_INFO;\n\n";
00246
00247 static const char * const reg_subclass_query[]={
00248 "typedef mUINT8 mISA_REGISTER_SUBCLASS;",
00249 "",
00250 "#define FOR_ALL_ISA_REGISTER_SUBCLASS(sc) \\",
00251 " for (sc = ISA_REGISTER_SUBCLASS_MIN; \\",
00252 " sc <= ISA_REGISTER_SUBCLASS_MAX; \\",
00253 " sc = (ISA_REGISTER_SUBCLASS)(sc + 1))",
00254 "",
00255 "typedef struct {",
00256 " const char *name;",
00257 " mISA_REGISTER_CLASS rclass;",
00258 " mUINT8 count;",
00259 " mUINT8 members[ISA_REGISTER_MAX+1];",
00260 " const char *reg_name[ISA_REGISTER_MAX+1];",
00261 "} ISA_REGISTER_SUBCLASS_INFO;",
00262 "",
00263 "inline const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(",
00264 " ISA_REGISTER_CLASS rc",
00265 ")",
00266 "{",
00267 " extern const ISA_REGISTER_CLASS_INFO ISA_REGISTER_CLASS_info[];",
00268 " extern mUINT8 ISA_REGISTER_CLASS_info_index[];",
00269 " INT index = ISA_REGISTER_CLASS_info_index[(INT)rc];",
00270 " return &ISA_REGISTER_CLASS_info[index];",
00271 "}",
00272 "",
00273 "inline INT ISA_REGISTER_CLASS_INFO_First_Reg(",
00274 " const ISA_REGISTER_CLASS_INFO *info",
00275 ")",
00276 "{",
00277 " return info->min_regnum;",
00278 "}",
00279 "",
00280 "inline INT ISA_REGISTER_CLASS_INFO_Last_Reg(",
00281 " const ISA_REGISTER_CLASS_INFO *info",
00282 ")",
00283 "{",
00284 " return info->max_regnum;",
00285 "}",
00286 "",
00287 "inline INT ISA_REGISTER_CLASS_INFO_Bit_Size(",
00288 " const ISA_REGISTER_CLASS_INFO *info",
00289 ")",
00290 "{",
00291 " return info->bit_size;",
00292 "}",
00293 "",
00294 "inline BOOL ISA_REGISTER_CLASS_INFO_Can_Store(",
00295 " const ISA_REGISTER_CLASS_INFO *info",
00296 ")",
00297 "{",
00298 " return info->can_store;",
00299 "}",
00300 "",
00301 "inline BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(",
00302 " const ISA_REGISTER_CLASS_INFO *info",
00303 ")",
00304 "{",
00305 " return info->multiple_save;",
00306 "}",
00307 "",
00308 "inline const char *ISA_REGISTER_CLASS_INFO_Name(",
00309 " const ISA_REGISTER_CLASS_INFO *info",
00310 ")",
00311 "{",
00312 " return info->name;",
00313 "}",
00314 "",
00315 "inline const char *ISA_REGISTER_CLASS_INFO_Reg_Name(",
00316 " const ISA_REGISTER_CLASS_INFO *info,",
00317 " INT reg_index",
00318 ")",
00319 "{",
00320 " return info->reg_name[reg_index];",
00321 "}",
00322 "",
00323 "inline const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(",
00324 " ISA_REGISTER_SUBCLASS sc",
00325 ")",
00326 "{",
00327 " extern const ISA_REGISTER_SUBCLASS_INFO ISA_REGISTER_SUBCLASS_info[];",
00328 " return &ISA_REGISTER_SUBCLASS_info[sc];",
00329 "}",
00330 "",
00331 "inline const char *ISA_REGISTER_SUBCLASS_INFO_Name(",
00332 " const ISA_REGISTER_SUBCLASS_INFO *info",
00333 ")",
00334 "{",
00335 " return info->name;",
00336 "}",
00337 "",
00338 "inline ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(",
00339 " const ISA_REGISTER_SUBCLASS_INFO *info",
00340 ")",
00341 "{",
00342 " return (ISA_REGISTER_CLASS)info->rclass;",
00343 "}",
00344 "",
00345 "inline INT ISA_REGISTER_SUBCLASS_INFO_Count(",
00346 " const ISA_REGISTER_SUBCLASS_INFO *info",
00347 ")",
00348 "{",
00349 " return info->count;",
00350 "}",
00351 "",
00352 "inline UINT ISA_REGISTER_SUBCLASS_INFO_Member(",
00353 " const ISA_REGISTER_SUBCLASS_INFO *info,",
00354 " INT n",
00355 ")",
00356 "{",
00357 " return info->members[n];",
00358 "}",
00359 "",
00360 "inline const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(",
00361 " const ISA_REGISTER_SUBCLASS_INFO *info,",
00362 " INT n",
00363 ")",
00364 "{",
00365 " return info->reg_name[n];",
00366 "}",
00367 "",
00368 "extern void ISA_REGISTER_Initialize(void);\n", NULL};
00369
00370 static const char init_reg_func[]= "\
00371 void ISA_REGISTER_Initialize(void)\n\
00372 {\n\
00373 INT rc;\n\
00374 INT mask = 1 << (INT)ISA_SUBSET_Value;\n\
00375 for (rc = ISA_REGISTER_CLASS_MIN; rc <= ISA_REGISTER_CLASS_MAX; ++rc) {\n\
00376 INT i = ISA_REGISTER_CLASS_info_index[rc];\n\
00377 const ISA_REGISTER_CLASS_INFO *info = &ISA_REGISTER_CLASS_info[i];\n\
00378 while ((info->isa_mask & mask) == 0) ++info, ++i;\n\
00379 ISA_REGISTER_CLASS_info_index[rc] = i;\n\
00380 }\n\
00381 }\n";
00382
00383
00384 static const char * const abi_descript[]= {
00385 "/* ====================================================================",
00386 " * ====================================================================",
00387 " *",
00388 " * Description:",
00389 " *",
00390 " * A description of the ABI properties. The description exports",
00391 " * the following:",
00392 " *",
00393 " * typedef (enum) ABI_PROPERTIES_ABI",
00394 " *",
00395 " * An enumeration of the ABIs described. The names have the form:",
00396 " *",
00397 " * ABI_PROPERTIES_ABI_xxx",
00398 " *",
00399 " * where 'xxx' is replaced with the ABI name.",
00400 " *",
00401 " * const ABI_PROPERTIES_ABI ABI_PROPERTIES_ABI_UNDEFINED",
00402 " * Useful value guaranteed not to be a valid ABI_PROPERTIES_ABI.",
00403 " *",
00404 " * ABI_PROPERTIES_ABI ABI_PROPERTIES_ABI_Value",
00405 " * A variable containing the current ABI value.",
00406 " *",
00407 " * const char *ABI_PROPERTIES_ABI_Name(ABI_PROPERTIES_ABI abi)",
00408 " * Returns a name for the given 'abi'.",
00409 " *",
00410 " * void ABI_PROPERTIES_Initialize(void)",
00411 " * Initialize for the target ABI specified by ABI_PROPERTIES_ABI_Value.",
00412 " *",
00413 " * const char *ABI_PROPERTY_Reg_Name(",
00414 " * ISA_REGISTER_CLASS rc,",
00415 " * INT reg",
00416 " * )",
00417 " * Return the ABI specific name of register 'reg' in class 'rc'.",
00418 " *",
00419 " * BOOL ABI_PROPERTY_Is_xxx(",
00420 " * ISA_REGISTER_CLASS rc,",
00421 " * INT reg",
00422 " * )",
00423 " * Return a boolean that indicates if register 'reg' in class",
00424 " * 'rc' had the property 'xxx'.",
00425 " *",
00426 " * ====================================================================",
00427 " * ====================================================================",
00428 " */", NULL};
00429
00430 static const char abi_common[]="\
00431 extern ABI_PROPERTIES_ABI ABI_PROPERTIES_ABI_Value;\n\
00432 \n\
00433 extern const char *ABI_PROPERTIES_ABI_Name(ABI_PROPERTIES_ABI abi);\n\
00434 \n\
00435 extern void ABI_PROPERTIES_Initialize(void);\n\
00436 \n\
00437 inline const char *ABI_PROPERTY_Reg_Name(\n\
00438 ISA_REGISTER_CLASS rc,\n\
00439 INT reg)\n\
00440 {\n\
00441 extern const ABI_PROPERTIES *ABI_PROPERTIES_target_props;\n\
00442 return ABI_PROPERTIES_target_props->reg_names[rc][reg];\n\
00443 }\n\n";
00444
00445 const char abi_com_func[]="\
00446 ABI_PROPERTIES_ABI ABI_PROPERTIES_ABI_Value = ABI_PROPERTIES_ABI_UNDEFINED;\n\
00447 \n\
00448 const char *ABI_PROPERTIES_ABI_Name(ABI_PROPERTIES_ABI abi)\n\
00449 {\n\
00450 return abi_names[(INT)abi];\n\
00451 }\n\
00452 \n\
00453 const ABI_PROPERTIES *ABI_PROPERTIES_target_props = &abi_properties[ABI_PROPERTIES_ABI_UNDEFINED];\n\
00454 \n\
00455 void ABI_PROPERTIES_Initialize(void)\n\
00456 {\n\
00457 ABI_PROPERTIES_target_props = &abi_properties[(INT)ABI_PROPERTIES_ABI_Value];\n\
00458 }\n";
00459
00460
00461 void Register_Generator(void *pknobs, GEN_MODE mode)
00462 {
00463
00464
00465 FILE *c_file, *h_file, *export_file;
00466 int reg_class_count = EKAPI_RegClassCount(pknobs);
00467 int index;
00468 int max_reg_count = 0;
00469 EKAPI_REGISTER_CLASS_INFO *reg_class_info = (EKAPI_REGISTER_CLASS_INFO*)
00470 malloc(reg_class_count*sizeof(EKAPI_REGISTER_CLASS_INFO));
00471
00472 for (index=0; index<reg_class_count; index++){
00473 EKAPI_RegStruct4id(pknobs, ®_class_info[index], index);
00474 if (EKAPI_GetRegMaxNum(®_class_info[index]) > max_reg_count){
00475 max_reg_count = EKAPI_GetRegMaxNum(®_class_info[index]);
00476 }
00477 }
00478
00479
00480
00481
00482 Init_Module_Files(mode, "targ_isa_registers", &c_file, &h_file,
00483 &export_file);
00484 Emit_Header(h_file, "targ_isa_registers", reg_descript);
00485 fprintf(h_file, "#include \"targ_isa_subset.h\"\n\n");
00486 fprintf(c_file, "#include \"targ_isa_subset.h\"\n");
00487 fprintf(c_file, "#include \"targ_isa_registers.h\"\n\n");
00488
00489 fprintf(h_file, "\n#define ISA_REGISTER_FIRST (%d)\n", 0);
00490 fprintf(h_file, "#define ISA_REGISTER_MAX (%d)\n\n", max_reg_count);
00491
00493
00494 fprintf(h_file, "typedef enum {\n ISA_REGISTER_CLASS_UNDEFINED,\n");
00495 for (index=0; index<reg_class_count; index++){
00496 fprintf(h_file, " ISA_REGISTER_CLASS_%s,\n",
00497 EKAPI_GetRegClassName(®_class_info[index]));
00498 }
00499 fprintf(h_file, " ISA_REGISTER_CLASS_MIN = ISA_REGISTER_CLASS_%s,\n",
00500 EKAPI_GetRegClassName(®_class_info[0]));
00501 fprintf(h_file, " ISA_REGISTER_CLASS_MAX = ISA_REGISTER_CLASS_%s,\n",
00502 EKAPI_GetRegClassName(®_class_info[reg_class_count-1]));
00503 fprintf(h_file, " ISA_REGISTER_CLASS_COUNT = ISA_REGISTER_CLASS_MAX - ISA_REGISTER_CLASS_MIN + 1\n");
00504 fprintf(h_file, "} ISA_REGISTER_CLASS;\n\n");
00505
00506 fprintf(h_file, "%s", reg_class_iter);
00507
00509
00510 fprintf(export_file, "ISA_REGISTER_CLASS_info\n");
00511 fprintf(c_file, "const ISA_REGISTER_CLASS_INFO ISA_REGISTER_CLASS_info[] = {\n");
00512 fprintf(c_file, " { 0x00, 0, -1, 0, 0, 0, \"UNDEFINED\", { 0 } },\n");
00513 for (index=0; index<reg_class_count; index++){
00514 fprintf(c_file, " { 0x%02x, %3d, %3d, %2d, %d, %d, \"%s\",",
00515 EKAPI_GetRegIsaMask(®_class_info[index]),
00516 EKAPI_GetRegMinNum(®_class_info[index]),
00517 EKAPI_GetRegMaxNum(®_class_info[index]),
00518 EKAPI_GetRegBitSize(®_class_info[index]),
00519 EKAPI_GetRegCanStore(®_class_info[index]),
00520 EKAPI_GetRegMultiSave(®_class_info[index]),
00521 EKAPI_GetRegClassName(®_class_info[index]));
00522 int len=fprintf(c_file, "\n { ");
00523 for (int i=EKAPI_GetRegMinNum(®_class_info[index]);
00524 i<EKAPI_GetRegMaxNum(®_class_info[index]); i++){
00525 if (len > 70){ len = fprintf(c_file, "\n ");}
00526 len += fprintf(c_file, "\"%s\", ",
00527 EKAPI_GetRegName(pknobs,®_class_info[index],i));
00528 }
00529 if (len > 70){ len = fprintf(c_file, "\n ");}
00530 fprintf(c_file, "\"%s\" } },\n",
00531 EKAPI_GetRegName(pknobs,®_class_info[index],
00532 EKAPI_GetRegMaxNum(®_class_info[index])));
00533 }
00534 fprintf(c_file, "};\n\n");
00535
00536 fprintf(export_file, "ISA_REGISTER_CLASS_info_index\n");
00537 fprintf(c_file, "mUINT8 ISA_REGISTER_CLASS_info_index[] = {\n");
00538 fprintf(c_file, " 0, /* ISA_REGISTER_CLASS_UNDEFINED */\n");
00539 for (index=0; index<reg_class_count; index++){
00540 fprintf(c_file, " %d, /* ISA_REGISTER_CLASS_%s */\n",
00541 index+1, EKAPI_GetRegClassName(®_class_info[index]));
00542 }
00543 fprintf(c_file, "};\n\n");
00544
00545
00547
00548 int subclass_count = EKAPI_RegSubclassCount(pknobs);
00549 fprintf(h_file, "typedef enum {\n ISA_REGISTER_SUBCLASS_UNDEFINED,\n");
00550 for (index=0; index<subclass_count; index++){
00551 fprintf(h_file, " ISA_REGISTER_SUBCLASS_%s,\n",
00552 EKAPI_RegSubclassName(pknobs,index));
00553 }
00554 fprintf(h_file," ISA_REGISTER_SUBCLASS_MIN = ISA_REGISTER_SUBCLASS_%s,\n",
00555 EKAPI_RegSubclassName(pknobs, 0));
00556 fprintf(h_file," ISA_REGISTER_SUBCLASS_MAX = ISA_REGISTER_SUBCLASS_%s,\n",
00557 EKAPI_RegSubclassName(pknobs, subclass_count-1));
00558 fprintf(h_file," ISA_REGISTER_SUBCLASS_COUNT = ISA_REGISTER_SUBCLASS_MAX - ISA_REGISTER_SUBCLASS_MIN + 1\n");
00559 fprintf(h_file,"} ISA_REGISTER_SUBCLASS;\n\n");
00560
00561 for (int i=0; reg_subclass_query[i] != NULL; i++)
00562 fprintf(h_file, "%s\n", reg_subclass_query[i]);
00563
00564
00566
00567 fprintf(export_file, "ISA_REGISTER_SUBCLASS_info\n");
00568 fprintf(c_file, "const ISA_REGISTER_SUBCLASS_INFO ISA_REGISTER_SUBCLASS_info[] = {\n");
00569 fprintf(c_file, " { \"UNDEFINED\", ISA_REGISTER_CLASS_UNDEFINED, 0, { 0 }, { 0 } },\n");
00570
00571 int * members = (int*)malloc(max_reg_count*sizeof(int));
00572 FmtAssert(members, ("Memory Allocation Failure!\n"));
00573 for (index=0; index<EKAPI_RegSubclassCount(pknobs); index++){
00574 int class_id;
00575 int num = EKAPI_RegSubclassMember(pknobs, index, &class_id, members);
00576 fprintf(c_file, " { \"%s\", ISA_REGISTER_CLASS_%s, %d,\n",
00577 EKAPI_RegSubclassName(pknobs,index),
00578 EKAPI_GetRegClassName(®_class_info[class_id]), num);
00579 int len = fprintf(c_file, " { ");
00580 for (int i=0; i<num; i++){
00581 if (len >= 70) { len = fprintf(c_file, "\n "); }
00582 len += fprintf(c_file, "%d", members[i]);
00583 len += fprintf(c_file, "%s", i!=(num-1) ? ", " : " },\n");
00584 }
00585 fprintf(c_file, " { 0 } },\n");
00586 }
00587 free(members);
00588 fprintf(c_file, "};\n\n");
00589
00590 fprintf(c_file, init_reg_func);
00591 fprintf(export_file, "ISA_REGISTER_Initialize\n");
00592
00593 Emit_Tailer(h_file);
00594 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00595
00596
00597
00598
00599
00600
00601 Init_Module_Files(mode, "targ_abi_properties", &c_file, &h_file,
00602 &export_file);
00603 Emit_Header(h_file, "targ_abi_properties", abi_descript);
00604 fprintf(h_file, "#include \"targ_isa_registers.h\"\n\n");
00605 fprintf(c_file, "#include \"targ_abi_properties.h\"\n\n");
00606
00607 fprintf(h_file, "typedef struct {\n mUINT32 reg_flags[%d][%d];\n",
00608 reg_class_count+1, max_reg_count+1);
00609 fprintf(h_file, " const char *reg_names[%d][%d];\n} ABI_PROPERTIES;\n\n",
00610 reg_class_count+1, max_reg_count+1);
00611
00612
00613 for (index=0; index<EKAPI_ABIPropCount(pknobs); index++){
00614 fprintf(h_file, "#define ABI_PROPERTY_%-20s 0x%08xU\n",
00615 EKAPI_ABIPropName(pknobs,index),
00616 (index==0)? 0 : (unsigned int)(1ULL << index-1));
00617 }
00618
00620
00621 fprintf(c_file, "\nstatic const ABI_PROPERTIES abi_properties[] = {\n");
00622 for (int abi_i=0; abi_i<EKAPI_ABICount(pknobs); abi_i++){
00623 fprintf(c_file, " {\n /* %s */\n {\n",
00624 EKAPI_ABIName(pknobs,abi_i));
00625
00626
00627 bv32_t *reg_flags = (bv32_t*)malloc((max_reg_count+1) * sizeof(bv32_t));
00628 FmtAssert(reg_flags, ("Memeory Allocation Failure!\n"));
00629
00630
00631 int reg_i;
00632 fprintf(c_file, " /* ISA_REGISTER_CLASS_UNDEFINED */");
00633 int len=fprintf(c_file,"\n {");
00634 for (reg_i=0; reg_i<=max_reg_count; reg_i++){
00635 if (len>=70) { len = fprintf(c_file, "\n "); }
00636 len += fprintf(c_file, " 0x00000000U,");
00637 }
00638 fprintf(c_file, " },\n");
00639
00640
00641 int reg_class_i;
00642 for (reg_class_i=0; reg_class_i<reg_class_count; reg_class_i++){
00643 int reg_num = EKAPI_RegPropMask(pknobs, reg_class_i, reg_flags);
00644
00645 fprintf(c_file, " /* ISA_REGISTER_CLASS_%s */",
00646 EKAPI_GetRegClassName(®_class_info[reg_class_i]));
00647
00648 len = fprintf(c_file,"\n {");
00649 for (reg_i=0; reg_i<=max_reg_count; reg_i++){
00650 if (len>=70) { len = fprintf(c_file, "\n "); }
00651 len += fprintf(c_file, " 0x");
00652 if (reg_i <= EKAPI_GetRegMaxNum(®_class_info[reg_class_i])){
00653 len += fprintf(c_file, "%08xU,", reg_flags[reg_i] );
00654 }
00655 else{
00656 len += fprintf(c_file, "00000000U,");
00657 }
00658 }
00659 fprintf(c_file, " },\n");
00660
00661 }
00662 fprintf(c_file, " },\n {\n");
00663
00664
00665 fprintf(c_file, " /* ISA_REGISTER_CLASS_UNDEFINED */");
00666 len=fprintf(c_file,"\n {");
00667 for (reg_i=0; reg_i<=max_reg_count; reg_i++){
00668 if (len>=80) { len = fprintf(c_file, "\n "); }
00669 len += fprintf(c_file, " \"\",");
00670 }
00671 fprintf(c_file, " },\n");
00672
00673 for (reg_class_i=0; reg_class_i<reg_class_count; reg_class_i++){
00674 fprintf(c_file, " /* ISA_REGISTER_CLASS_%s */",
00675 EKAPI_GetRegClassName(®_class_info[reg_class_i]));
00676
00677 len=fprintf(c_file,"\n {");
00678 for (reg_i=0; reg_i<=max_reg_count; reg_i++){
00679 char * name = "";
00680 if (reg_i <= EKAPI_GetRegMaxNum(®_class_info[reg_class_i])){
00681 name= EKAPI_GetRegName(pknobs, ®_class_info[reg_class_i], reg_i);
00682 }
00683 if ((len+strlen(name))>76) { len = fprintf(c_file, "\n "); }
00684 len += fprintf(c_file, " \"%s\",", name);
00685 }
00686
00687 fprintf(c_file, " },\n");
00688 }
00689 fprintf(c_file, " },\n },\n");
00690 }
00691 free(reg_class_info);
00692 fprintf(c_file, "};\n\n");
00693
00695
00696 fprintf(h_file, "\ntypedef enum {\n");
00697 for (index=0; index<EKAPI_ABICount(pknobs); index++){
00698 fprintf(h_file, " ABI_PROPERTIES_ABI_%s,\n",
00699 EKAPI_ABIName(pknobs,index));
00700 }
00701 fprintf(h_file, " ABI_PROPERTIES_ABI_UNDEFINED,\n");
00702 fprintf(h_file, " ABI_PROPERTIES_ABI_MAX=%d\n} ABI_PROPERTIES_ABI;\n\n",
00703 index-1);
00704
00706
00707 fprintf(c_file, "static const char * const abi_names[] = {\n");
00708 for (index=0; index<EKAPI_ABICount(pknobs); index++){
00709 fprintf(c_file, " \"%s\",\n", EKAPI_ABIName(pknobs,index));
00710 }
00711 fprintf(c_file, " \"UNDEFINED\"\n};\n\n");
00712
00714
00715
00716 fprintf(h_file, "%s", abi_common);
00717 fprintf(export_file, "ABI_PROPERTIES_ABI_Value\n");
00718 fprintf(export_file, "ABI_PROPERTIES_Initialize\n");
00719
00720 fprintf(c_file, "%s", abi_com_func);
00721 fprintf(export_file, "ABI_PROPERTIES_target_props\n");
00722 fprintf(export_file, "ABI_PROPERTIES_Initialize\n");
00723
00724
00726
00727 for (index=0; index<EKAPI_ABIPropCount(pknobs); index++){
00728 if (index==0){ fprintf(h_file, "/*ARGSUSED*/\n"); }
00729 fprintf(h_file, "inline BOOL ABI_PROPERTY_Is_%s(\n",
00730 EKAPI_ABIPropName(pknobs,index));
00731 fprintf(h_file, " ISA_REGISTER_CLASS rc,\n INT reg)\n{\n");
00732 if (index==0){ fprintf(h_file, " return FALSE;\n"); }
00733 else{
00734 fprintf(h_file, " extern const ABI_PROPERTIES *ABI_PROPERTIES_target_props;\n");
00735 fprintf(h_file, " return ( ABI_PROPERTIES_target_props->reg_flags[rc][reg]\n");
00736 fprintf(h_file, " & ABI_PROPERTY_%s) != 0;\n",
00737 EKAPI_ABIPropName(pknobs,index));
00738 }
00739 fprintf(h_file, "}\n\n");
00740 }
00741
00742
00743
00744
00745 Emit_Tailer(h_file);
00746 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00747
00748
00749 }