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 "subset_gen.h"
00043
00044 static const char * const description[]= {"\
00045 /* ====================================================================\n\
00046 * ====================================================================\n\
00047 *\n\
00048 * Description:\n\
00049 *\n\
00050 * A description of the ISA subset hierarchy. The description\n\
00051 * exports the following:\n\
00052 *\n\
00053 * typedef (enum) ISA_SUBSET\n\
00054 * An enumberated type of the different subsets.\n\
00055 *\n\
00056 * const ISA_SUBSET ISA_SUBSET_UNDEFINED\n\
00057 * Useful value guaranteed not to be a valid ISA_SUBSET.\n\
00058 *\n\
00059 * extern ISA_SUBSET ISA_SUBSET_Value\n\
00060 * A variable containing the current subset value.\n\
00061 *\n\
00062 * const char* ISA_SUBSET_Name( ISA_SUBSET subset )\n\
00063 * Returns a name suitable for printing.\n\
00064 *\n\
00065 * int ISA_SUBSET_Member( ISA_SUBSET subset, TOP opcode )\n\
00066 * Is the given <opcode> a member of the given <subset>?\n\
00067 *\n\
00068 * ====================================================================\n\
00069 * ====================================================================\n\
00070 */", NULL};
00071
00072 static const char func_subset_name[]= "\
00073 const char* ISA_SUBSET_Name( ISA_SUBSET subset ) {\n\
00074 return isa_subset_names[(INT)subset];\n\
00075 }\n";
00076
00077 static const char* func_subset_member =
00078 "int ISA_SUBSET_Member( ISA_SUBSET subset, TOP opcode )\n"
00079 "{\n"
00080 " INT byte_index = ((UINT) opcode) / 8;\n"
00081 " INT bit_index = ((UINT) opcode) % 8;\n"
00082 " INT byte = isa_subset_opcode_table[(int) subset][byte_index];\n"
00083 " return (byte >> bit_index) & 1;\n"
00084 "}\n";
00085
00086
00087
00088
00089 void Subset_Generator(void *pknobs, GEN_MODE mode)
00090 {
00091 FILE *c_file, *h_file, *export_file;
00092 int subset_index, op_index;
00093
00094 Init_Module_Files(mode, "targ_isa_subset", &c_file, &h_file, &export_file);
00095 Emit_Header(h_file, "targ_isa_subset", description);
00096 fprintf(h_file, "#include \"topcode.h\"\n\n");
00097 fprintf(c_file, "#include \"topcode.h\"\n");
00098 fprintf(c_file, "#include \"targ_isa_subset.h\"\n\n");
00099
00100
00101 fprintf(h_file, "typedef enum {\n");
00102 fprintf(c_file, "static const char* const isa_subset_names[] = {\n");
00103 for (subset_index=0; subset_index<EKAPI_SubsetCount(pknobs); subset_index++){
00104 char * buf = EKAPI_SubsetName4id(pknobs, subset_index);
00105 fprintf(c_file, " \"%s\",", buf);
00106 fprintf(h_file, " ISA_SUBSET_%s,\n", buf);
00107
00108 }
00109 fprintf(h_file, " ISA_SUBSET_UNDEFINED,\n");
00110 fprintf(h_file, " ISA_SUBSET_MIN=ISA_SUBSET_%s,\n",
00111 EKAPI_SubsetName4id(pknobs,0));
00112 fprintf(h_file, " ISA_SUBSET_MAX=ISA_SUBSET_%s\n} ISA_SUBSET;\n",
00113 EKAPI_SubsetName4id(pknobs,EKAPI_SubsetCount(pknobs)-1));
00114 fprintf(c_file, " \"UNDEFINED\"\n};\n");
00115
00116
00117 fprintf(h_file, "extern ISA_SUBSET ISA_SUBSET_Value;\n\n");
00118 fprintf(export_file, "ISA_SUBSET_Value\n");
00119 fprintf(c_file, "ISA_SUBSET ISA_SUBSET_Value = ISA_SUBSET_UNDEFINED;\n\n");
00120
00121
00122 fprintf(h_file, "extern const char* ISA_SUBSET_Name( ISA_SUBSET subset );\n");
00123 fprintf(export_file, "ISA_SUBSET_Name\n");
00124 fprintf(h_file, "extern INT ISA_SUBSET_Member( ISA_SUBSET subset,\n\
00125 TOP opcode );\n");
00126 fprintf(export_file, "ISA_SUBSET_Member\n");
00127
00128
00129 fprintf(c_file, func_subset_name);
00130
00131
00132 fprintf(c_file, "static const char isa_subset_opcode_table[%d][%d] = {\n",
00133 EKAPI_SubsetCount(pknobs)+1, (EKAPI_OpCount(pknobs))/8 +1);
00134 for (subset_index=0; subset_index<EKAPI_SubsetCount(pknobs); subset_index++){
00135 char * cur_subset = EKAPI_SubsetName4id(pknobs, subset_index);
00136 fprintf(c_file, " { /* %s */\n", cur_subset);
00137
00138 char bitset = 0;
00139 char comment[20*8]="";
00140 for (op_index=0; op_index<EKAPI_OpCount(pknobs); op_index++){
00141 char * this_set = EKAPI_Op2SubSet(pknobs, op_index);
00142
00143 strcat(comment, EKAPI_OpName4id(pknobs, op_index));
00144 strcat(comment, " ");
00145 bitset = bitset << 1;
00146 bitset |= (strcmp(this_set, cur_subset)==0)? 1 : 0;
00147
00148 if (op_index%8 == 7){
00149 fprintf(c_file, " %#o, /* %s*/\n", bitset, comment);
00150 bitset = 0;
00151 comment[0]='\0';
00152 }
00153 }
00154
00155 fprintf(c_file, " %#o, /* %s*/\n", bitset, comment);
00156 bitset = 0;
00157 comment[0]='\0';
00158 fprintf(c_file, " },\n");
00159 }
00160
00161
00162 fprintf(c_file, " { /* UNDEFINED */\n 0\n }\n};\n");
00163 fprintf(c_file, func_subset_member);
00164
00165 Emit_Tailer(h_file);
00166 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00167 }