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 #include "lits_gen.h"
00042
00043 static const char* const description[] = {"\
00044 /* ====================================================================\n\
00045 * ====================================================================\n\
00046 *\n\
00047 * Description:\n\
00048 *\n\
00049 * A list of all the lit classes used in an ISA.\n\
00050 * It exports the following:\n\
00051 *",
00052 " * typedef (enum) ISA_LIT_CLASS\n\
00053 * An enumeration of the lit classes.\n\
00054 *\n\
00055 * typedef (struct) ISA_LIT_CLASS_INFO\n\
00056 * Contains info about first and last ECV in the EC.\n\
00057 * The contents are private.\n\
00058 *\n\
00059 * typedef (struct) ISA_LIT_CLASS_VALUE_INFO\n\
00060 * Contains info about name and min/max of the LC.\n\
00061 * The contents are private.\n\
00062 *",
00063 " * const char * ISA_LC_Name (ISA_LIT_CLASS lc)\n\
00064 * Returns name of <lc>.\n\
00065 *\n\
00066 * INT64 ISA_LC_Min (ISA_LIT_CLASS lc)\n\
00067 * Returns the minimum value for the specified <lc>. For classes\n\
00068 * that have multiple sub-ranges, ISA_LC_Min returns the smallest\n\
00069 * minimum of all the sub-ranges.\n\
00070 *",
00071 " * INT64 ISA_LC_Max (ISA_LIT_CLASS lc)\n\
00072 * Returns the maximum value for the specified <lc>. For classes\n\
00073 * that have multiple sub-ranges, ISA_LC_Max returns the largest\n\
00074 * maximum of all the sub-ranges.\n\
00075 *\n\
00076 * BOOL ISA_LC_Is_Signed (ISA_LIT_CLASS lc)\n\
00077 * Returns whether the lit-class <lc> is signed.\n\
00078 *",
00079 " * BOOL ISA_LC_Value_In_Class (INT64 val, ISA_LIT_CLASS lc)\n\
00080 * Returns whether <val> is a value that belongs to <lc>.\n\
00081 *\n\
00082 * ====================================================================\n\
00083 * ====================================================================\n\
00084 */", NULL};
00085
00086 void Lits_Generator(void *pknobs, GEN_MODE mode)
00087 {
00088 FILE *c_file, *h_file, *export_file;
00089 int index, lc_count, r_index;
00090 char suffix_INT64[6] = "LL";
00091 #ifdef TARG_WIN
00092 strcpy(suffix_INT64, "mI64");
00093 #endif
00094
00095 Init_Module_Files(mode, "targ_isa_lits", &c_file, &h_file, &export_file);
00096 Emit_Header(h_file, "targ_isa_lits", description);
00097 fprintf(c_file, "#include \"targ_isa_lits.h\"\n\n");
00098 fprintf(export_file, "ISA_LIT_CLASS_info\n");
00099
00100
00101 lc_count = EKAPI_LitClassCount(pknobs);
00102 fprintf(h_file, "typedef enum {\n");
00103 fprintf(h_file, "\tLC_UNDEFINED,\n");
00104 for(index=0; index<lc_count; index++)
00105 {
00106 char *name = EKAPI_LitClassName(pknobs, index);
00107 fprintf(h_file, "\t%s,\n",
00108 name
00109 );
00110 free(name);
00111 }
00112 fprintf(h_file, "\tLC_MAX\n} ISA_LIT_CLASS;\n\n");
00113
00114
00115 fprintf(c_file, "const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[] = {\n");
00116 fprintf(c_file,
00117 " { { { 0x0000000000000000%s, 0x0000000000000000%s } }, 0, 0, \"LC_UNDEFINED\" },\n"
00118 , suffix_INT64, suffix_INT64);
00119 for(index=0; index<lc_count; index++)
00120 {
00121 EKAPI_RANGE ranges[20];
00122 int range_num = EKAPI_GetLcRange(pknobs, index, ranges);
00123 char *lc_name = EKAPI_LitClassName(pknobs, index);
00124 BOOL sign = EKAPI_LitIsSigned(pknobs, index);
00125
00126
00127 fprintf(c_file, " { { { 0x%016llx%s, 0x%016llx%s }",
00128 ranges[0].min,
00129 suffix_INT64,
00130 ranges[range_num-1].max,
00131 suffix_INT64
00132 );
00133
00134 for(r_index=0; r_index<range_num; r_index++)
00135 {
00136 fprintf(c_file, ",\n { 0x%016llx%s, 0x%016llx%s }",
00137 ranges[r_index].min,
00138 suffix_INT64,
00139 ranges[r_index].max,
00140 suffix_INT64
00141 );
00142 }
00143
00144 fprintf(c_file, " }, %d, %d, \"%s\" },\n",
00145 range_num,
00146 sign,
00147 lc_name);
00148 free(lc_name);
00149 }
00150 fprintf(c_file, "};\n");
00151
00152
00153 fprintf(h_file, "typedef struct {\n"
00154 " struct { INT64 min; INT64 max; } range[9];\n"
00155 " mUINT8 num_ranges;\n"
00156 " mBOOL is_signed;\n"
00157 " const char *name;\n"
00158 "} ISA_LIT_CLASS_INFO;\n\n"
00159 );
00160
00161 fprintf(h_file, "inline const char * ISA_LC_Name (ISA_LIT_CLASS lc)\n"
00162 "{\n"
00163 " extern const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[];\n"
00164 " return ISA_LIT_CLASS_info[lc].name;\n"
00165 "}\n\n"
00166 "inline INT64 ISA_LC_Min (ISA_LIT_CLASS lc)\n"
00167 "{\n"
00168 " extern const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[];\n"
00169 " return ISA_LIT_CLASS_info[lc].range[0].min;\n"
00170 "}\n\n"
00171 "inline INT64 ISA_LC_Max (ISA_LIT_CLASS lc)\n"
00172 "{\n"
00173 " extern const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[];\n"
00174 " return ISA_LIT_CLASS_info[lc].range[0].max;\n"
00175 "}\n\n"
00176 "inline BOOL ISA_LC_Is_Signed (ISA_LIT_CLASS lc)\n"
00177 "{\n"
00178 " extern const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[];\n"
00179 " return ISA_LIT_CLASS_info[lc].is_signed;\n"
00180 "}\n\n"
00181 "inline BOOL ISA_LC_Value_In_Class (INT64 val, ISA_LIT_CLASS lc)\n"
00182 "{\n"
00183 " extern const ISA_LIT_CLASS_INFO ISA_LIT_CLASS_info[];\n"
00184 " const ISA_LIT_CLASS_INFO *plc = ISA_LIT_CLASS_info + lc;\n"
00185 " INT i;\n"
00186 " for (i = 1; i <= plc->num_ranges; ++i) {\n"
00187 " INT64 min = plc->range[i].min;\n"
00188 " INT64 max = plc->range[i].max;\n"
00189 " if ( plc->is_signed ) {\n"
00190 " if (val >= min && val <= max) return TRUE;\n"
00191 " } else {\n"
00192 " if ((UINT64)val >= (UINT64)min && (UINT64)val <= (UINT64)max) return TRUE;\n"
00193 " }\n"
00194 " }\n"
00195 " return FALSE;\n"
00196 "}\n"
00197 );
00198
00199 Emit_Tailer(h_file);
00200 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00201 }