Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
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_enums_gen.cxx 00038 // 00039 // Generate a list of enum classes and their values. 00040 // 00042 // 00043 00044 #include <stddef.h> 00045 #include <stdlib.h> 00046 #include <stdarg.h> 00047 #include <stdio.h> 00048 #include <assert.h> 00049 00050 #include <vector> 00051 00052 using namespace std; 00053 00054 #include "gen_util.h" 00055 #include "isa_enums_gen.h" 00056 00057 typedef struct { 00058 const char *ecv_ecname; 00059 const char *ecv_name; 00060 int ecv_int; 00061 } ECV_struct; 00062 00063 typedef struct { 00064 const char *ec_name; 00065 int first_ecv; 00066 int last_ecv; 00067 } EC_struct; 00068 00069 static vector<ECV_struct> all_ecv; 00070 static vector<EC_struct> all_ec; 00071 00072 static const char * const interface[] = { 00073 "/* ====================================================================", 00074 " * ====================================================================", 00075 " *", 00076 " * Description:", 00077 " *", 00078 " * A list of all the enum classes used in an ISA.", 00079 " * It exports the following:", 00080 " *", 00081 " * typedef (enum) ISA_ENUM_CLASS", 00082 " * An enumeration of the enum classes.", 00083 " *", 00084 " * typedef (enum) ISA_ENUM_CLASS_VALUE", 00085 " * An enumeration of the enum class values.", 00086 " *", 00087 " * typedef (struct) ISA_ENUM_CLASS_INFO", 00088 " * Contains info about first and last ECV in the EC.", 00089 " * The contents are private.", 00090 " *", 00091 " * typedef (struct) ISA_ENUM_CLASS_VALUE_INFO", 00092 " * Contains info about name and int-value of the ECV.", 00093 " * The contents are private.", 00094 " *", 00095 " * const char * ISA_EC_Name (ISA_ENUM_CLASS)", 00096 " * Returns name of EC.", 00097 " *", 00098 " * ISA_ENUM_CLASS_VALUE ISA_EC_First_Value (ISA_ENUM_CLASS)", 00099 " * Returns the first ECV for the specified EC.", 00100 " *", 00101 " * ISA_ENUM_CLASS_VALUE ISA_EC_Last_Value (ISA_ENUM_CLASS)", 00102 " * Returns the last ECV for the specified EC.", 00103 " * Note that it assumes all ECV for an EC are in the", 00104 " * first/last range given by the above two functions.", 00105 " *", 00106 " * const char * ISA_ECV_Name (ISA_ENUM_CLASS_VALUE)", 00107 " * Returns name of ECV.", 00108 " *", 00109 " * INT ISA_ECV_Intval (ISA_ENUM_CLASS_VALUE)", 00110 " * Returns int-value of ECV.", 00111 " *", 00112 " * ====================================================================", 00113 " * ====================================================================", 00114 " */", 00115 NULL 00116 }; 00117 00119 void ISA_Enums_Begin (void) 00121 // See interface description. 00123 { 00124 // start with undefined value 00125 ECV_struct current_ecv = {"","UNDEFINED",UNDEFINED}; 00126 all_ecv.push_back (current_ecv); 00127 EC_struct current_ec = {"UNDEFINED",0,0}; 00128 all_ec.push_back (current_ec); 00129 } 00130 00132 void ISA_Create_Enum_Class ( const char* name, ...) 00134 // See interface description. 00136 { 00137 const char *ecv_name; 00138 va_list ap; 00139 EC_struct current_ec; 00140 ECV_struct current_ecv; 00141 current_ec.ec_name = name; 00142 current_ec.first_ecv = all_ecv.size(); 00143 va_start(ap, name); 00144 do { // loop through ecvs 00145 ecv_name = va_arg(ap, char*); 00146 current_ecv.ecv_ecname = name; 00147 current_ecv.ecv_name = ecv_name ? ecv_name : ""; 00148 current_ecv.ecv_int = va_arg(ap, int); 00149 if (current_ecv.ecv_int == UNDEFINED) 00150 break; // no default value 00151 all_ecv.push_back (current_ecv); 00152 } while (ecv_name != NULL); 00153 va_end(ap); 00154 current_ec.last_ecv = all_ecv.size() - 1; 00155 all_ec.push_back (current_ec); 00156 } 00157 00158 00159 static const char* 00160 Print_ECV_EName (const char *name) 00161 { 00162 // will print direct to file, so can use temp buffers 00163 static char buf[80]; 00164 char *p = (char*) name; 00165 int i = 0; 00166 if (name == NULL) 00167 return "_none"; 00168 else if (name[0] != '\0' && name[0] != '.' && name[0] != '_') { 00169 // insert leading _ 00170 buf[0] = '_'; 00171 ++i; 00172 } 00173 for ( ; *p != '\0'; ++p) { 00174 switch (*p) { 00175 case '.': 00176 buf[i++] = '_'; 00177 break; 00178 case '@': 00179 // remove from name 00180 break; 00181 default: 00182 buf[i++] = *p; 00183 break; 00184 } 00185 } 00186 buf[i] = '\0'; 00187 return buf; 00188 } 00189 00191 void ISA_Enums_End(void) 00193 // See interface description. 00195 { 00196 vector<EC_struct>::iterator iec; 00197 vector<ECV_struct>::iterator iecv; 00198 ECV_struct tecv; 00199 00200 #define FNAME "targ_isa_enums" 00201 char buf[1000]; 00202 sprintf (buf, "%s.h", FNAME); 00203 FILE* hfile = fopen(buf, "w"); 00204 sprintf (buf, "%s.c", FNAME); 00205 FILE* cfile = fopen(buf, "w"); 00206 sprintf (buf, "%s.Exported", FNAME); 00207 FILE* efile = fopen(buf, "w"); 00208 00209 fprintf(cfile,"#include \"%s.h\"\n\n", FNAME); 00210 00211 sprintf (buf, "%s", FNAME); 00212 Emit_Header (hfile, buf, interface); 00213 00214 fprintf(hfile, "\ntypedef enum {\n"); 00215 for ( iec = all_ec.begin(); iec != all_ec.end(); ++iec) { 00216 fprintf(hfile, "\tEC%s,\n", Print_ECV_EName(iec->ec_name)); 00217 } 00218 fprintf(hfile, "\tEC_MAX\n"); 00219 fprintf(hfile, "} ISA_ENUM_CLASS;\n"); 00220 fprintf(hfile, "\ntypedef enum {\n"); 00221 for ( iecv = all_ecv.begin(); iecv != all_ecv.end(); ++iecv) { 00222 // have to use multiple calls since Print_ECV_EName uses a static bufr 00223 fprintf(hfile, "\tECV%s", Print_ECV_EName (iecv->ecv_ecname)); 00224 fprintf(hfile, "%s,\n", Print_ECV_EName (iecv->ecv_name)); 00225 } 00226 fprintf(hfile, "\tECV_MAX\n"); 00227 fprintf(hfile, "} ISA_ENUM_CLASS_VALUE;\n"); 00228 00229 fprintf(hfile, "\ntypedef struct {\n" 00230 " char *name;\n" 00231 " ISA_ENUM_CLASS_VALUE first;\n" 00232 " ISA_ENUM_CLASS_VALUE last;\n" 00233 "} ISA_ENUM_CLASS_INFO;\n"); 00234 fprintf(hfile, "extern const ISA_ENUM_CLASS_INFO ISA_ENUM_CLASS_info[];\n"); 00235 fprintf(efile, "ISA_ENUM_CLASS_info\n"); 00236 fprintf(cfile, "const ISA_ENUM_CLASS_INFO ISA_ENUM_CLASS_info[] = {\n"); 00237 for ( iec = all_ec.begin(); iec != all_ec.end(); ++iec) { 00238 fprintf(cfile, "\t{ \"EC%s\",", Print_ECV_EName(iec->ec_name)); 00239 tecv = all_ecv[iec->first_ecv]; 00240 // have to use multiple calls since Print_ECV_EName uses a static bufr 00241 fprintf(cfile, "\tECV%s", Print_ECV_EName(tecv.ecv_ecname)); 00242 fprintf(cfile, "%s,", Print_ECV_EName(tecv.ecv_name)); 00243 tecv = all_ecv[iec->last_ecv]; 00244 // have to use multiple calls since Print_ECV_EName uses a static bufr 00245 fprintf(cfile, "\tECV%s", Print_ECV_EName(tecv.ecv_ecname)); 00246 fprintf(cfile, "%s },\n", Print_ECV_EName(tecv.ecv_name)); 00247 } 00248 fprintf(cfile, "};\n\n"); 00249 00250 fprintf(hfile, "\ntypedef struct {\n" 00251 " char *name;\n" 00252 " INT intval;\n" 00253 "} ISA_ENUM_CLASS_VALUE_INFO;\n"); 00254 fprintf(hfile, "extern const ISA_ENUM_CLASS_VALUE_INFO ISA_ENUM_CLASS_VALUE_info[];\n\n"); 00255 fprintf(efile, "ISA_ENUM_CLASS_VALUE_info\n"); 00256 fprintf(cfile, "const ISA_ENUM_CLASS_VALUE_INFO ISA_ENUM_CLASS_VALUE_info[] = {\n"); 00257 for ( iecv = all_ecv.begin(); iecv != all_ecv.end(); ++iecv) { 00258 fprintf(cfile, "\t{ \"%s\",\t%d },\n", iecv->ecv_name, iecv->ecv_int); 00259 } 00260 fprintf(cfile, "};\n\n"); 00261 00262 fprintf(hfile, "inline const char * ISA_EC_Name (ISA_ENUM_CLASS ec)\n" 00263 "{\n" 00264 " return ISA_ENUM_CLASS_info[ec].name;\n" 00265 "}\n\n"); 00266 00267 fprintf(hfile, "inline ISA_ENUM_CLASS_VALUE ISA_EC_First_Value (ISA_ENUM_CLASS ec)\n" 00268 "{\n" 00269 " return ISA_ENUM_CLASS_info[ec].first;\n" 00270 "}\n\n"); 00271 00272 fprintf(hfile, "inline ISA_ENUM_CLASS_VALUE ISA_EC_Last_Value (ISA_ENUM_CLASS ec)\n" 00273 "{\n" 00274 " return ISA_ENUM_CLASS_info[ec].last;\n" 00275 "}\n\n"); 00276 00277 fprintf(hfile, "inline const char * ISA_ECV_Name (ISA_ENUM_CLASS_VALUE ecv)\n" 00278 "{\n" 00279 " return ISA_ENUM_CLASS_VALUE_info[ecv].name;\n" 00280 "}\n\n"); 00281 00282 fprintf(hfile, "inline INT ISA_ECV_Intval (ISA_ENUM_CLASS_VALUE ecv)\n" 00283 "{\n" 00284 " return ISA_ENUM_CLASS_VALUE_info[ecv].intval;\n" 00285 "}\n\n"); 00286 00287 Emit_Footer (hfile); 00288 }