Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
isa_registers_gen.cxx
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2 of the GNU General Public License as
00007   published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if 
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU General Public License along
00021   with this program; if not, write the Free Software Foundation, Inc., 59
00022   Temple Place - Suite 330, Boston MA 02111-1307, USA.
00023 
00024   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00025   Mountain View, CA 94043, or:
00026 
00027   http://www.sgi.com
00028 
00029   For further information regarding this notice, see:
00030 
00031   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00032 
00033 */
00034 
00035 
00036 //  isa_registers_gen.cxx
00038 //
00039 //  Description:
00040 //
00041 //      Generate a description of the ISA registers.
00042 //
00044 //
00045 
00046 
00047 #include <stddef.h>
00048 #include <stdlib.h>
00049 #include <stdio.h>
00050 #include <assert.h>
00051 
00052 #include <list>
00053 
00054 using namespace std;
00055 
00056 #include "gen_util.h"
00057 #include "targ_isa_subset.h"
00058 #include "isa_registers_gen.h"
00059 
00060 typedef struct isa_register_set {
00061   int isa_mask;
00062   int min_regnum;
00063   int max_regnum;
00064   const char *def_name_format;
00065   const char **names;
00066 } *ISA_REGISTER_SET;
00067 
00068 typedef struct isa_register_subclass {
00069   const char *name;
00070   ISA_REGISTER_CLASS rclass;
00071   int count;
00072   const int *members;
00073   const char **names;
00074 } *ISA_REGISTER_SUBCLASS;
00075 
00076 struct isa_register_class {
00077   const char *name;
00078   int bit_size;
00079   bool can_store;
00080   bool multiple_save;
00081   int min_reg;
00082   int max_reg;
00083   list<ISA_REGISTER_SET> regsets;
00084   list<ISA_REGISTER_SUBCLASS> subclasses;
00085 };
00086 
00087 static list<ISA_REGISTER_CLASS> rclasses; // All the classes
00088 static list<ISA_REGISTER_SUBCLASS> subclasses; // All the sub classes
00089 
00090 static const char * const interface[] = {
00091   "/* ====================================================================",
00092   " * ====================================================================",
00093   " *",
00094   " * Description:",
00095   " *",
00096   " *   A description of the ISA registers. The description exports",
00097   " *   the following:",
00098   " *",
00099   " *   typedef (enum) ISA_REGISTER_CLASS",
00100   " *       An enumeration of the register classes.",
00101   " *",
00102   " *   typedef mISA_REGISTER_CLASS",
00103   " *       The most compact (integral) representation that can hold",
00104   " *       all values of ISA_REGISTER_CLASS",
00105   " *",
00106   " *   typedef (struct) ISA_REGISTER_CLASS_INFO",
00107   " *       Describes a particular register class. The contents are private.",
00108   " *",
00109   " *   const INT ISA_REGISTER_CLASS_UNDEFINED",
00110   " *       A special register class that is out-of-range of valid",
00111   " *       register clases.",
00112   " *",
00113   " *   const INT ISA_REGISTER_CLASS_MIN",
00114   " *       The first register class. The range of register classes",
00115   " *       is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00116   " *       (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00117   " * ",
00118   " *   const INT ISA_REGISTER_CLASS_MAX",
00119   " *       The last register class. The range of register classes",
00120   " *       is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00121   " *       (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00122   " * ",
00123   " *   const INT ISA_REGISTER_CLASS_COUNT",
00124   " *       The number of register classes. The range of register classes",
00125   " *       is ISA_REGISTER_CLASS_MIN..ISA_REGISTER_CLASS_MAX",
00126   " *       (this range excludes ISA_REGISTER_CLASS_UNDEFINED)."
00127   " * ",
00128   " *   (macro) FOR_ALL_ISA_REGISTER_CLASS(cl)",
00129   " *       Iterate over all the register class values using the",
00130   " *       ISA_REGISTER_CLASS variable <cl>.",
00131   " *",
00132   " *   (macro) FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl)",
00133   " *       Iterate over all the register class values in reverse order using",
00134   " *       the ISA_REGISTER_CLASS variable <cl>.",
00135   " *",
00136   " *   const INT ISA_REGISTER_MAX",
00137   " *       The maximum (highest) register number of all classes.",
00138   " *       NOTE: the lowest number register is implicitly 0.",
00139   " *",
00140   " *   typedef (enum) ISA_REGISTER_SUBCLASS",
00141   " *       An enumeration of the register subclasses.",
00142   " *",
00143   " *   typedef mISA_REGISTER_SUBCLASS",
00144   " *       The most compact (integral) representation that can hold",
00145   " *       all values of ISA_REGISTER_SUBCLASS",
00146   " *",
00147   " *   typedef (struct) ISA_REGISTER_SUBCLASS_INFO",
00148   " *       Describes a particular register subclass. The contents are private.",
00149   " *",
00150   " *   const INT ISA_REGISTER_SUBCLASS_UNDEFINED",
00151   " *       A special register subclass that is out-of-range of valid",
00152   " *       register subclases.",
00153   " *",
00154   " *   const INT ISA_REGISTER_SUBCLASS_MIN",
00155   " *       The first register subclass. The range of register subclasses",
00156   " *       is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00157   " * ",
00158   " *   const INT ISA_REGISTER_SUBCLASS_MAX",
00159   " *       The last register subclass. The range of register subclasses",
00160   " *       is ISA_REGISTER_SUBCLASS_MIN..ISA_REGISTER_SUBCLASS_MAX",
00161   " * ",
00162   " *   const INT ISA_REGISTER_SUBCLASS_COUNT",
00163   " *       The number of register subclasses.",
00164   " * ",
00165   " *   (macro) FOR_ALL_ISA_REGISTER_SUBCLASS(sc)",
00166   " *       Iterate over all the register subclass values using the",
00167   " *       the ISA_REGISTER_SUBCLASS variable <sc>.",
00168   " *",
00169   " *   const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(",
00170   " *     ISA_REGISTER_CLASS rc",
00171   " *   )",
00172   " *       Return a pointer to the register class info for class 'rc'.",
00173   " *",
00174   " *   INT ISA_REGISTER_CLASS_INFO_First_Reg(",
00175   " *     const ISA_REGISTER_CLASS_INFO *info",
00176   " *   )",
00177   " *       Get the first (lowest numbered) register for the class",
00178   " *       described by 'info'.",
00179   " *",
00180   " *   INT ISA_REGISTER_CLASS_INFO_Last_Reg(",
00181   " *     const ISA_REGISTER_CLASS_INFO *info",
00182   " *   )",
00183   " *       Get the last (highest numbered) register for the class",
00184   " *       described by 'info'.",
00185   " *",
00186   " *   INT ISA_REGISTER_CLASS_INFO_Bit_Size(",
00187   " *     const ISA_REGISTER_CLASS_INFO *info",
00188   " *   )",
00189   " *       Get the size, in bits, of the register in the class",
00190   " *       described by 'info'.",
00191   " *",
00192   " *   BOOL ISA_REGISTER_CLASS_INFO_Can_Store(",
00193   " *     const ISA_REGISTER_CLASS_INFO *info",
00194   " *   )",
00195   " *       Return a flag that indicates if the registers in the class",
00196   " *       described by 'info' can be stored to memory, i.e. there",
00197   " *       is a store instruction for the registers in the class.",
00198   " *",
00199   " *   BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(",
00200   " *     const ISA_REGISTER_CLASS_INFO *info",
00201   " *   )",
00202   " *       Return a flag that indicates if the registers in the class",
00203   " *       described by 'info' can be saved and restore to memory in",
00204   " *       multiples, i.e. as a group.",
00205   " *",
00206   " *   const char *ISA_REGISTER_CLASS_INFO_Name(",
00207   " *     const ISA_REGISTER_CLASS_INFO *info",
00208   " *   )",
00209   " *       Return the name of the class described by 'info'.",
00210   " *",
00211   " *   const char *ISA_REGISTER_CLASS_INFO_Reg_Name(",
00212   " *     const ISA_REGISTER_CLASS_INFO *info,",
00213   " *     INT reg_index",
00214   " *   )",
00215   " *       Return the name of the 'reg_index'th register in the",
00216   " *       class described by 'info'. NOTE: reg_index==0 corresponds",
00217   " *       to the first register of the class.",
00218   " *",
00219   " *   const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(",
00220   " *     ISA_REGISTER_SUBCLASS sc",
00221   " *   )",
00222   " *",
00223   " *       Return a pointer to the register subclass info for the",
00224   " *       subclass 'sc'.",
00225   " *",
00226   " *   const char *ISA_REGISTER_SUBCLASS_INFO_Name(",
00227   " *     const ISA_REGISTER_SUBCLASS_INFO *info",
00228   " *   )",
00229   " *",
00230   " *       Return the name of the subclass described by 'info'.",
00231   " *",
00232   " *   ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(",
00233   " *     const ISA_REGISTER_SUBCLASS_INFO *info",
00234   " *   )",
00235   " *",
00236   " *       Return the base register class for the subclass described",
00237   " *       by 'info'.",
00238   " *",
00239   " *   INT ISA_REGISTER_SUBCLASS_INFO_Count(",
00240   " *     const ISA_REGISTER_SUBCLASS_INFO *info",
00241   " *   )",
00242   " *",
00243   " *       Return the number of registers in the subclass described",
00244   " *       by 'info'.",
00245   " *",
00246   " *   UINT ISA_REGISTER_SUBCLASS_INFO_Member(",
00247   " *     const ISA_REGISTER_SUBCLASS_INFO *info,",
00248   " *     INT n",
00249   " *   )",
00250   " *",
00251   " *       Return the 'n'th member (register) of the subclass described",
00252   " *       by 'info'. The order of the registers returned is arbitrary.",
00253   " *",
00254   " *   const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(",
00255   " *     const ISA_REGISTER_SUBCLASS_INFO *info,",
00256   " *     INT index",
00257   " *   )",
00258   " *",
00259   " *       Return the 'n'th member's register name of the subclass",
00260   " *       described by 'info'. If the member does not have a subclass",
00261   " *       specific name, NULL is returned.",
00262   " *",
00263   " *   void ISA_REGISTER_Initialize(void)",
00264   " *       Initialize the register package for use with the ISA specified",
00265   " *       by ISA_SUBSET_Value.",
00266   " *",
00267   " * ====================================================================",
00268   " * ====================================================================",
00269   " */",
00270   NULL
00271 };
00272 
00273 
00275 void ISA_Registers_Begin( const char* /* name */ )
00277 //  See interface description.
00279 {
00280 }
00281 
00282 
00284 ISA_REGISTER_CLASS ISA_Register_Class_Create(
00285   const char *name,
00286   int bit_size,
00287   bool can_store,
00288   bool multiple_save
00289 )
00291 //  See interface description.
00293 {
00294   ISA_REGISTER_CLASS result = new isa_register_class;
00295   rclasses.push_back(result);
00296   result->name = name;
00297   result->bit_size = bit_size;
00298   result->can_store = can_store;
00299   result->multiple_save = multiple_save;
00300   return result;
00301 }
00302 
00303 
00305 void ISA_Register_Set(
00306   ISA_REGISTER_CLASS rclass,
00307   int min_regnum,
00308   int max_regnum,
00309   const char *def_name_format,
00310   const char **names,
00311   int isa_mask
00312 )
00314 //  See interface description.
00316 {
00317   ISA_REGISTER_SET regset = new isa_register_set;
00318 
00319   regset->min_regnum = min_regnum;
00320   regset->max_regnum = max_regnum;
00321   regset->def_name_format = def_name_format;
00322   regset->names = names;
00323   regset->isa_mask = isa_mask;
00324   rclass->regsets.push_back(regset);
00325 }
00326 
00327 
00329 void ISA_Register_Subclass_Create(
00330   const char *name,
00331   ISA_REGISTER_CLASS rclass,
00332   int count,
00333   const int *members,
00334   const char **names
00335 )
00337 //  See interface description.
00339 {
00340   ISA_REGISTER_SUBCLASS result = new isa_register_subclass;
00341   subclasses.push_back(result);
00342   result->name = name;
00343   result->rclass = rclass;
00344   result->count = count;
00345   result->members = members;
00346   result->names = names;
00347   rclass->subclasses.push_back(result);
00348 }
00349 
00350 
00352 void ISA_Registers_End(void)
00354 //  See interface description.
00356 {
00357   list <ISA_REGISTER_CLASS>::iterator rc_iter;
00358   list <ISA_REGISTER_SUBCLASS>::iterator rsc_iter;
00359   int i;
00360 
00361   int max_reg = 0;
00362   for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00363     ISA_REGISTER_CLASS rclass = *rc_iter;
00364     int class_max = 0;
00365     int class_min = 0;
00366     list<ISA_REGISTER_SET>::iterator reg_iter;
00367     for (reg_iter = rclass->regsets.begin();
00368          reg_iter != rclass->regsets.end();
00369          ++reg_iter
00370     ) {
00371       ISA_REGISTER_SET regset = *reg_iter;
00372       int this_max = regset->max_regnum;
00373       if (this_max > class_max) class_max = this_max;
00374 
00375       int this_min = regset->min_regnum;
00376       if (this_min > class_min) class_min = this_min;
00377     }
00378     rclass->max_reg = class_max;
00379     rclass->min_reg = class_min;
00380     if (class_max > max_reg) max_reg = class_max;
00381   }
00382 
00383 #define FNAME "targ_isa_registers"
00384   char filename[1000];
00385   sprintf(filename,"%s.h",FNAME);
00386   FILE* hfile = fopen(filename,"w");
00387   sprintf(filename,"%s.c",FNAME);
00388   FILE* cfile = fopen(filename,"w");
00389   sprintf(filename,"%s.Exported",FNAME);
00390   FILE* efile = fopen(filename,"w");
00391 
00392   fprintf(cfile,"#include \"targ_isa_subset.h\"\n");
00393   fprintf(cfile,"#include \"%s.h\"\n",FNAME);
00394 
00395   sprintf (filename, "%s", FNAME);
00396   Emit_Header (hfile, filename, interface);
00397   fprintf(hfile,"#include \"targ_isa_subset.h\"\n");
00398 
00399   fprintf(hfile, "\n#define ISA_REGISTER_MAX (%d)\n", max_reg);
00400 
00401   /**************************************************
00402    * classes:
00403    */
00404 
00405   fprintf(hfile, "\ntypedef enum {\n");
00406   fprintf(hfile, "  ISA_REGISTER_CLASS_UNDEFINED,\n");
00407   for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00408     ISA_REGISTER_CLASS rclass = *rc_iter;
00409     fprintf(hfile, "  ISA_REGISTER_CLASS_%s,\n", rclass->name);
00410   }
00411   fprintf(hfile, "  ISA_REGISTER_CLASS_MIN = ISA_REGISTER_CLASS_%s,\n",
00412           rclasses.front()->name);
00413   fprintf(hfile, "  ISA_REGISTER_CLASS_MAX = ISA_REGISTER_CLASS_%s,\n",
00414           rclasses.back()->name);
00415   fprintf(hfile, "  ISA_REGISTER_CLASS_COUNT = "
00416                  "ISA_REGISTER_CLASS_MAX - ISA_REGISTER_CLASS_MIN + 1\n");
00417 
00418   fprintf(hfile, "} ISA_REGISTER_CLASS;\n");
00419 
00420   fprintf(hfile, "\ntypedef mUINT8 mISA_REGISTER_CLASS;\n");
00421 
00422   fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_CLASS(cl) \\\n"
00423                  "\tfor (cl = ISA_REGISTER_CLASS_MIN; \\\n"
00424                  "\t     cl <= ISA_REGISTER_CLASS_MAX; \\\n"
00425                  "\t     cl = (ISA_REGISTER_CLASS)(cl + 1))\n");
00426 
00427   fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_CLASS_IN_REVERSE(cl) \\\n"
00428                  "\tfor (cl = ISA_REGISTER_CLASS_MAX; \\\n"
00429                  "\t     cl >= ISA_REGISTER_CLASS_MIN; \\\n"
00430                  "\t     cl = (ISA_REGISTER_CLASS)(cl - 1))\n");
00431 
00432   fprintf(hfile, "\ntypedef struct {\n"
00433                  "  mUINT8 isa_mask;\n"
00434                  "  mUINT8 min_regnum;\n"
00435                  "  mUINT8 max_regnum;\n"
00436                  "  mUINT8 bit_size;\n"
00437                  "  mBOOL can_store;\n"
00438                  "  mBOOL multiple_save;\n"
00439                  "  const char *name;\n"
00440                  "  const char *reg_name[ISA_REGISTER_MAX+1];\n"
00441                  "} ISA_REGISTER_CLASS_INFO;\n");
00442 
00443   fprintf(efile, "ISA_REGISTER_CLASS_info\n");
00444 
00445   fprintf(cfile, "\nconst ISA_REGISTER_CLASS_INFO"
00446                    " ISA_REGISTER_CLASS_info[] = {\n");
00447   fprintf(cfile, "  { 0x%02x, %3d, %3d, %2d, %1d, %1d, \"%s\", { 0 } },\n",
00448                  0, 0, -1, 0, 0, 0, "UNDEFINED");
00449   for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00450     ISA_REGISTER_CLASS rclass = *rc_iter;
00451     list<ISA_REGISTER_SET>::iterator reg_iter;
00452     for (reg_iter = rclass->regsets.begin();
00453          reg_iter != rclass->regsets.end();
00454          ++reg_iter
00455     ) {
00456       ISA_REGISTER_SET regset = *reg_iter;
00457       fprintf(cfile, "  { 0x%02x, %3d, %3d, %2d, %1d, %1d, \"%s\",",
00458               regset->isa_mask,
00459               regset->min_regnum,
00460               regset->max_regnum,
00461               rclass->bit_size,
00462               rclass->can_store,
00463               rclass->multiple_save,
00464               rclass->name);
00465 
00466       int len = fprintf(cfile, "\n    { ");
00467       for (i = regset->min_regnum; i <= regset->max_regnum; ++i) {
00468         if (len > 70) len = fprintf(cfile, "\n      ");
00469         len += fprintf(cfile, "\"");
00470         if (regset->names && regset->names[i - regset->min_regnum]) {
00471           len += fputs(regset->names[i - regset->min_regnum], cfile);
00472         } else {
00473           len += fprintf(cfile, regset->def_name_format, i);
00474         }
00475         len += fprintf(cfile, "\"%s", i != regset->max_regnum ? ", " : "");
00476       }
00477       fprintf(cfile, " } },\n");
00478     }
00479   }
00480   fprintf(cfile, "};\n");
00481 
00482   fprintf(efile, "ISA_REGISTER_CLASS_info_index\n");
00483 
00484   fprintf(cfile, "\nmUINT8 ISA_REGISTER_CLASS_info_index[] = {\n");
00485   fprintf(cfile, "  %d,  /* ISA_REGISTER_CLASS_%s */\n", 0, "UNDEFINED");
00486   int index = 1;
00487   for (rc_iter = rclasses.begin(); rc_iter != rclasses.end(); ++rc_iter) {
00488     ISA_REGISTER_CLASS rclass = *rc_iter;
00489     list<ISA_REGISTER_SET>::iterator reg_iter;
00490     fprintf(cfile, "  %d,  /* ISA_REGISTER_CLASS_%s */\n", index, rclass->name);
00491     for (reg_iter = rclass->regsets.begin();
00492          reg_iter != rclass->regsets.end();
00493          ++reg_iter
00494     ) ++index;
00495   };
00496   fprintf(cfile, "};\n");
00497 
00498   /**************************************************
00499    * subclasses:
00500    */
00501 
00502   fprintf(hfile, "\ntypedef enum {\n");
00503   fprintf(hfile, "  ISA_REGISTER_SUBCLASS_UNDEFINED,\n");
00504   for (rsc_iter = subclasses.begin(); rsc_iter != subclasses.end(); ++rsc_iter) {
00505     ISA_REGISTER_SUBCLASS subclass = *rsc_iter;
00506       fprintf(hfile, "  ISA_REGISTER_SUBCLASS_%s,\n", subclass->name);
00507     }
00508   if (subclasses.empty()) {
00509     fprintf(hfile, "  ISA_REGISTER_SUBCLASS_MIN = 1,\n");
00510     fprintf(hfile, "  ISA_REGISTER_SUBCLASS_MAX = 0,\n");
00511   } else {
00512     fprintf(hfile, "  ISA_REGISTER_SUBCLASS_MIN = ISA_REGISTER_SUBCLASS_%s,\n",
00513             subclasses.front()->name);
00514     fprintf(hfile, "  ISA_REGISTER_SUBCLASS_MAX = ISA_REGISTER_SUBCLASS_%s,\n",
00515             subclasses.back()->name);
00516   }
00517   fprintf(hfile, "  ISA_REGISTER_SUBCLASS_COUNT = "
00518                  "ISA_REGISTER_SUBCLASS_MAX - ISA_REGISTER_SUBCLASS_MIN + 1\n");
00519 
00520   fprintf(hfile, "} ISA_REGISTER_SUBCLASS;\n");
00521 
00522   fprintf(hfile, "\ntypedef mUINT8 mISA_REGISTER_SUBCLASS;\n");
00523 
00524   fprintf(hfile, "\n#define FOR_ALL_ISA_REGISTER_SUBCLASS(sc) \\\n"
00525                  "\tfor (sc = ISA_REGISTER_SUBCLASS_MIN; \\\n"
00526                  "\t     sc <= ISA_REGISTER_SUBCLASS_MAX; \\\n"
00527                  "\t     sc = (ISA_REGISTER_SUBCLASS)(sc + 1))\n");
00528 
00529   fprintf(hfile, "\ntypedef struct {\n"
00530                  "  const char *name;\n"
00531                  "  mISA_REGISTER_CLASS rclass;\n"
00532                  "  mUINT8 count;\n"
00533                  "  mUINT8 members[ISA_REGISTER_MAX+1];\n"
00534                  "  const char *reg_name[ISA_REGISTER_MAX+1];\n"
00535                  "} ISA_REGISTER_SUBCLASS_INFO;\n");
00536 
00537   fprintf(efile, "ISA_REGISTER_SUBCLASS_info\n");
00538 
00539   fprintf(cfile, "\nconst ISA_REGISTER_SUBCLASS_INFO"
00540                    " ISA_REGISTER_SUBCLASS_info[] = {\n");
00541   fprintf(cfile, "  { \"%s\", ISA_REGISTER_CLASS_%s, 0, { 0 }, { 0 } },\n", 
00542                  "UNDEFINED", "UNDEFINED");
00543   for (rsc_iter = subclasses.begin(); rsc_iter != subclasses.end(); ++rsc_iter) {
00544     ISA_REGISTER_SUBCLASS subclass = *rsc_iter;
00545     fprintf(cfile, "  { \"%s\", ISA_REGISTER_CLASS_%s, %d,", 
00546                    subclass->name, subclass->rclass->name, subclass->count);
00547     int len = fprintf(cfile, "\n    { ");
00548     for (i = 0; i < subclass->count; ++i) {
00549       if (len > 70) len = fprintf(cfile, "\n      ");
00550       len += fprintf(cfile, "%d%s",
00551                             subclass->members[i],
00552                             i != (subclass->count - 1) ? ", " : "");
00553     }
00554     fprintf(cfile, " },\n");
00555 
00556     len = fprintf(cfile, "    { ");
00557     if (subclass->names) {
00558       for (i = 0; i < subclass->count; ++i) {
00559         if (len > 70) len = fprintf(cfile, "\n      ");
00560         if (subclass->names[i]) {
00561           len += fprintf(cfile, "\"%s\"", subclass->names[i]);
00562         } else {
00563           len += fputs("0", cfile);
00564         }
00565         len += fprintf(cfile, "%s", i != (subclass->count - 1) ? ", " : "");
00566       }
00567     } else {
00568       fputs("0", cfile);
00569     }
00570     fprintf(cfile, " } },\n");
00571   }
00572   fprintf(cfile, "};\n");
00573 
00574   /**************************************************
00575    * accessors:
00576    */
00577 
00578   fprintf(hfile, "\ninline const ISA_REGISTER_CLASS_INFO *ISA_REGISTER_CLASS_Info(\n"
00579                  "  ISA_REGISTER_CLASS rc\n"
00580                  ")\n"
00581                  "{\n"
00582                  "  extern const ISA_REGISTER_CLASS_INFO ISA_REGISTER_CLASS_info[];\n"
00583                  "  extern mUINT8 ISA_REGISTER_CLASS_info_index[];\n"
00584                  "  INT index = ISA_REGISTER_CLASS_info_index[(INT)rc];\n"
00585                  "  return &ISA_REGISTER_CLASS_info[index];\n"
00586                  "}\n");
00587 
00588   fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_First_Reg(\n"
00589                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00590                  ")\n"
00591                  "{\n"
00592                  "  return info->min_regnum;\n"
00593                  "}\n");
00594 
00595   fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_Last_Reg(\n"
00596                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00597                  ")\n"
00598                  "{\n"
00599                  "  return info->max_regnum;\n"
00600                  "}\n");
00601 
00602   fprintf(hfile, "\ninline INT ISA_REGISTER_CLASS_INFO_Bit_Size(\n"
00603                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00604                  ")\n"
00605                  "{\n"
00606                  "  return info->bit_size;\n"
00607                  "}\n");
00608 
00609   fprintf(hfile, "\ninline BOOL ISA_REGISTER_CLASS_INFO_Can_Store(\n"
00610                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00611                  ")\n"
00612                  "{\n"
00613                  "  return info->can_store;\n"
00614                  "}\n");
00615 
00616   fprintf(hfile, "\ninline BOOL ISA_REGISTER_CLASS_INFO_Multiple_Save(\n"
00617                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00618                  ")\n"
00619                  "{\n"
00620                  "  return info->multiple_save;\n"
00621                  "}\n");
00622 
00623   fprintf(hfile, "\ninline const char *ISA_REGISTER_CLASS_INFO_Name(\n"
00624                  "  const ISA_REGISTER_CLASS_INFO *info\n"
00625                  ")\n"
00626                  "{\n"
00627                  "  return info->name;\n"
00628                  "}\n");
00629 
00630   fprintf(hfile, "\ninline const char *ISA_REGISTER_CLASS_INFO_Reg_Name(\n"
00631                  "  const ISA_REGISTER_CLASS_INFO *info,\n"
00632                  "  INT reg_index\n"
00633                  ")\n"
00634                  "{\n"
00635                  "  return info->reg_name[reg_index];\n"
00636                  "}\n");
00637 
00638   fprintf(hfile, "\ninline const ISA_REGISTER_SUBCLASS_INFO *ISA_REGISTER_SUBCLASS_Info(\n"
00639                  "  ISA_REGISTER_SUBCLASS sc\n"
00640                  ")\n"
00641                  "{\n"
00642                  "  extern const ISA_REGISTER_SUBCLASS_INFO ISA_REGISTER_SUBCLASS_info[];\n"
00643                  "  return &ISA_REGISTER_SUBCLASS_info[sc];\n"
00644                  "}\n");
00645 
00646   fprintf(hfile, "\ninline const char *ISA_REGISTER_SUBCLASS_INFO_Name(\n"
00647                  "  const ISA_REGISTER_SUBCLASS_INFO *info\n"
00648                  ")\n"
00649                  "{\n"
00650                  "  return info->name;\n"
00651                  "}\n");
00652 
00653   fprintf(hfile, "\ninline ISA_REGISTER_CLASS ISA_REGISTER_SUBCLASS_INFO_Class(\n"
00654                  "  const ISA_REGISTER_SUBCLASS_INFO *info\n"
00655                  ")\n"
00656                  "{\n"
00657                  "  return (ISA_REGISTER_CLASS)info->rclass;\n"
00658                  "}\n");
00659 
00660   fprintf(hfile, "\ninline INT ISA_REGISTER_SUBCLASS_INFO_Count(\n"
00661                  "  const ISA_REGISTER_SUBCLASS_INFO *info\n"
00662                  ")\n"
00663                  "{\n"
00664                  "  return info->count;\n"
00665                  "}\n");
00666 
00667   fprintf(hfile, "\ninline UINT ISA_REGISTER_SUBCLASS_INFO_Member(\n"
00668                  "  const ISA_REGISTER_SUBCLASS_INFO *info,\n"
00669                  "  INT n\n"
00670                  ")\n"
00671                  "{\n"
00672                  "  return info->members[n];\n"
00673                  "}\n");
00674 
00675   fprintf(hfile, "\ninline const char *ISA_REGISTER_SUBCLASS_INFO_Reg_Name(\n"
00676                  "  const ISA_REGISTER_SUBCLASS_INFO *info,\n"
00677                  "  INT n\n"
00678                  ")\n"
00679                  "{\n"
00680                  "  return info->reg_name[n];\n"
00681                  "}\n");
00682 
00683   fprintf(hfile, "\nextern void ISA_REGISTER_Initialize(void);\n");
00684 
00685   fprintf(efile, "ISA_REGISTER_Initialize\n");
00686 
00687   fprintf(cfile, "\nvoid ISA_REGISTER_Initialize(void)\n"
00688                  "{\n"
00689                  "  INT rc;\n"
00690                  "  INT mask = 1 << (INT)ISA_SUBSET_Value;\n"
00691                  "  for (rc = ISA_REGISTER_CLASS_MIN; "
00692                          "rc <= ISA_REGISTER_CLASS_MAX; ++rc) {\n"
00693                  "    INT i = ISA_REGISTER_CLASS_info_index[rc];\n"
00694                  "    const ISA_REGISTER_CLASS_INFO *info = "
00695                             "&ISA_REGISTER_CLASS_info[i];\n"
00696                  "    while ((info->isa_mask & mask) == 0) ++info, ++i;\n"
00697                  "    ISA_REGISTER_CLASS_info_index[rc] = i;\n"
00698                  "  }\n"
00699                  "}\n");
00700 
00701   Emit_Footer(hfile);
00702 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines