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
00042
00043
00044
00045
00046
00048
00049
00050
00051
00052
00053
00054
00055 #include <stddef.h>
00056 #include <stdlib.h>
00057 #include <stdio.h>
00058 #include <assert.h>
00059 #include <list>
00060 #include "gen_util.h"
00061 #include "targ_isa_subset.h"
00062 #include "isa_registers_gen.h"
00063
00064 typedef struct isa_register_set {
00065 int isa_mask;
00066 int min_regnum;
00067 int max_regnum;
00068 const char *def_name_format;
00069 const char **names;
00070 } *ISA_REGISTER_SET;
00071
00072 typedef struct isa_register_subclass {
00073 const char *name;
00074 ISA_REGISTER_CLASS rclass;
00075 int count;
00076 const int *members;
00077 const char **names;
00078 } *ISA_REGISTER_SUBCLASS;
00079
00080 struct isa_register_class {
00081 const char *name;
00082 int bit_size;
00083 bool can_store;
00084 bool multiple_save;
00085 int min_reg;
00086 int max_reg;
00087 std::list<ISA_REGISTER_SET> regsets;
00088 std::list<ISA_REGISTER_SUBCLASS> subclasses;
00089 };
00090
00091 static std::list<ISA_REGISTER_CLASS> rclasses;
00092 static std::list<ISA_REGISTER_SUBCLASS> subclasses;
00093
00094 static const char * const interface[] = {
00095 "/* ====================================================================",
00096 " * ====================================================================",
00097 " *",
00098 " * Description:",
00099 " *",
00100 " * A description of the ISA registers. The description exports",
00101 " * the following:",
00102 " *",
00103 " * typedef (enum) ISA_REGISTER_CLASS",
00104 " * An enumeration of the register classes.",
00105 " *",
00106 " * typedef mISA_REGISTER_CLASS",
00107 " * The most compact (integral) representation that can hold",
00108 " * all values of ISA_REGISTER_CLASS",
00109 " *",
00110 " * typedef (struct) ISA_REGISTER_CLASS_INFO",
00111 " * Describes a particular register class. The contents are private.",
00112 " *",
00113 " * const INT ISA_REGISTER_CLASS_UNDEFINED",
00114 " * A special register class that is out-of-range of valid",
00115 " * register clases.",
00116 " *",
00117 " * const INT ISA_REGISTER_CLASS_MIN",
00118 " * The first register class. The range of register classes",
00119 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00120 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00121 " * ",
00122 " * const INT ISA_REGISTER_CLASS_MAX",
00123 " * The last register class. The range of register classes",
00124 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00125 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00126 " * ",
00127 " * const INT ISA_REGISTER_CLASS_COUNT",
00128 " * The number of register classes. The range of register classes",
00129 " * is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00130 " * (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00131 " * ",
00132 " * (macro) FOR_ALL_ISA_REGISTER_CLASS(cl)",
00133 " * Iterate over all the register class values using the",
00134 " * ISA_REGISTER_CLASS variable <cl>.",
00135 " *",
00136 " * (macro) FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl)",
00137 " * Iterate over all the register class values in reverse order using",
00138 " * the ISA_REGISTER_CLASS variable <cl>.",
00139 " *",
00140 " * const INT ISA_REGISTER_MAX",
00141 " * The maximum (highest) register number of all classes.",
00142 " * NOTE: the lowest number register is implicitly 0.",
00143 " *",
00144 " * typedef (enum) ISA_REGISTER_SUBCLASS",
00145 " * An enumeration of the register subclasses.",
00146 " *",
00147 " * typedef mISA_REGISTER_SUBCLASS",
00148 " * The most compact (integral) representation that can hold",
00149 " * all values of ISA_REGISTER_SUBCLASS",
00150 " *",
00151 " * typedef (struct) ISA_REGISTER_SUBCLASS_INFO",
00152 " * Describes a particular register subclass. The contents are private.",
00153 " *",
00154 " * const INT ISA_REGISTER_SUBCLASS_UNDEFINED",
00155 " * A special register subclass that is out-of-range of valid",
00156 " * register subclases.",
00157 " *",
00158 " * const INT ISA_REGISTER_SUBCLASS_MIN",
00159 " * The first register subclass. The range of register subclasses",
00160 " * is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00161 " * ",
00162 " * const INT ISA_REGISTER_SUBCLASS_MAX",
00163 " * The last register subclass. The range of register subclasses",
00164 " * is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00165 " * ",
00166 " * const INT ISA_REGISTER_SUBCLASS_COUNT",
00167 " * The number of register subclasses.",
00168 " * ",
00169 " * (macro) FOR_ALL_ISA_REGISTER_SUBCLASS(sc)",
00170 " * Iterate over all the register subclass values using the",
00171 " * the ISA_REGISTER_SUBCLASS variable <sc>.",
00172 " *",
00173 " * const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(",
00174 " * ISA_REGISTER_CLASS rc",
00175 " * )",
00176 " * Return a pointer to the register class info for class 'rc'.",
00177 " *",
00178 " * INT ISA_REGISTER_CLASS_INFO_First_Reg(",
00179 " * const ISA_REGISTER_CLASS_INFO *info",
00180 " * )",
00181 " * Get the first (lowest numbered) register for the class",
00182 " * described by 'info'.",
00183 " *",
00184 " * INT ISA_REGISTER_CLASS_INFO_Last_Reg(",
00185 " * const ISA_REGISTER_CLASS_INFO *info",
00186 " * )",
00187 " * Get the last (highest numbered) register for the class",
00188 " * described by 'info'.",
00189 " *",
00190 " * INT ISA_REGISTER_CLASS_INFO_Bit_Size(",
00191 " * const ISA_REGISTER_CLASS_INFO *info",
00192 " * )",
00193 " * Get the size, in bits, of the register in the class",
00194 " * described by 'info'.",
00195 " *",
00196 " * BOOL ISA_REGISTER_CLASS_INFO_Can_Store(",
00197 " * const ISA_REGISTER_CLASS_INFO *info",
00198 " * )",
00199 " * Return a flag that indicates if the registers in the class",
00200 " * described by 'info' can be stored to memory, i.e. there",
00201 " * is a store instruction for the registers in the class.",
00202 " *",
00203 " * BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(",
00204 " * const ISA_REGISTER_CLASS_INFO *info",
00205 " * )",
00206 " * Return a flag that indicates if the registers in the class",
00207 " * described by 'info' can be saved and restore to memory in",
00208 " * multiples, i.e. as a group.",
00209 " *",
00210 " * const char *ISA_REGISTER_CLASS_INFO_Name(",
00211 " * const ISA_REGISTER_CLASS_INFO *info",
00212 " * )",
00213 " * Return the name of the class described by 'info'.",
00214 " *",
00215 " * const char *ISA_REGISTER_CLASS_INFO_Reg_Name(",
00216 " * const ISA_REGISTER_CLASS_INFO *info,",
00217 " * INT reg_index",
00218 " * )",
00219 " * Return the name of the 'reg_index'th register in the",
00220 " * class described by 'info'. NOTE: reg_index==0 corresponds",
00221 " * to the first register of the class.",
00222 " *",
00223 " * const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(",
00224 " * ISA_REGISTER_SUBCLASS sc",
00225 " * )",
00226 " *",
00227 " * Return a pointer to the register subclass info for the",
00228 " * subclass 'sc'.",
00229 " *",
00230 " * const char *ISA_REGISTER_SUBCLASS_INFO_Name(",
00231 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00232 " * )",
00233 " *",
00234 " * Return the name of the subclass described by 'info'.",
00235 " *",
00236 " * ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(",
00237 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00238 " * )",
00239 " *",
00240 " * Return the base register class for the subclass described",
00241 " * by 'info'.",
00242 " *",
00243 " * INT ISA_REGISTER_SUBCLASS_INFO_Count(",
00244 " * const ISA_REGISTER_SUBCLASS_INFO *info",
00245 " * )",
00246 " *",
00247 " * Return the number of registers in the subclass described",
00248 " * by 'info'.",
00249 " *",
00250 " * UINT ISA_REGISTER_SUBCLASS_INFO_Member(",
00251 " * const ISA_REGISTER_SUBCLASS_INFO *info,",
00252 " * INT n",
00253 " * )",
00254 " *",
00255 " * Return the 'n'th member (register) of the subclass described",
00256 " * by 'info'. The order of the registers returned is arbitrary.",
00257 " *",
00258 " * const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(",
00259 " * const ISA_REGISTER_SUBCLASS_INFO *info,",
00260 " * INT index",
00261 " * )",
00262 " *",
00263 " * Return the 'n'th member's register name of the subclass",
00264 " * described by 'info'. If the member does not have a subclass",
00265 " * specific name, NULL is returned.",
00266 " *",
00267 " * void ISA_REGISTER_Initialize(void)",
00268 " * Initialize the register package for use with the ISA specified",
00269 " * by ISA_SUBSET_Value.",
00270 " *",
00271 " * ====================================================================",
00272 " * ====================================================================",
00273 " */",
00274 NULL
00275 };
00276
00277
00279 void ISA_Registers_Begin( const char* )
00281
00283 {
00284 }
00285
00286
00288 ISA_REGISTER_CLASS ISA_Register_Class_Create(
00289 const char *name,
00290 int bit_size,
00291 bool can_store,
00292 bool multiple_save
00293 )
00295
00297 {
00298 ISA_REGISTER_CLASS result = new isa_register_class;
00299 rclasses.push_back(result);
00300 result->name = name;
00301 result->bit_size = bit_size;
00302 result->can_store = can_store;
00303 result->multiple_save = multiple_save;
00304 return result;
00305 }
00306
00307
00309 void ISA_Register_Set(
00310 ISA_REGISTER_CLASS rclass,
00311 int min_regnum,
00312 int max_regnum,
00313 const char *def_name_format,
00314 const char **names,
00315 int isa_mask
00316 )
00318
00320 {
00321 ISA_REGISTER_SET regset = new isa_register_set;
00322
00323 regset->min_regnum = min_regnum;
00324 regset->max_regnum = max_regnum;
00325 regset->def_name_format = def_name_format;
00326 regset->names = names;
00327 regset->isa_mask = isa_mask;
00328 rclass->regsets.push_back(regset);
00329 }
00330
00331
00333 void ISA_Register_Subclass_Create(
00334 const char *name,
00335 ISA_REGISTER_CLASS rclass,
00336 int count,
00337 const int *members,
00338 const char **names
00339 )
00341
00343 {
00344 ISA_REGISTER_SUBCLASS result = new isa_register_subclass;
00345 subclasses.push_back(result);
00346 result->name = name;
00347 result->rclass = rclass;
00348 result->count = count;
00349 result->members = members;
00350 result->names = names;
00351 rclass->subclasses.push_back(result);
00352 }
00353
00354
00356 void ISA_Registers_End(void)
00358
00360 {
00361 std::list <ISA_REGISTER_CLASS>::iterator rc_iter;
00362 std::list <ISA_REGISTER_SUBCLASS>::iterator rsc_iter;
00363 int i;
00364
00365 int max_reg = 0;
00366 int first_reg = max_reg;
00367 bool many_regs = false;
00368 for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00369 ISA_REGISTER_CLASS rclass = *rc_iter;
00370 int class_max = 0;
00371 int class_min = 0;
00372 std::list<ISA_REGISTER_SET>::iterator reg_iter;
00373 for (reg_iter = rclass->regsets.begin();
00374 reg_iter != rclass->regsets.end();
00375 ++reg_iter
00376 ) {
00377 ISA_REGISTER_SET regset = *reg_iter;
00378 int this_max = regset->max_regnum;
00379 if (this_max > class_max) class_max = this_max;
00380
00381 int this_min = regset->min_regnum;
00382 if (this_min > class_min) class_min = this_min;
00383 }
00384 rclass->max_reg = class_max;
00385 rclass->min_reg = class_min;
00386 if (class_max > max_reg) max_reg = class_max;
00387 }
00388
00389
00390
00391 if (max_reg > 1000) many_regs = true;
00392
00393 #define FNAME "targ_isa_registers"
00394 char filename[1000];
00395 sprintf(filename,"%s.h",FNAME);
00396 FILE* hfile = fopen(filename,"w");
00397 sprintf(filename,"%s.c",FNAME);
00398 FILE* cfile = fopen(filename,"w");
00399 sprintf(filename,"%s.Exported",FNAME);
00400 FILE* efile = fopen(filename,"w");
00401
00402 if (many_regs) {
00403 fprintf(hfile,"#include <stddef.h>\n");
00404 fprintf(cfile,"#include <stdio.h>\n");
00405 }
00406 fprintf(cfile,"#include \"targ_isa_subset.h\"\n");
00407 fprintf(cfile,"#include \"%s.h\"\n",FNAME);
00408
00409 sprintf (filename, "%s", FNAME);
00410 Emit_Header (hfile, filename, interface);
00411 fprintf(hfile,"#include \"targ_isa_subset.h\"\n");
00412
00413 fprintf(hfile, "\n#define ISA_REGISTER_FIRST (%d)\n", first_reg);
00414 fprintf(hfile, "\n#define ISA_REGISTER_MAX (%d)\n", max_reg);
00415
00416
00417
00418
00419
00420 fprintf(hfile, "\ntypedef enum {\n");
00421 fprintf(hfile, " ISA_REGISTER_CLASS_UNDEFINED,\n");
00422 for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00423 ISA_REGISTER_CLASS rclass = *rc_iter;
00424 fprintf(hfile, " ISA_REGISTER_CLASS_%s,\n", rclass->name);
00425 }
00426 fprintf(hfile, " ISA_REGISTER_CLASS_MIN = ISA_REGISTER_CLASS_%s,\n",
00427 rclasses.front()->name);
00428 fprintf(hfile, " ISA_REGISTER_CLASS_MAX = ISA_REGISTER_CLASS_%s,\n",
00429 rclasses.back()->name);
00430 fprintf(hfile, " ISA_REGISTER_CLASS_COUNT = "
00431 "ISA_REGISTER_CLASS_MAX - ISA_REGISTER_CLASS_MIN + 1\n");
00432
00433 fprintf(hfile, "} ISA_REGISTER_CLASS;\n");
00434
00435 fprintf(hfile, "\ntypedef mUINT8 mISA_REGISTER_CLASS;\n");
00436
00437 fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_CLASS(cl) \\\n"
00438 "\tfor (cl = ISA_REGISTER_CLASS_MIN; \\\n"
00439 "\t cl <= ISA_REGISTER_CLASS_MAX; \\\n"
00440 "\t cl = (ISA_REGISTER_CLASS)(cl + 1))\n");
00441
00442 fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl) \\\n"
00443 "\tfor (cl = ISA_REGISTER_CLASS_MAX; \\\n"
00444 "\t cl >= ISA_REGISTER_CLASS_MIN; \\\n"
00445 "\t cl = (ISA_REGISTER_CLASS)(cl - 1))\n");
00446
00447 fprintf(hfile, "\ntypedef struct {\n"
00448 " mUINT8 isa_mask;\n"
00449 " mUINT8 bit_size;\n"
00450 " mUINT16 min_regnum;\n"
00451 " mUINT16 max_regnum;\n"
00452 " mBOOL can_store;\n"
00453 " mBOOL multiple_save;\n"
00454 " const char *name;\n");
00455
00456 if ( many_regs) {
00457 fprintf(hfile, " const char *reg_name_format;\n");
00458 } else {
00459 fprintf(hfile, " const char *reg_name[ISA_REGISTER_MAX+1];\n");
00460 }
00461 fprintf(hfile, "} ISA_REGISTER_CLASS_INFO;\n");
00462
00463 fprintf(efile, "ISA_REGISTER_CLASS_info\n");
00464
00465 if (many_regs) {
00466
00467
00468
00469
00470
00471 fprintf(cfile, "\nstatic char namebuf[16];\n");
00472 }
00473 fprintf(cfile, "\nconst ISA_REGISTER_CLASS_INFO"
00474 " ISA_REGISTER_CLASS_info[] = {\n");
00475 fprintf(cfile, " { 0x%02x, %2d, %3d, %3d, %1d, %1d, \"%s\",",
00476 0, 0, -1, 0, 0, 0, "UNDEFINED");
00477 if (many_regs) {
00478 fprintf(cfile, " \"\" },\n");
00479 } else {
00480 fprintf(cfile, " { 0 } },\n");
00481 }
00482 for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00483 ISA_REGISTER_CLASS rclass = *rc_iter;
00484 std::list<ISA_REGISTER_SET>::iterator reg_iter;
00485 for (reg_iter = rclass->regsets.begin();
00486 reg_iter != rclass->regsets.end();
00487 ++reg_iter
00488 ) {
00489 ISA_REGISTER_SET regset = *reg_iter;
00490 fprintf(cfile, " { 0x%02x, %2d, %3d, %3d, %1d, %1d, \"%s\",",
00491 regset->isa_mask,
00492 rclass->bit_size,
00493 regset->min_regnum,
00494 regset->max_regnum,
00495 rclass->can_store,
00496 rclass->multiple_save,
00497 rclass->name);
00498
00499 if (many_regs) {
00500 fprintf(cfile, " \"%s\" ", regset->def_name_format);
00501 } else {
00502 int len = fprintf(cfile, "\n { ");
00503 for (i = regset->min_regnum; i <= regset->max_regnum; ++i) {
00504 if (len > 70) len = fprintf(cfile, "\n ");
00505 len += fprintf(cfile, "\"");
00506 if (regset->names && regset->names[i - regset->min_regnum]) {
00507 len += fputs(regset->names[i - regset->min_regnum], cfile);
00508 } else {
00509 len += fprintf(cfile, regset->def_name_format, i);
00510 }
00511 len += fprintf(cfile, "\"%s", i != regset->max_regnum ? ", " : "");
00512 }
00513 fprintf(cfile, " }");
00514 }
00515 fprintf(cfile, " },\n");
00516 }
00517 }
00518 fprintf(cfile, "};\n");
00519
00520 fprintf(efile, "ISA_REGISTER_CLASS_info_index\n");
00521
00522 fprintf(cfile, "\nmUINT8 ISA_REGISTER_CLASS_info_index[] = {\n");
00523 fprintf(cfile, " %d, /* ISA_REGISTER_CLASS_%s */\n", 0, "UNDEFINED");
00524 int index = 1;
00525 for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00526 ISA_REGISTER_CLASS rclass = *rc_iter;
00527 std::list<ISA_REGISTER_SET>::iterator reg_iter;
00528 fprintf(cfile, " %d, /* ISA_REGISTER_CLASS_%s */\n", index, rclass->name);
00529 for (reg_iter = rclass->regsets.begin();
00530 reg_iter != rclass->regsets.end();
00531 ++reg_iter
00532 ) ++index;
00533 };
00534 fprintf(cfile, "};\n");
00535
00536
00537
00538
00539
00540 fprintf(hfile, "\ntypedef enum {\n");
00541 fprintf(hfile, " ISA_REGISTER_SUBCLASS_UNDEFINED,\n");
00542 for (rsc_iter = subclasses.begin(); rsc_iter != subclasses.end(); ++rsc_iter) {
00543 ISA_REGISTER_SUBCLASS subclass = *rsc_iter;
00544 fprintf(hfile, " ISA_REGISTER_SUBCLASS_%s,\n", subclass->name);
00545 }
00546 if (subclasses.empty()) {
00547 fprintf(hfile, " ISA_REGISTER_SUBCLASS_MIN = 1,\n");
00548 fprintf(hfile, " ISA_REGISTER_SUBCLASS_MAX = 0,\n");
00549 } else {
00550 fprintf(hfile, " ISA_REGISTER_SUBCLASS_MIN = ISA_REGISTER_SUBCLASS_%s,\n",
00551 subclasses.front()->name);
00552 fprintf(hfile, " ISA_REGISTER_SUBCLASS_MAX = ISA_REGISTER_SUBCLASS_%s,\n",
00553 subclasses.back()->name);
00554 }
00555 fprintf(hfile, " ISA_REGISTER_SUBCLASS_COUNT = "
00556 "ISA_REGISTER_SUBCLASS_MAX - ISA_REGISTER_SUBCLASS_MIN + 1\n");
00557
00558 fprintf(hfile, "} ISA_REGISTER_SUBCLASS;\n");
00559
00560 fprintf(hfile, "\ntypedef mUINT8 mISA_REGISTER_SUBCLASS;\n");
00561
00562 fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_SUBCLASS(sc) \\\n"
00563 "\tfor (sc = ISA_REGISTER_SUBCLASS_MIN; \\\n"
00564 "\t sc <= ISA_REGISTER_SUBCLASS_MAX; \\\n"
00565 "\t sc = (ISA_REGISTER_SUBCLASS)(sc + 1))\n");
00566
00567 fprintf(hfile, "\ntypedef struct {\n"
00568 " const char *name;\n"
00569 " mISA_REGISTER_CLASS rclass;\n"
00570 " mUINT16 count;\n");
00571 if (many_regs && subclasses.empty()) {
00572
00573 } else {
00574 fprintf(hfile, " mUINT16 members[ISA_REGISTER_MAX+1];\n"
00575 " const char *reg_name[ISA_REGISTER_MAX+1];\n");
00576 }
00577 fprintf(hfile, "} ISA_REGISTER_SUBCLASS_INFO;\n");
00578
00579 fprintf(efile, "ISA_REGISTER_SUBCLASS_info\n");
00580
00581 fprintf(cfile, "\nconst ISA_REGISTER_SUBCLASS_INFO"
00582 " ISA_REGISTER_SUBCLASS_info[] = {\n");
00583 fprintf(cfile, " { \"%s\", ISA_REGISTER_CLASS_%s, 0",
00584 "UNDEFINED", "UNDEFINED");
00585 if ( !many_regs || !subclasses.empty()) {
00586 fprintf(cfile, ", { 0 }, { 0 } ");
00587 }
00588 fprintf(cfile, " },\n");
00589 for (rsc_iter = subclasses.begin(); rsc_iter != subclasses.end(); ++rsc_iter) {
00590 ISA_REGISTER_SUBCLASS subclass = *rsc_iter;
00591 fprintf(cfile, " { \"%s\", ISA_REGISTER_CLASS_%s, %d,",
00592 subclass->name, subclass->rclass->name, subclass->count);
00593 int len = fprintf(cfile, "\n { ");
00594 for (i = 0; i < subclass->count; ++i) {
00595 if (len > 70) len = fprintf(cfile, "\n ");
00596 len += fprintf(cfile, "%d%s",
00597 subclass->members[i],
00598 i != (subclass->count - 1) ? ", " : "");
00599 }
00600 fprintf(cfile, " },\n");
00601
00602 len = fprintf(cfile, " { ");
00603 if (subclass->names) {
00604 for (i = 0; i < subclass->count; ++i) {
00605 if (len > 70) len = fprintf(cfile, "\n ");
00606 if (subclass->names[i]) {
00607 len += fprintf(cfile, "\"%s\"", subclass->names[i]);
00608 } else {
00609 len += fputs("0", cfile);
00610 }
00611 len += fprintf(cfile, "%s", i != (subclass->count - 1) ? ", " : "");
00612 }
00613 } else {
00614 fputs("0", cfile);
00615 }
00616 fprintf(cfile, " } },\n");
00617 }
00618 fprintf(cfile, "};\n");
00619
00620
00621
00622
00623
00624 fprintf(hfile, "\ninline const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(\n"
00625 " ISA_REGISTER_CLASS rc\n"
00626 ")\n"
00627 "{\n"
00628 " extern const ISA_REGISTER_CLASS_INFO ISA_REGISTER_CLASS_info[];\n"
00629 " extern mUINT8 ISA_REGISTER_CLASS_info_index[];\n"
00630 " INT index = ISA_REGISTER_CLASS_info_index[(INT)rc];\n"
00631 " return &ISA_REGISTER_CLASS_info[index];\n"
00632 "}\n");
00633
00634 fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_First_Reg(\n"
00635 " const ISA_REGISTER_CLASS_INFO *info\n"
00636 ")\n"
00637 "{\n"
00638 " return info->min_regnum;\n"
00639 "}\n");
00640
00641 fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_Last_Reg(\n"
00642 " const ISA_REGISTER_CLASS_INFO *info\n"
00643 ")\n"
00644 "{\n"
00645 " return info->max_regnum;\n"
00646 "}\n");
00647
00648 fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_Bit_Size(\n"
00649 " const ISA_REGISTER_CLASS_INFO *info\n"
00650 ")\n"
00651 "{\n"
00652 " return info->bit_size;\n"
00653 "}\n");
00654
00655 fprintf(hfile, "\ninline BOOL ISA_REGISTER_CLASS_INFO_Can_Store(\n"
00656 " const ISA_REGISTER_CLASS_INFO *info\n"
00657 ")\n"
00658 "{\n"
00659 " return info->can_store;\n"
00660 "}\n");
00661
00662 fprintf(hfile, "\ninline BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(\n"
00663 " const ISA_REGISTER_CLASS_INFO *info\n"
00664 ")\n"
00665 "{\n"
00666 " return info->multiple_save;\n"
00667 "}\n");
00668
00669 fprintf(hfile, "\ninline const char *ISA_REGISTER_CLASS_INFO_Name(\n"
00670 " const ISA_REGISTER_CLASS_INFO *info\n"
00671 ")\n"
00672 "{\n"
00673 " return info->name;\n"
00674 "}\n");
00675
00676 if (many_regs) {
00677 fprintf(hfile, "\n/* Note that Reg_Name returns a temporary name buffer\n"
00678 " * that gets reused, so must emit or copy the name\n"
00679 " * before calling Reg_Name again */\n");
00680 fprintf(hfile, "extern const char *ISA_REGISTER_CLASS_INFO_Reg_Name(\n"
00681 " const ISA_REGISTER_CLASS_INFO *info,\n"
00682 " INT reg_index\n"
00683 ");\n");
00684 fprintf(cfile, "\nconst char *ISA_REGISTER_CLASS_INFO_Reg_Name(\n"
00685 " const ISA_REGISTER_CLASS_INFO *info,\n"
00686 " INT reg_index\n"
00687 ")\n"
00688 "{\n"
00689 " sprintf(namebuf, info->reg_name_format, reg_index);\n"
00690 " return namebuf;\n"
00691 "}\n");
00692 } else {
00693 fprintf(hfile, "\ninline const char *ISA_REGISTER_CLASS_INFO_Reg_Name(\n"
00694 " const ISA_REGISTER_CLASS_INFO *info,\n"
00695 " INT reg_index\n"
00696 ")\n"
00697 "{\n"
00698 " return info->reg_name[reg_index];\n"
00699 "}\n");
00700 }
00701
00702 fprintf(hfile, "\ninline const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(\n"
00703 " ISA_REGISTER_SUBCLASS sc\n"
00704 ")\n"
00705 "{\n"
00706 " extern const ISA_REGISTER_SUBCLASS_INFO ISA_REGISTER_SUBCLASS_info[];\n"
00707 " return &ISA_REGISTER_SUBCLASS_info[sc];\n"
00708 "}\n");
00709
00710 fprintf(hfile, "\ninline const char *ISA_REGISTER_SUBCLASS_INFO_Name(\n"
00711 " const ISA_REGISTER_SUBCLASS_INFO *info\n"
00712 ")\n"
00713 "{\n"
00714 " return info->name;\n"
00715 "}\n");
00716
00717 fprintf(hfile, "\ninline ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(\n"
00718 " const ISA_REGISTER_SUBCLASS_INFO *info\n"
00719 ")\n"
00720 "{\n"
00721 " return (ISA_REGISTER_CLASS)info->rclass;\n"
00722 "}\n");
00723
00724 fprintf(hfile, "\ninline INT ISA_REGISTER_SUBCLASS_INFO_Count(\n"
00725 " const ISA_REGISTER_SUBCLASS_INFO *info\n"
00726 ")\n"
00727 "{\n"
00728 " return info->count;\n"
00729 "}\n");
00730
00731 fprintf(hfile, "\ninline UINT ISA_REGISTER_SUBCLASS_INFO_Member(\n"
00732 " const ISA_REGISTER_SUBCLASS_INFO *info,\n"
00733 " INT n\n"
00734 ")\n"
00735 "{\n");
00736 if (many_regs && subclasses.empty()) {
00737 fprintf(hfile, " return 0;\n");
00738 } else {
00739 fprintf(hfile, " return info->members[n];\n");
00740 }
00741 fprintf(hfile, "}\n");
00742
00743 fprintf(hfile, "\ninline const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(\n"
00744 " const ISA_REGISTER_SUBCLASS_INFO *info,\n"
00745 " INT n\n"
00746 ")\n"
00747 "{\n");
00748 if (many_regs && subclasses.empty()) {
00749 fprintf(hfile, " return NULL;\n");
00750 } else {
00751 fprintf(hfile, " return info->reg_name[n];\n");
00752 }
00753 fprintf(hfile, "}\n");
00754
00755 fprintf(hfile, "\nextern void ISA_REGISTER_Initialize(void);\n");
00756
00757 fprintf(efile, "ISA_REGISTER_Initialize\n");
00758
00759 fprintf(cfile, "\nvoid ISA_REGISTER_Initialize(void)\n"
00760 "{\n"
00761 " INT rc;\n"
00762 " INT mask = 1 << (INT)ISA_SUBSET_Value;\n"
00763 " for (rc = ISA_REGISTER_CLASS_MIN; "
00764 "rc <= ISA_REGISTER_CLASS_MAX; ++rc) {\n"
00765 " INT i = ISA_REGISTER_CLASS_info_index[rc];\n"
00766 " const ISA_REGISTER_CLASS_INFO *info = "
00767 "&ISA_REGISTER_CLASS_info[i];\n"
00768 " while ((info->isa_mask & mask) == 0) ++info, ++i;\n"
00769 " ISA_REGISTER_CLASS_info_index[rc] = i;\n"
00770 " }\n"
00771 "}\n");
00772
00773 Emit_Footer(hfile);
00774 }