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 "enums_gen.h"
00043
00044 static const char* const description[] = {"\
00045 /* ====================================================================\n\
00046 * ====================================================================\n\
00047 *\n\
00048 * Description:\n\
00049 *\n\
00050 * A list of all the enum classes used in an ISA.\n\
00051 * It exports the following:\n\
00052 *",
00053 " * typedef (enum) ISA_ENUM_CLASS\n\
00054 * An enumeration of the enum classes.\n\
00055 *\n\
00056 * typedef (enum) ISA_ENUM_CLASS_VALUE\n\
00057 * An enumeration of the enum class values.\n\
00058 *\n\
00059 * typedef (struct) ISA_ENUM_CLASS_INFO\n\
00060 * Contains info about first and last ECV in the EC.\n\
00061 * The contents are private.\n\
00062 *",
00063 " * typedef (struct) ISA_ENUM_CLASS_VALUE_INFO\n\
00064 * Contains info about name and int-value of the ECV.\n\
00065 * The contents are private.\n\
00066 *\n\
00067 * const char * ISA_EC_Name (ISA_ENUM_CLASS)\n\
00068 * Returns name of EC.\n\
00069 *\n\
00070 * ISA_ENUM_CLASS_VALUE ISA_EC_First_Value (ISA_ENUM_CLASS)\n\
00071 * Returns the first ECV for the specified EC.\n\
00072 *" ,
00073 " * ISA_ENUM_CLASS_VALUE ISA_EC_Last_Value (ISA_ENUM_CLASS)\n\
00074 * Returns the last ECV for the specified EC.\n\
00075 * Note that it assumes all ECV for an EC are in the\n\
00076 * first/last range given by the above two functions.\n\
00077 *\n\
00078 * const char * ISA_ECV_Name (ISA_ENUM_CLASS_VALUE)\n\
00079 * Returns name of ECV.\n\
00080 *" ,
00081 " * INT ISA_ECV_Intval (ISA_ENUM_CLASS_VALUE)\n\
00082 * Returns int-value of ECV.\n\
00083 *\n\
00084 * ====================================================================\n\
00085 * ====================================================================\n\
00086 */", NULL};
00087
00088
00089 void Enums_Generator(void *pknobs, GEN_MODE mode)
00090 {
00091 FILE *c_file, *h_file, *export_file;
00092 int index, ec_count, ecv_count;
00093
00094
00095 Init_Module_Files(mode, "targ_isa_enums", &c_file, &h_file, &export_file);
00096 Emit_Header(h_file, "targ_isa_enums", description);
00097 fprintf(c_file, "#include \"targ_isa_enums.h\"\n");
00098 fprintf(export_file, "ISA_ENUM_CLASS_info\nISA_ENUM_CLASS_VALUE_info\n");
00099
00100
00101
00102 fprintf(h_file, "\ntypedef enum {\n");
00103 fprintf(h_file, "\tEC_UNDEFINED,\n");
00104 ec_count = EKAPI_EnumClassCount(pknobs);
00105 for (index=0; index<ec_count; index++)
00106 {
00107 fprintf(h_file, "\t%s,\n", EKAPI_EnumClassName(pknobs, index));
00108 }
00109 fprintf(h_file, "\tEC_MAX\n} ISA_ENUM_CLASS;\n\n");
00110
00111
00112 ecv_count = EKAPI_EvClassCount(pknobs);
00113 fprintf(h_file, "typedef enum {\n\tECV_UNDEFINED,\n");
00114 for (index=0; index<ecv_count; index++)
00115 {
00116 fprintf(h_file, "\t%s,\n", EKAPI_EvClassName(pknobs, index));
00117 }
00118 fprintf(h_file, "\tECV_MAX\n} ISA_ENUM_CLASS_VALUE;\n\n");
00119
00120
00121 fprintf(c_file, "\nconst ISA_ENUM_CLASS_INFO ISA_ENUM_CLASS_info[] = {\n");
00122 fprintf(c_file, "\t{ \"EC_UNDEFINED\",\tECV_UNDEFINED,\tECV_UNDEFINED },\n");
00123 for (index=0; index<ec_count; index++)
00124 {
00125 int first = EKAPI_EcFirstValue(pknobs, index);
00126 int last = EKAPI_EcLastValue(pknobs, index);
00127 fprintf(c_file, "\t{ \"%s\",\t%s,\t%s },\n",
00128 EKAPI_EnumClassName(pknobs, index),
00129 EKAPI_EvClassName(pknobs, first),
00130 EKAPI_EvClassName(pknobs, last)
00131 );
00132 }
00133 fprintf(c_file, "};\n\n");
00134
00135
00136 fprintf(c_file, "const ISA_ENUM_CLASS_VALUE_INFO ISA_ENUM_CLASS_VALUE_info[] = {\n");
00137 fprintf(c_file, "\t{ \"UNDEFINED\",\t-1 },\n");
00138 for (index=0; index<ecv_count; index++)
00139 {
00140 fprintf(c_file, "\t{ \"%s\",\t%d },\n",
00141 EKAPI_EvClassAsmName(pknobs, index),
00142 EKAPI_EvClassValue(pknobs, index)
00143 );
00144 }
00145 fprintf(c_file, "};\n\n");
00146
00147
00148 fprintf(h_file, "typedef struct {\n"
00149 " char *name;\n"
00150 " ISA_ENUM_CLASS_VALUE first;\n"
00151 " ISA_ENUM_CLASS_VALUE last;\n"
00152 "} ISA_ENUM_CLASS_INFO;\n"
00153 "extern const ISA_ENUM_CLASS_INFO ISA_ENUM_CLASS_info[];\n"
00154 "\n"
00155 "typedef struct {\n"
00156 " char *name;\n"
00157 " INT intval;\n"
00158 "} ISA_ENUM_CLASS_VALUE_INFO;\n"
00159 "extern const ISA_ENUM_CLASS_VALUE_INFO ISA_ENUM_CLASS_VALUE_info[];\n\n"
00160 );
00161
00162 fprintf(h_file, "inline const char * ISA_EC_Name (ISA_ENUM_CLASS ec)\n"
00163 "{\n"
00164 " return ISA_ENUM_CLASS_info[ec].name;\n"
00165 "}\n"
00166 "\n"
00167 "inline ISA_ENUM_CLASS_VALUE ISA_EC_First_Value (ISA_ENUM_CLASS ec)\n"
00168 "{\n"
00169 " return ISA_ENUM_CLASS_info[ec].first;\n"
00170 "}\n"
00171 "\n"
00172 "inline ISA_ENUM_CLASS_VALUE ISA_EC_Last_Value (ISA_ENUM_CLASS ec)\n"
00173 "{\n"
00174 " return ISA_ENUM_CLASS_info[ec].last;\n"
00175 "}\n"
00176 "\n"
00177 "inline const char * ISA_ECV_Name (ISA_ENUM_CLASS_VALUE ecv)\n"
00178 "{\n"
00179 " return ISA_ENUM_CLASS_VALUE_info[ecv].name;\n"
00180 "}\n"
00181 "\n"
00182 "inline INT ISA_ECV_Intval (ISA_ENUM_CLASS_VALUE ecv)\n"
00183 "{\n"
00184 " return ISA_ENUM_CLASS_VALUE_info[ecv].intval;\n"
00185 "}\n\n"
00186 );
00187
00188 Emit_Tailer(h_file);
00189 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00190 }
00191