musashi: don't generate unneeded handlers
[picodrive.git] / cpu / musashi / m68kmake.c
index d7cbc37..361481b 100644 (file)
@@ -3,10 +3,10 @@
 /* ======================================================================== */\r
 /*\r
  *                                  MUSASHI\r
- *                                Version 3.3\r
+ *                                Version 3.31\r
  *\r
  * A portable Motorola M680x0 processor emulation engine.\r
- * Copyright 1998-2001 Karl Stenerud.  All rights reserved.\r
+ * Copyright 1998-2007 Karl Stenerud.  All rights reserved.\r
  *\r
  * This code may be freely used for non-commercial purposes as long as this\r
  * copyright notice remains unaltered in the source code and any binary files\r
@@ -52,7 +52,7 @@
  */\r
 \r
 \r
-const char* g_version = "3.3";\r
+static const char* g_version = "3.31";\r
 \r
 /* ======================================================================== */\r
 /* =============================== INCLUDES =============================== */\r
@@ -88,9 +88,6 @@ const char* g_version = "3.3";
 #define FILENAME_INPUT      "m68k_in.c"\r
 #define FILENAME_PROTOTYPE  "m68kops.h"\r
 #define FILENAME_TABLE      "m68kops.c"\r
-#define FILENAME_OPS_AC     "m68kopac.c"\r
-#define FILENAME_OPS_DM     "m68kopdm.c"\r
-#define FILENAME_OPS_NZ     "m68kopnz.c"\r
 \r
 \r
 /* Identifier sequences recognized by this program */\r
@@ -240,7 +237,7 @@ void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode);
 void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode);\r
 void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op);\r
 void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset);\r
-void process_opcode_handlers(void);\r
+void process_opcode_handlers(FILE* filep);\r
 void populate_table(void);\r
 void read_insert(char* insert);\r
 \r
@@ -257,9 +254,6 @@ char g_input_filename[M68K_MAX_PATH] = FILENAME_INPUT;
 FILE* g_input_file = NULL;\r
 FILE* g_prototype_file = NULL;\r
 FILE* g_table_file = NULL;\r
-FILE* g_ops_ac_file = NULL;\r
-FILE* g_ops_dm_file = NULL;\r
-FILE* g_ops_nz_file = NULL;\r
 \r
 int g_num_functions = 0;  /* Number of functions processed */\r
 int g_num_primitives = 0; /* Number of function primitives read */\r
@@ -481,9 +475,6 @@ void error_exit(const char* fmt, ...)
 \r
        if(g_prototype_file) fclose(g_prototype_file);\r
        if(g_table_file) fclose(g_table_file);\r
-       if(g_ops_ac_file) fclose(g_ops_ac_file);\r
-       if(g_ops_dm_file) fclose(g_ops_dm_file);\r
-       if(g_ops_nz_file) fclose(g_ops_nz_file);\r
        if(g_input_file) fclose(g_input_file);\r
 \r
        exit(EXIT_FAILURE);\r
@@ -500,9 +491,6 @@ void perror_exit(const char* fmt, ...)
 \r
        if(g_prototype_file) fclose(g_prototype_file);\r
        if(g_table_file) fclose(g_table_file);\r
-       if(g_ops_ac_file) fclose(g_ops_ac_file);\r
-       if(g_ops_dm_file) fclose(g_ops_dm_file);\r
-       if(g_ops_nz_file) fclose(g_ops_nz_file);\r
        if(g_input_file) fclose(g_input_file);\r
 \r
        exit(EXIT_FAILURE);\r
@@ -1001,10 +989,9 @@ void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct*
 }\r
 \r
 /* Process the opcode handlers section of the input file */\r
-void process_opcode_handlers(void)\r
+void process_opcode_handlers(FILE* filep)\r
 {\r
        FILE* input_file = g_input_file;\r
-       FILE* output_file;\r
        char func_name[MAX_LINE_LENGTH+1];\r
        char oper_name[MAX_LINE_LENGTH+1];\r
        int  oper_size;\r
@@ -1014,9 +1001,6 @@ void process_opcode_handlers(void)
        replace_struct* replace = malloc(sizeof(replace_struct));\r
        body_struct* body = malloc(sizeof(body_struct));\r
 \r
-\r
-       output_file = g_ops_ac_file;\r
-\r
        for(;;)\r
        {\r
                /* Find the first line of the function */\r
@@ -1059,23 +1043,22 @@ void process_opcode_handlers(void)
                if(opinfo == NULL)\r
                        error_exit("Unable to find matching table entry for %s", func_name);\r
 \r
-        /* Change output files if we pass 'c' or 'n' */\r
-               if(output_file == g_ops_ac_file && oper_name[0] > 'c')\r
-                       output_file = g_ops_dm_file;\r
-               else if(output_file == g_ops_dm_file && oper_name[0] > 'm')\r
-                       output_file = g_ops_nz_file;\r
+#if 1 /* PD hack: 000 only */\r
+               if (opinfo->cpus[0] == UNSPECIFIED_CH)\r
+                       continue;\r
+#endif\r
 \r
                replace->length = 0;\r
 \r
                /* Generate opcode variants */\r
                if(strcmp(opinfo->name, "bcc") == 0 || strcmp(opinfo->name, "scc") == 0)\r
-                       generate_opcode_cc_variants(output_file, body, replace, opinfo, 1);\r
+                       generate_opcode_cc_variants(filep, body, replace, opinfo, 1);\r
                else if(strcmp(opinfo->name, "dbcc") == 0)\r
-                       generate_opcode_cc_variants(output_file, body, replace, opinfo, 2);\r
+                       generate_opcode_cc_variants(filep, body, replace, opinfo, 2);\r
                else if(strcmp(opinfo->name, "trapcc") == 0)\r
-                       generate_opcode_cc_variants(output_file, body, replace, opinfo, 4);\r
+                       generate_opcode_cc_variants(filep, body, replace, opinfo, 4);\r
                else\r
-                       generate_opcode_ea_variants(output_file, body, replace, opinfo);\r
+                       generate_opcode_ea_variants(filep, body, replace, opinfo);\r
        }\r
 \r
        free(replace);\r
@@ -1248,7 +1231,9 @@ int main(int argc, char **argv)
        /* Inserts */\r
        char temp_insert[MAX_INSERT_LENGTH+1];\r
        char prototype_footer_insert[MAX_INSERT_LENGTH+1];\r
+       char table_header_insert[MAX_INSERT_LENGTH+1];\r
        char table_footer_insert[MAX_INSERT_LENGTH+1];\r
+       char ophandler_header_insert[MAX_INSERT_LENGTH+1];\r
        char ophandler_footer_insert[MAX_INSERT_LENGTH+1];\r
        /* Flags if we've processed certain parts already */\r
        int prototype_header_read = 0;\r
@@ -1260,8 +1245,8 @@ int main(int argc, char **argv)
        int table_body_read = 0;\r
        int ophandler_body_read = 0;\r
 \r
-       printf("\n\t\tMusashi v%s 68000, 68008, 68010, 68EC020, 68020 emulator\n", g_version);\r
-       printf("\t\tCopyright 1998-2000 Karl Stenerud (karl@mame.net)\n\n");\r
+       printf("\n\tMusashi v%s 68000, 68008, 68010, 68EC020, 68020, 68040 emulator\n", g_version);\r
+       printf("\tCopyright 1998-2007 Karl Stenerud (karl@mame.net)\n\n");\r
 \r
        /* Check if output path and source for the input file are given */\r
     if(argc > 1)\r
@@ -1293,18 +1278,6 @@ int main(int argc, char **argv)
        if((g_table_file = fopen(filename, "w")) == NULL)\r
                perror_exit("Unable to create table file (%s)\n", filename);\r
 \r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_AC);\r
-       if((g_ops_ac_file = fopen(filename, "w")) == NULL)\r
-               perror_exit("Unable to create ops ac file (%s)\n", filename);\r
-\r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_DM);\r
-       if((g_ops_dm_file = fopen(filename, "w")) == NULL)\r
-               perror_exit("Unable to create ops dm file (%s)\n", filename);\r
-\r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_NZ);\r
-       if((g_ops_nz_file = fopen(filename, "w")) == NULL)\r
-               perror_exit("Unable to create ops nz file (%s)\n", filename);\r
-\r
        if((g_input_file=fopen(g_input_filename, "r")) == NULL)\r
                perror_exit("can't open %s for input", g_input_filename);\r
 \r
@@ -1320,18 +1293,6 @@ int main(int argc, char **argv)
        if((g_table_file = fopen(filename, "wt")) == NULL)\r
                perror_exit("Unable to create table file (%s)\n", filename);\r
 \r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_AC);\r
-       if((g_ops_ac_file = fopen(filename, "wt")) == NULL)\r
-               perror_exit("Unable to create ops ac file (%s)\n", filename);\r
-\r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_DM);\r
-       if((g_ops_dm_file = fopen(filename, "wt")) == NULL)\r
-               perror_exit("Unable to create ops dm file (%s)\n", filename);\r
-\r
-       sprintf(filename, "%s%s", output_path, FILENAME_OPS_NZ);\r
-       if((g_ops_nz_file = fopen(filename, "wt")) == NULL)\r
-               perror_exit("Unable to create ops nz file (%s)\n", filename);\r
-\r
        if((g_input_file=fopen(g_input_filename, "rt")) == NULL)\r
                perror_exit("can't open %s for input", g_input_filename);\r
 \r
@@ -1360,18 +1321,14 @@ int main(int argc, char **argv)
                {\r
                        if(table_header_read)\r
                                error_exit("Duplicate table header");\r
-                       read_insert(temp_insert);\r
-                       fprintf(g_table_file, "%s", temp_insert);\r
+                       read_insert(table_header_insert);\r
                        table_header_read = 1;\r
                }\r
                else if(strcmp(section_id, ID_OPHANDLER_HEADER) == 0)\r
                {\r
                        if(ophandler_header_read)\r
                                error_exit("Duplicate opcode handler header");\r
-                       read_insert(temp_insert);\r
-                       fprintf(g_ops_ac_file, "%s\n\n", temp_insert);\r
-                       fprintf(g_ops_dm_file, "%s\n\n", temp_insert);\r
-                       fprintf(g_ops_nz_file, "%s\n\n", temp_insert);\r
+                       read_insert(ophandler_header_insert);\r
                        ophandler_header_read = 1;\r
                }\r
                else if(strcmp(section_id, ID_PROTOTYPE_FOOTER) == 0)\r
@@ -1424,7 +1381,9 @@ int main(int argc, char **argv)
                        if(ophandler_body_read)\r
                                error_exit("Duplicate opcode handler section");\r
 \r
-                       process_opcode_handlers();\r
+                       fprintf(g_table_file, "%s\n\n", ophandler_header_insert);\r
+                       process_opcode_handlers(g_table_file);\r
+                       fprintf(g_table_file, "%s\n\n", ophandler_footer_insert);\r
 \r
                        ophandler_body_read = 1;\r
                }\r
@@ -1448,13 +1407,11 @@ int main(int argc, char **argv)
                        if(!ophandler_body_read)\r
                                error_exit("Missing opcode handler body");\r
 \r
+                       fprintf(g_table_file, "%s\n\n", table_header_insert);\r
                        print_opcode_output_table(g_table_file);\r
+                       fprintf(g_table_file, "%s\n\n", table_footer_insert);\r
 \r
                        fprintf(g_prototype_file, "%s\n\n", prototype_footer_insert);\r
-                       fprintf(g_table_file, "%s\n\n", table_footer_insert);\r
-                       fprintf(g_ops_ac_file, "%s\n\n", ophandler_footer_insert);\r
-                       fprintf(g_ops_dm_file, "%s\n\n", ophandler_footer_insert);\r
-                       fprintf(g_ops_nz_file, "%s\n\n", ophandler_footer_insert);\r
 \r
                        break;\r
                }\r
@@ -1467,9 +1424,6 @@ int main(int argc, char **argv)
        /* Close all files and exit */\r
        fclose(g_prototype_file);\r
        fclose(g_table_file);\r
-       fclose(g_ops_ac_file);\r
-       fclose(g_ops_dm_file);\r
-       fclose(g_ops_nz_file);\r
        fclose(g_input_file);\r
 \r
        printf("Generated %d opcode handlers from %d primitives\n", g_num_functions, g_num_primitives);\r