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 "opcode_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 (actually just an enum of all the opcodes).\n\
00051 * The description exports the following:\n\
00052 *",
00053 " * TOPCODE stands for Target OPCODE; prefix is TOP.\n\
00054 *\n\
00055 * typedef (enum) TOP\n\
00056 * Contains all the target opcodes. Their names have the form\n\
00057 * TOP_<name>.\n\
00058 *\n\
00059 * typedef mTOP\n\
00060 * The smallest integer type that can contain all values of a TOP,\n\
00061 * including TOP_UNDEFINED -- useful for conserving space in tables.\n\
00062 *",
00063 " * const TOP TOP_UNDEFINED\n\
00064 * Useful value guaranteed not to be a valid TOP.\n\
00065 *\n\
00066 * const int TOP_count\n\
00067 * Gives the number of topcodes.\n\
00068 *\n\
00069 * const char* TOP_Name(TOP topcode)\n\
00070 * Returns an assembler style name for the given TOP.\n\
00071 *" ,
00072 " * ====================================================================\n\
00073 * ====================================================================\n\
00074 */", NULL };
00075
00076
00077
00078
00079
00080 void Opcode_Generator(void *pknobs, GEN_MODE mode)
00081 {
00082 FILE *c_file, *h_file, *export_file;
00083 int op_index;
00084
00085 Init_Module_Files(mode, "topcode", &c_file, &h_file, &export_file);
00086 Emit_Header(h_file, "TOPCODE", description);
00087 fprintf(c_file, "#include \"topcode.h\"\n");
00088
00089 fprintf(h_file, "typedef enum topcode {\n");
00090 fprintf(c_file, "static const char* const top_names[] = {\n");
00091 for (op_index=0; op_index<EKAPI_OpCount(pknobs); op_index++){
00092 char * buf = EKAPI_OpName4id(pknobs, op_index);
00093 fprintf(c_file, " \"%s\",\n", buf);
00094 Dot2Line(buf);
00095 fprintf(h_file, " TOP_%s,\n", buf);
00096
00097 }
00098 fprintf(c_file, " \"UNDEFINED\"\n};\n\n");
00099 fprintf(h_file, " TOP_UNDEFINED\n} TOP;\n\n");
00100
00101 fprintf(c_file, "const char* TOP_Name(TOP topcode)\n\
00102 {\n\
00103 return top_names[(int)topcode];\n\
00104 }\n");
00105 fprintf(h_file, "typedef mUINT16 mTOP;\n\n\
00106 #define TOP_count 759\n\n\
00107 extern const char* TOP_Name(TOP topcode);\n");
00108 fprintf(export_file, "TOP_Name\n");
00109
00110 Emit_Tailer(h_file);
00111 Close_Module_Files(mode, &c_file, &h_file, &export_file);
00112 }
00113