1 /* ======================================================================== */
2 /* ========================= LICENSING & COPYRIGHT ======================== */
3 /* ======================================================================== */
8 * A portable Motorola M680x0 processor emulation engine.
9 * Copyright 1998-2001 Karl Stenerud. All rights reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
32 /* ======================================================================== */
33 /* ============================ CODE GENERATOR ============================ */
34 /* ======================================================================== */
36 * This is the code generator program which will generate the opcode table
37 * and the final opcode handlers.
39 * It requires an input file to function (default m68k_in.c), but you can
40 * specify your own like so:
42 * m68kmake <output path> <input file>
44 * where output path is the path where the output files should be placed, and
45 * input file is the file to use for input.
47 * If you modify the input file greatly from its released form, you may have
48 * to tweak the configuration section a bit since I'm using static allocation
49 * to keep things simple.
52 * TODO: - build a better code generator for the move instruction.
53 * - Add callm and rtm instructions
54 * - Fix RTE to handle other format words
55 * - Add address error (and bus error?) handling
59 char* g_version = "3.3";
61 /* ======================================================================== */
62 /* =============================== INCLUDES =============================== */
63 /* ======================================================================== */
73 /* ======================================================================== */
74 /* ============================= CONFIGURATION ============================ */
75 /* ======================================================================== */
77 #define M68K_MAX_PATH 1024
78 #define M68K_MAX_DIR 1024
80 #define NUM_CPUS 3 /* 000, 010, 020 */
81 #define MAX_LINE_LENGTH 200 /* length of 1 line */
82 #define MAX_BODY_LENGTH 300 /* Number of lines in 1 function */
83 #define MAX_REPLACE_LENGTH 30 /* Max number of replace strings */
84 #define MAX_INSERT_LENGTH 5000 /* Max size of insert piece */
85 #define MAX_NAME_LENGTH 30 /* Max length of ophandler name */
86 #define MAX_SPEC_PROC_LENGTH 4 /* Max length of special processing str */
87 #define MAX_SPEC_EA_LENGTH 5 /* Max length of specified EA str */
88 #define EA_ALLOWED_LENGTH 11 /* Max length of ea allowed str */
89 #define MAX_OPCODE_INPUT_TABLE_LENGTH 1000 /* Max length of opcode handler tbl */
90 #define MAX_OPCODE_OUTPUT_TABLE_LENGTH 3000 /* Max length of opcode handler tbl */
92 /* Default filenames */
93 #define FILENAME_INPUT "m68k_in.c"
94 #define FILENAME_PROTOTYPE "m68kops.h"
95 #define FILENAME_TABLE "m68kops.c"
96 #define FILENAME_OPS_AC "m68kopac.c"
97 #define FILENAME_OPS_DM "m68kopdm.c"
98 #define FILENAME_OPS_NZ "m68kopnz.c"
101 /* Identifier sequences recognized by this program */
103 #define ID_INPUT_SEPARATOR "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
105 #define ID_BASE "M68KMAKE"
106 #define ID_PROTOTYPE_HEADER ID_BASE "_PROTOTYPE_HEADER"
107 #define ID_PROTOTYPE_FOOTER ID_BASE "_PROTOTYPE_FOOTER"
108 #define ID_TABLE_HEADER ID_BASE "_TABLE_HEADER"
109 #define ID_TABLE_FOOTER ID_BASE "_TABLE_FOOTER"
110 #define ID_TABLE_BODY ID_BASE "_TABLE_BODY"
111 #define ID_TABLE_START ID_BASE "_TABLE_START"
112 #define ID_OPHANDLER_HEADER ID_BASE "_OPCODE_HANDLER_HEADER"
113 #define ID_OPHANDLER_FOOTER ID_BASE "_OPCODE_HANDLER_FOOTER"
114 #define ID_OPHANDLER_BODY ID_BASE "_OPCODE_HANDLER_BODY"
115 #define ID_END ID_BASE "_END"
117 #define ID_OPHANDLER_NAME ID_BASE "_OP"
118 #define ID_OPHANDLER_EA_AY_8 ID_BASE "_GET_EA_AY_8"
119 #define ID_OPHANDLER_EA_AY_16 ID_BASE "_GET_EA_AY_16"
120 #define ID_OPHANDLER_EA_AY_32 ID_BASE "_GET_EA_AY_32"
121 #define ID_OPHANDLER_OPER_AY_8 ID_BASE "_GET_OPER_AY_8"
122 #define ID_OPHANDLER_OPER_AY_16 ID_BASE "_GET_OPER_AY_16"
123 #define ID_OPHANDLER_OPER_AY_32 ID_BASE "_GET_OPER_AY_32"
124 #define ID_OPHANDLER_CC ID_BASE "_CC"
125 #define ID_OPHANDLER_NOT_CC ID_BASE "_NOT_CC"
130 #endif /* DECL_SPEC */
134 /* ======================================================================== */
135 /* ============================== PROTOTYPES ============================== */
136 /* ======================================================================== */
138 #define CPU_TYPE_000 0
139 #define CPU_TYPE_010 1
140 #define CPU_TYPE_020 2
142 #define UNSPECIFIED "."
143 #define UNSPECIFIED_CH '.'
145 #define HAS_NO_EA_MODE(A) (strcmp(A, "..........") == 0)
146 #define HAS_EA_AI(A) ((A)[0] == 'A')
147 #define HAS_EA_PI(A) ((A)[1] == '+')
148 #define HAS_EA_PD(A) ((A)[2] == '-')
149 #define HAS_EA_DI(A) ((A)[3] == 'D')
150 #define HAS_EA_IX(A) ((A)[4] == 'X')
151 #define HAS_EA_AW(A) ((A)[5] == 'W')
152 #define HAS_EA_AL(A) ((A)[6] == 'L')
153 #define HAS_EA_PCDI(A) ((A)[7] == 'd')
154 #define HAS_EA_PCIX(A) ((A)[8] == 'x')
155 #define HAS_EA_I(A) ((A)[9] == 'I')
159 EA_MODE_NONE, /* No special addressing mode */
160 EA_MODE_AI, /* Address register indirect */
161 EA_MODE_PI, /* Address register indirect with postincrement */
162 EA_MODE_PI7, /* Address register 7 indirect with postincrement */
163 EA_MODE_PD, /* Address register indirect with predecrement */
164 EA_MODE_PD7, /* Address register 7 indirect with predecrement */
165 EA_MODE_DI, /* Address register indirect with displacement */
166 EA_MODE_IX, /* Address register indirect with index */
167 EA_MODE_AW, /* Absolute word */
168 EA_MODE_AL, /* Absolute long */
169 EA_MODE_PCDI, /* Program counter indirect with displacement */
170 EA_MODE_PCIX, /* Program counter indirect with index */
171 EA_MODE_I /* Immediate */
175 /* Everything we need to know about an opcode */
178 char name[MAX_NAME_LENGTH]; /* opcode handler name */
179 unsigned char size; /* Size of operation */
180 char spec_proc[MAX_SPEC_PROC_LENGTH]; /* Special processing mode */
181 char spec_ea[MAX_SPEC_EA_LENGTH]; /* Specified effective addressing mode */
182 unsigned char bits; /* Number of significant bits (used for sorting the table) */
183 unsigned short op_mask; /* Mask to apply for matching an opcode to a handler */
184 unsigned short op_match; /* Value to match after masking */
185 char ea_allowed[EA_ALLOWED_LENGTH]; /* Effective addressing modes allowed */
186 char cpu_mode[NUM_CPUS]; /* User or supervisor mode */
187 char cpus[NUM_CPUS+1]; /* Allowed CPUs */
188 unsigned char cycles[NUM_CPUS]; /* cycles for 000, 010, 020 */
192 /* All modifications necessary for a specific EA mode of an instruction */
197 unsigned int mask_add;
198 unsigned int match_add;
202 /* Holds the body of a function */
205 char body[MAX_BODY_LENGTH][MAX_LINE_LENGTH+1];
210 /* Holds a sequence of search / replace strings */
213 char replace[MAX_REPLACE_LENGTH][2][MAX_LINE_LENGTH+1];
218 /* Function Prototypes */
219 void error_exit(char* fmt, ...);
220 void perror_exit(char* fmt, ...);
221 int check_strsncpy(char* dst, char* src, int maxlength);
222 int check_atoi(char* str, int *result);
223 int skip_spaces(char* str);
224 int num_bits(int value);
225 int atoh(char* buff);
226 int fgetline(char* buff, int nchars, FILE* file);
227 int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type);
228 opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea);
229 opcode_struct* find_illegal_opcode(void);
230 int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea);
231 void add_replace_string(replace_struct* replace, char* search_str, char* replace_str);
232 void write_body(FILE* filep, body_struct* body, replace_struct* replace);
233 void get_base_name(char* base_name, opcode_struct* op);
234 void write_prototype(FILE* filep, char* base_name);
235 void write_function_name(FILE* filep, char* base_name);
236 void add_opcode_output_table_entry(opcode_struct* op, char* name);
237 static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr);
238 void print_opcode_output_table(FILE* filep);
239 void write_table_entry(FILE* filep, opcode_struct* op);
240 void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode);
241 void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode);
242 void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op);
243 void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset);
244 void process_opcode_handlers(void);
245 void populate_table(void);
246 void read_insert(char* insert);
250 /* ======================================================================== */
251 /* ================================= DATA ================================= */
252 /* ======================================================================== */
254 /* Name of the input file */
255 char g_input_filename[M68K_MAX_PATH] = FILENAME_INPUT;
258 FILE* g_input_file = NULL;
259 FILE* g_prototype_file = NULL;
260 FILE* g_table_file = NULL;
261 FILE* g_ops_ac_file = NULL;
262 FILE* g_ops_dm_file = NULL;
263 FILE* g_ops_nz_file = NULL;
265 int g_num_functions = 0; /* Number of functions processed */
266 int g_num_primitives = 0; /* Number of function primitives read */
267 int g_line_number = 1; /* Current line number */
269 /* Opcode handler table */
270 opcode_struct g_opcode_input_table[MAX_OPCODE_INPUT_TABLE_LENGTH];
272 opcode_struct g_opcode_output_table[MAX_OPCODE_OUTPUT_TABLE_LENGTH];
273 int g_opcode_output_table_length = 0;
275 ea_info_struct g_ea_info_table[13] =
276 {/* fname ea mask match */
277 {"", "", 0x00, 0x00}, /* EA_MODE_NONE */
278 {"ai", "AY_AI", 0x38, 0x10}, /* EA_MODE_AI */
279 {"pi", "AY_PI", 0x38, 0x18}, /* EA_MODE_PI */
280 {"pi7", "A7_PI", 0x3f, 0x1f}, /* EA_MODE_PI7 */
281 {"pd", "AY_PD", 0x38, 0x20}, /* EA_MODE_PD */
282 {"pd7", "A7_PD", 0x3f, 0x27}, /* EA_MODE_PD7 */
283 {"di", "AY_DI", 0x38, 0x28}, /* EA_MODE_DI */
284 {"ix", "AY_IX", 0x38, 0x30}, /* EA_MODE_IX */
285 {"aw", "AW", 0x3f, 0x38}, /* EA_MODE_AW */
286 {"al", "AL", 0x3f, 0x39}, /* EA_MODE_AL */
287 {"pcdi", "PCDI", 0x3f, 0x3a}, /* EA_MODE_PCDI */
288 {"pcix", "PCIX", 0x3f, 0x3b}, /* EA_MODE_PCIX */
289 {"i", "I", 0x3f, 0x3c}, /* EA_MODE_I */
293 char* g_cc_table[16][2] =
295 { "t", "T"}, /* 0000 */
296 { "f", "F"}, /* 0001 */
297 {"hi", "HI"}, /* 0010 */
298 {"ls", "LS"}, /* 0011 */
299 {"cc", "CC"}, /* 0100 */
300 {"cs", "CS"}, /* 0101 */
301 {"ne", "NE"}, /* 0110 */
302 {"eq", "EQ"}, /* 0111 */
303 {"vc", "VC"}, /* 1000 */
304 {"vs", "VS"}, /* 1001 */
305 {"pl", "PL"}, /* 1010 */
306 {"mi", "MI"}, /* 1011 */
307 {"ge", "GE"}, /* 1100 */
308 {"lt", "LT"}, /* 1101 */
309 {"gt", "GT"}, /* 1110 */
310 {"le", "LE"}, /* 1111 */
313 /* size to index translator (0 -> 0, 8 and 16 -> 1, 32 -> 2) */
314 int g_size_select_table[33] =
317 0, 0, 0, 0, 0, 0, 0, 1, /* 8 */
318 0, 0, 0, 0, 0, 0, 0, 1, /* 16 */
319 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 /* 32 */
322 /* Extra cycles required for certain EA modes */
323 int g_ea_cycle_table[13][NUM_CPUS][3] =
325 {{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}}, /* EA_MODE_NONE */
326 {{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}}, /* EA_MODE_AI */
327 {{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}}, /* EA_MODE_PI */
328 {{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}}, /* EA_MODE_PI7 */
329 {{ 0, 6, 10}, { 0, 6, 10}, { 0, 5, 5}}, /* EA_MODE_PD */
330 {{ 0, 6, 10}, { 0, 6, 10}, { 0, 5, 5}}, /* EA_MODE_PD7 */
331 {{ 0, 8, 12}, { 0, 8, 12}, { 0, 5, 5}}, /* EA_MODE_DI */
332 {{ 0, 10, 14}, { 0, 10, 14}, { 0, 7, 7}}, /* EA_MODE_IX */
333 {{ 0, 8, 12}, { 0, 8, 12}, { 0, 4, 4}}, /* EA_MODE_AW */
334 {{ 0, 12, 16}, { 0, 12, 16}, { 0, 4, 4}}, /* EA_MODE_AL */
335 {{ 0, 8, 12}, { 0, 8, 12}, { 0, 5, 5}}, /* EA_MODE_PCDI */
336 {{ 0, 10, 14}, { 0, 10, 14}, { 0, 7, 7}}, /* EA_MODE_PCIX */
337 {{ 0, 4, 8}, { 0, 4, 8}, { 0, 2, 4}}, /* EA_MODE_I */
340 /* Extra cycles for JMP instruction (000, 010) */
341 int g_jmp_cycle_table[13] =
343 0, /* EA_MODE_NONE */
353 6, /* EA_MODE_PCDI */
354 10, /* EA_MODE_PCIX */
358 /* Extra cycles for JSR instruction (000, 010) */
359 int g_jsr_cycle_table[13] =
361 0, /* EA_MODE_NONE */
371 6, /* EA_MODE_PCDI */
372 10, /* EA_MODE_PCIX */
376 /* Extra cycles for LEA instruction (000, 010) */
377 int g_lea_cycle_table[13] =
379 0, /* EA_MODE_NONE */
389 8, /* EA_MODE_PCDI */
390 12, /* EA_MODE_PCIX */
394 /* Extra cycles for PEA instruction (000, 010) */
395 int g_pea_cycle_table[13] =
397 0, /* EA_MODE_NONE */
407 10, /* EA_MODE_PCDI */
408 14, /* EA_MODE_PCIX */
412 /* Extra cycles for MOVES instruction (010) */
413 int g_moves_cycle_table[13][3] =
415 { 0, 0, 0}, /* EA_MODE_NONE */
416 { 0, 4, 6}, /* EA_MODE_AI */
417 { 0, 4, 6}, /* EA_MODE_PI */
418 { 0, 4, 6}, /* EA_MODE_PI7 */
419 { 0, 6, 12}, /* EA_MODE_PD */
420 { 0, 6, 12}, /* EA_MODE_PD7 */
421 { 0, 12, 16}, /* EA_MODE_DI */
422 { 0, 16, 20}, /* EA_MODE_IX */
423 { 0, 12, 16}, /* EA_MODE_AW */
424 { 0, 16, 20}, /* EA_MODE_AL */
425 { 0, 0, 0}, /* EA_MODE_PCDI */
426 { 0, 0, 0}, /* EA_MODE_PCIX */
427 { 0, 0, 0}, /* EA_MODE_I */
430 /* Extra cycles for CLR instruction (010) */
431 int g_clr_cycle_table[13][3] =
433 { 0, 0, 0}, /* EA_MODE_NONE */
434 { 0, 4, 6}, /* EA_MODE_AI */
435 { 0, 4, 6}, /* EA_MODE_PI */
436 { 0, 4, 6}, /* EA_MODE_PI7 */
437 { 0, 6, 8}, /* EA_MODE_PD */
438 { 0, 6, 8}, /* EA_MODE_PD7 */
439 { 0, 8, 10}, /* EA_MODE_DI */
440 { 0, 10, 14}, /* EA_MODE_IX */
441 { 0, 8, 10}, /* EA_MODE_AW */
442 { 0, 10, 14}, /* EA_MODE_AL */
443 { 0, 0, 0}, /* EA_MODE_PCDI */
444 { 0, 0, 0}, /* EA_MODE_PCIX */
445 { 0, 0, 0}, /* EA_MODE_I */
450 /* ======================================================================== */
451 /* =========================== UTILITY FUNCTIONS ========================== */
452 /* ======================================================================== */
454 /* Print an error message and exit with status error */
455 void error_exit(char* fmt, ...)
458 fprintf(stderr, "In %s, near or on line %d:\n\t", g_input_filename, g_line_number);
460 vfprintf(stderr, fmt, args);
462 fprintf(stderr, "\n");
464 if(g_prototype_file) fclose(g_prototype_file);
465 if(g_table_file) fclose(g_table_file);
466 if(g_ops_ac_file) fclose(g_ops_ac_file);
467 if(g_ops_dm_file) fclose(g_ops_dm_file);
468 if(g_ops_nz_file) fclose(g_ops_nz_file);
469 if(g_input_file) fclose(g_input_file);
474 /* Print an error message, call perror(), and exit with status error */
475 void perror_exit(char* fmt, ...)
479 vfprintf(stderr, fmt, args);
483 if(g_prototype_file) fclose(g_prototype_file);
484 if(g_table_file) fclose(g_table_file);
485 if(g_ops_ac_file) fclose(g_ops_ac_file);
486 if(g_ops_dm_file) fclose(g_ops_dm_file);
487 if(g_ops_nz_file) fclose(g_ops_nz_file);
488 if(g_input_file) fclose(g_input_file);
494 /* copy until 0 or space and exit with error if we read too far */
495 int check_strsncpy(char* dst, char* src, int maxlength)
498 while(*src && *src != ' ')
501 if(p - dst > maxlength)
502 error_exit("Field too long");
508 /* copy until 0 or specified character and exit with error if we read too far */
509 int check_strcncpy(char* dst, char* src, char delim, int maxlength)
512 while(*src && *src != delim)
515 if(p - dst > maxlength)
516 error_exit("Field too long");
522 /* convert ascii to integer and exit with error if we find invalid data */
523 int check_atoi(char* str, int *result)
527 while(*p >= '0' && *p <= '9')
532 if(*p != ' ' && *p != 0)
533 error_exit("Malformed integer value (%c)", *p);
538 /* Skip past spaces in a string */
539 int skip_spaces(char* str)
549 /* Count the number of set bits in a value */
550 int num_bits(int value)
552 value = ((value & 0xaaaa) >> 1) + (value & 0x5555);
553 value = ((value & 0xcccc) >> 2) + (value & 0x3333);
554 value = ((value & 0xf0f0) >> 4) + (value & 0x0f0f);
555 value = ((value & 0xff00) >> 8) + (value & 0x00ff);
559 /* Convert a hex value written in ASCII */
566 if(*buff >= '0' && *buff <= '9')
569 accum += *buff - '0';
571 else if(*buff >= 'a' && *buff <= 'f')
574 accum += *buff - 'a' + 10;
581 /* Get a line of text from a file, discarding any end-of-line characters */
582 int fgetline(char* buff, int nchars, FILE* file)
586 if(fgets(buff, nchars, file) == NULL)
589 memcpy(buff, buff + 1, nchars - 1);
591 length = strlen(buff);
592 while(length && (buff[length-1] == '\r' || buff[length-1] == '\n'))
602 /* ======================================================================== */
603 /* =========================== HELPER FUNCTIONS =========================== */
604 /* ======================================================================== */
606 /* Calculate the number of cycles an opcode requires */
607 int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type)
609 int size = g_size_select_table[op->size];
611 if(op->cpus[cpu_type] == '.')
614 if(cpu_type < CPU_TYPE_020)
616 if(cpu_type == CPU_TYPE_010)
618 if(strcmp(op->name, "moves") == 0)
619 return op->cycles[cpu_type] + g_moves_cycle_table[ea_mode][size];
620 if(strcmp(op->name, "clr") == 0)
621 return op->cycles[cpu_type] + g_clr_cycle_table[ea_mode][size];
624 /* ASG: added these cases -- immediate modes take 2 extra cycles here */
625 if(cpu_type == CPU_TYPE_000 && ea_mode == EA_MODE_I &&
626 ((strcmp(op->name, "add") == 0 && strcmp(op->spec_proc, "er") == 0) ||
627 strcmp(op->name, "adda") == 0 ||
628 (strcmp(op->name, "and") == 0 && strcmp(op->spec_proc, "er") == 0) ||
629 (strcmp(op->name, "or") == 0 && strcmp(op->spec_proc, "er") == 0) ||
630 (strcmp(op->name, "sub") == 0 && strcmp(op->spec_proc, "er") == 0) ||
631 strcmp(op->name, "suba") == 0))
632 return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size] + 2;
634 if(strcmp(op->name, "jmp") == 0)
635 return op->cycles[cpu_type] + g_jmp_cycle_table[ea_mode];
636 if(strcmp(op->name, "jsr") == 0)
637 return op->cycles[cpu_type] + g_jsr_cycle_table[ea_mode];
638 if(strcmp(op->name, "lea") == 0)
639 return op->cycles[cpu_type] + g_lea_cycle_table[ea_mode];
640 if(strcmp(op->name, "pea") == 0)
641 return op->cycles[cpu_type] + g_pea_cycle_table[ea_mode];
643 return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size];
646 /* Find an opcode in the opcode handler list */
647 opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea)
652 for(op = g_opcode_input_table;op->name != NULL;op++)
654 if( strcmp(name, op->name) == 0 &&
655 (size == op->size) &&
656 strcmp(spec_proc, op->spec_proc) == 0 &&
657 strcmp(spec_ea, op->spec_ea) == 0)
663 /* Specifically find the illegal opcode in the list */
664 opcode_struct* find_illegal_opcode(void)
668 for(op = g_opcode_input_table;op->name != NULL;op++)
670 if(strcmp(op->name, "illegal") == 0)
676 /* Parse an opcode handler name */
677 int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea)
679 char* ptr = strstr(src, ID_OPHANDLER_NAME);
684 ptr += strlen(ID_OPHANDLER_NAME) + 1;
686 ptr += check_strcncpy(name, ptr, ',', MAX_NAME_LENGTH);
687 if(*ptr != ',') return 0;
689 ptr += skip_spaces(ptr);
692 ptr = strstr(ptr, ",");
693 if(ptr == NULL) return 0;
695 ptr += skip_spaces(ptr);
697 ptr += check_strcncpy(spec_proc, ptr, ',', MAX_SPEC_PROC_LENGTH);
698 if(*ptr != ',') return 0;
700 ptr += skip_spaces(ptr);
702 ptr += check_strcncpy(spec_ea, ptr, ')', MAX_SPEC_EA_LENGTH);
703 if(*ptr != ')') return 0;
705 ptr += skip_spaces(ptr);
711 /* Add a search/replace pair to a replace structure */
712 void add_replace_string(replace_struct* replace, char* search_str, char* replace_str)
714 if(replace->length >= MAX_REPLACE_LENGTH)
715 error_exit("overflow in replace structure");
717 strcpy(replace->replace[replace->length][0], search_str);
718 strcpy(replace->replace[replace->length++][1], replace_str);
721 /* Write a function body while replacing any selected strings */
722 void write_body(FILE* filep, body_struct* body, replace_struct* replace)
727 char output[MAX_LINE_LENGTH+1];
728 char temp_buff[MAX_LINE_LENGTH+1];
731 for(i=0;i<body->length;i++)
733 strcpy(output, body->body[i]);
734 /* Check for the base directive header */
735 if(strstr(output, ID_BASE) != NULL)
737 /* Search for any text we need to replace */
739 for(j=0;j<replace->length;j++)
741 ptr = strstr(output, replace->replace[j][0]);
744 /* We found something to replace */
746 strcpy(temp_buff, ptr+strlen(replace->replace[j][0]));
747 strcpy(ptr, replace->replace[j][1]);
748 strcat(ptr, temp_buff);
751 /* Found a directive with no matching replace string */
753 error_exit("Unknown " ID_BASE " directive");
755 fprintf(filep, "%s\n", output);
757 fprintf(filep, "\n\n");
760 /* Generate a base function name from an opcode struct */
761 void get_base_name(char* base_name, opcode_struct* op)
763 sprintf(base_name, "m68k_op_%s", op->name);
765 sprintf(base_name+strlen(base_name), "_%d", op->size);
766 if(strcmp(op->spec_proc, UNSPECIFIED) != 0)
767 sprintf(base_name+strlen(base_name), "_%s", op->spec_proc);
768 if(strcmp(op->spec_ea, UNSPECIFIED) != 0)
769 sprintf(base_name+strlen(base_name), "_%s", op->spec_ea);
772 /* Write the prototype of an opcode handler function */
773 void write_prototype(FILE* filep, char* base_name)
775 fprintf(filep, "void %s(void);\n", base_name);
778 /* Write the name of an opcode handler function */
779 void write_function_name(FILE* filep, char* base_name)
781 fprintf(filep, "void %s(void)\n", base_name);
784 void add_opcode_output_table_entry(opcode_struct* op, char* name)
787 if(g_opcode_output_table_length > MAX_OPCODE_OUTPUT_TABLE_LENGTH)
788 error_exit("Opcode output table overflow");
790 ptr = g_opcode_output_table + g_opcode_output_table_length++;
793 strcpy(ptr->name, name);
794 ptr->bits = num_bits(ptr->op_mask);
798 * Comparison function for qsort()
799 * For entries with an equal number of set bits in
800 * the mask compare the match values
802 static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr)
804 const opcode_struct *a = aptr, *b = bptr;
805 if(a->bits != b->bits)
806 return a->bits - b->bits;
807 if(a->op_mask != b->op_mask)
808 return a->op_mask - b->op_mask;
809 return a->op_match - b->op_match;
812 void print_opcode_output_table(FILE* filep)
815 qsort((void *)g_opcode_output_table, g_opcode_output_table_length, sizeof(g_opcode_output_table[0]), compare_nof_true_bits);
817 for(i=0;i<g_opcode_output_table_length;i++)
818 write_table_entry(filep, g_opcode_output_table+i);
821 /* Write an entry in the opcode handler table */
822 void write_table_entry(FILE* filep, opcode_struct* op)
826 fprintf(filep, "\t{%-28s, 0x%04x, 0x%04x, {",
827 op->name, op->op_mask, op->op_match);
829 for(i=0;i<NUM_CPUS;i++)
831 fprintf(filep, "%3d", op->cycles[i]);
833 fprintf(filep, ", ");
836 fprintf(filep, "}},\n");
839 /* Fill out an opcode struct with a specific addressing mode of the source opcode struct */
840 void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode)
846 for(i=0;i<NUM_CPUS;i++)
847 dst->cycles[i] = get_oper_cycles(dst, ea_mode, i);
848 if(strcmp(dst->spec_ea, UNSPECIFIED) == 0 && ea_mode != EA_MODE_NONE)
849 sprintf(dst->spec_ea, "%s", g_ea_info_table[ea_mode].fname_add);
850 dst->op_mask |= g_ea_info_table[ea_mode].mask_add;
851 dst->op_match |= g_ea_info_table[ea_mode].match_add;
855 /* Generate a final opcode handler from the provided data */
856 void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode)
858 char str[MAX_LINE_LENGTH+1];
859 opcode_struct* op = malloc(sizeof(opcode_struct));
861 /* Set the opcode structure and write the tables, prototypes, etc */
862 set_opcode_struct(opinfo, op, ea_mode);
863 get_base_name(str, op);
864 write_prototype(g_prototype_file, str);
865 add_opcode_output_table_entry(op, str);
866 write_function_name(filep, str);
868 /* Add any replace strings needed */
869 if(ea_mode != EA_MODE_NONE)
871 sprintf(str, "EA_%s_8()", g_ea_info_table[ea_mode].ea_add);
872 add_replace_string(replace, ID_OPHANDLER_EA_AY_8, str);
873 sprintf(str, "EA_%s_16()", g_ea_info_table[ea_mode].ea_add);
874 add_replace_string(replace, ID_OPHANDLER_EA_AY_16, str);
875 sprintf(str, "EA_%s_32()", g_ea_info_table[ea_mode].ea_add);
876 add_replace_string(replace, ID_OPHANDLER_EA_AY_32, str);
877 sprintf(str, "OPER_%s_8()", g_ea_info_table[ea_mode].ea_add);
878 add_replace_string(replace, ID_OPHANDLER_OPER_AY_8, str);
879 sprintf(str, "OPER_%s_16()", g_ea_info_table[ea_mode].ea_add);
880 add_replace_string(replace, ID_OPHANDLER_OPER_AY_16, str);
881 sprintf(str, "OPER_%s_32()", g_ea_info_table[ea_mode].ea_add);
882 add_replace_string(replace, ID_OPHANDLER_OPER_AY_32, str);
885 /* Now write the function body with the selected replace strings */
886 write_body(filep, body, replace);
891 /* Generate opcode variants based on available addressing modes */
892 void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op)
894 int old_length = replace->length;
896 /* No ea modes available for this opcode */
897 if(HAS_NO_EA_MODE(op->ea_allowed))
899 generate_opcode_handler(filep, body, replace, op, EA_MODE_NONE);
903 /* Check for and create specific opcodes for each available addressing mode */
904 if(HAS_EA_AI(op->ea_allowed))
905 generate_opcode_handler(filep, body, replace, op, EA_MODE_AI);
906 replace->length = old_length;
907 if(HAS_EA_PI(op->ea_allowed))
909 generate_opcode_handler(filep, body, replace, op, EA_MODE_PI);
910 replace->length = old_length;
912 generate_opcode_handler(filep, body, replace, op, EA_MODE_PI7);
914 replace->length = old_length;
915 if(HAS_EA_PD(op->ea_allowed))
917 generate_opcode_handler(filep, body, replace, op, EA_MODE_PD);
918 replace->length = old_length;
920 generate_opcode_handler(filep, body, replace, op, EA_MODE_PD7);
922 replace->length = old_length;
923 if(HAS_EA_DI(op->ea_allowed))
924 generate_opcode_handler(filep, body, replace, op, EA_MODE_DI);
925 replace->length = old_length;
926 if(HAS_EA_IX(op->ea_allowed))
927 generate_opcode_handler(filep, body, replace, op, EA_MODE_IX);
928 replace->length = old_length;
929 if(HAS_EA_AW(op->ea_allowed))
930 generate_opcode_handler(filep, body, replace, op, EA_MODE_AW);
931 replace->length = old_length;
932 if(HAS_EA_AL(op->ea_allowed))
933 generate_opcode_handler(filep, body, replace, op, EA_MODE_AL);
934 replace->length = old_length;
935 if(HAS_EA_PCDI(op->ea_allowed))
936 generate_opcode_handler(filep, body, replace, op, EA_MODE_PCDI);
937 replace->length = old_length;
938 if(HAS_EA_PCIX(op->ea_allowed))
939 generate_opcode_handler(filep, body, replace, op, EA_MODE_PCIX);
940 replace->length = old_length;
941 if(HAS_EA_I(op->ea_allowed))
942 generate_opcode_handler(filep, body, replace, op, EA_MODE_I);
943 replace->length = old_length;
946 /* Generate variants of condition code opcodes */
947 void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset)
952 int old_length = replace->length;
953 opcode_struct* op = malloc(sizeof(opcode_struct));
957 op->op_mask |= 0x0f00;
959 /* Do all condition codes except t and f */
962 /* Add replace strings for this condition code */
963 sprintf(repl, "COND_%s()", g_cc_table[i][1]);
964 sprintf(replnot, "COND_NOT_%s()", g_cc_table[i][1]);
966 add_replace_string(replace, ID_OPHANDLER_CC, repl);
967 add_replace_string(replace, ID_OPHANDLER_NOT_CC, replnot);
969 /* Set the new opcode info */
970 strcpy(op->name+offset, g_cc_table[i][0]);
972 op->op_match = (op->op_match & 0xf0ff) | (i<<8);
974 /* Generate all opcode variants for this modified opcode */
975 generate_opcode_ea_variants(filep, body, replace, op);
976 /* Remove the above replace strings */
977 replace->length = old_length;
982 /* Process the opcode handlers section of the input file */
983 void process_opcode_handlers(void)
985 FILE* input_file = g_input_file;
987 char func_name[MAX_LINE_LENGTH+1];
988 char oper_name[MAX_LINE_LENGTH+1];
990 char oper_spec_proc[MAX_LINE_LENGTH+1];
991 char oper_spec_ea[MAX_LINE_LENGTH+1];
992 opcode_struct* opinfo;
993 replace_struct* replace = malloc(sizeof(replace_struct));
994 body_struct* body = malloc(sizeof(body_struct));
997 output_file = g_ops_ac_file;
1001 /* Find the first line of the function */
1003 while(strstr(func_name, ID_OPHANDLER_NAME) == NULL)
1005 if(strcmp(func_name, ID_INPUT_SEPARATOR) == 0)
1009 return; /* all done */
1011 if(fgetline(func_name, MAX_LINE_LENGTH, input_file) < 0)
1012 error_exit("Premature end of file when getting function name");
1014 /* Get the rest of the function */
1015 for(body->length=0;;body->length++)
1017 if(body->length > MAX_BODY_LENGTH)
1018 error_exit("Function too long");
1020 if(fgetline(body->body[body->length], MAX_LINE_LENGTH, input_file) < 0)
1021 error_exit("Premature end of file when getting function body");
1023 if(body->body[body->length][0] == '}')
1032 /* Extract the function name information */
1033 if(!extract_opcode_info(func_name, oper_name, &oper_size, oper_spec_proc, oper_spec_ea))
1034 error_exit("Invalid " ID_OPHANDLER_NAME " format");
1036 /* Find the corresponding table entry */
1037 opinfo = find_opcode(oper_name, oper_size, oper_spec_proc, oper_spec_ea);
1039 error_exit("Unable to find matching table entry for %s", func_name);
1041 /* Change output files if we pass 'c' or 'n' */
1042 if(output_file == g_ops_ac_file && oper_name[0] > 'c')
1043 output_file = g_ops_dm_file;
1044 else if(output_file == g_ops_dm_file && oper_name[0] > 'm')
1045 output_file = g_ops_nz_file;
1047 replace->length = 0;
1049 /* Generate opcode variants */
1050 if(strcmp(opinfo->name, "bcc") == 0 || strcmp(opinfo->name, "scc") == 0)
1051 generate_opcode_cc_variants(output_file, body, replace, opinfo, 1);
1052 else if(strcmp(opinfo->name, "dbcc") == 0)
1053 generate_opcode_cc_variants(output_file, body, replace, opinfo, 2);
1054 else if(strcmp(opinfo->name, "trapcc") == 0)
1055 generate_opcode_cc_variants(output_file, body, replace, opinfo, 4);
1057 generate_opcode_ea_variants(output_file, body, replace, opinfo);
1065 /* Populate the opcode handler table from the input file */
1066 void populate_table(void)
1069 char bitpattern[17];
1071 char buff[MAX_LINE_LENGTH];
1077 /* Find the start of the table */
1078 while(strcmp(buff, ID_TABLE_START) != 0)
1079 if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
1080 error_exit("Premature EOF while reading table");
1082 /* Process the entire table */
1083 for(op = g_opcode_input_table;;op++)
1085 if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
1086 error_exit("Premature EOF while reading table");
1087 if(strlen(buff) == 0)
1089 /* We finish when we find an input separator */
1090 if(strcmp(buff, ID_INPUT_SEPARATOR) == 0)
1093 /* Extract the info from the table */
1097 ptr += skip_spaces(ptr);
1098 ptr += check_strsncpy(op->name, ptr, MAX_NAME_LENGTH);
1101 ptr += skip_spaces(ptr);
1102 ptr += check_atoi(ptr, &temp);
1103 op->size = (unsigned char)temp;
1105 /* Special processing */
1106 ptr += skip_spaces(ptr);
1107 ptr += check_strsncpy(op->spec_proc, ptr, MAX_SPEC_PROC_LENGTH);
1109 /* Specified EA Mode */
1110 ptr += skip_spaces(ptr);
1111 ptr += check_strsncpy(op->spec_ea, ptr, MAX_SPEC_EA_LENGTH);
1113 /* Bit Pattern (more processing later) */
1114 ptr += skip_spaces(ptr);
1115 ptr += check_strsncpy(bitpattern, ptr, 17);
1117 /* Allowed Addressing Mode List */
1118 ptr += skip_spaces(ptr);
1119 ptr += check_strsncpy(op->ea_allowed, ptr, EA_ALLOWED_LENGTH);
1121 /* CPU operating mode (U = user or supervisor, S = supervisor only */
1122 ptr += skip_spaces(ptr);
1123 for(i=0;i<NUM_CPUS;i++)
1125 op->cpu_mode[i] = *ptr++;
1126 ptr += skip_spaces(ptr);
1129 /* Allowed CPUs for this instruction */
1130 for(i=0;i<NUM_CPUS;i++)
1132 ptr += skip_spaces(ptr);
1133 if(*ptr == UNSPECIFIED_CH)
1135 op->cpus[i] = UNSPECIFIED_CH;
1141 op->cpus[i] = '0' + i;
1142 ptr += check_atoi(ptr, &temp);
1143 op->cycles[i] = (unsigned char)temp;
1147 /* generate mask and match from bitpattern */
1152 op->op_mask |= (bitpattern[i] != '.') << (15-i);
1153 op->op_match |= (bitpattern[i] == '1') << (15-i);
1156 /* Terminate the list */
1160 /* Read a header or footer insert from the input file */
1161 void read_insert(char* insert)
1164 char* overflow = insert + MAX_INSERT_LENGTH - MAX_LINE_LENGTH;
1166 char* first_blank = NULL;
1170 /* Skip any leading blank lines */
1171 for(length = 0;length == 0;length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file))
1173 error_exit("Buffer overflow reading inserts");
1175 error_exit("Premature EOF while reading inserts");
1177 /* Advance and append newline */
1179 strcpy(ptr++, "\n");
1181 /* Read until next separator */
1184 /* Read a new line */
1186 error_exit("Buffer overflow reading inserts");
1187 if((length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file)) < 0)
1188 error_exit("Premature EOF while reading inserts");
1190 /* Stop if we read a separator */
1191 if(strcmp(ptr, ID_INPUT_SEPARATOR) == 0)
1194 /* keep track in case there are trailing blanks */
1197 if(first_blank == NULL)
1203 /* Advance and append newline */
1205 strcpy(ptr++, "\n");
1208 /* kill any trailing blank lines */
1216 /* ======================================================================== */
1217 /* ============================= MAIN FUNCTION ============================ */
1218 /* ======================================================================== */
1220 int main(int argc, char **argv)
1223 char output_path[M68K_MAX_DIR] = "";
1224 char filename[M68K_MAX_PATH];
1225 /* Section identifier */
1226 char section_id[MAX_LINE_LENGTH+1];
1228 char temp_insert[MAX_INSERT_LENGTH+1];
1229 char prototype_footer_insert[MAX_INSERT_LENGTH+1];
1230 char table_footer_insert[MAX_INSERT_LENGTH+1];
1231 char ophandler_footer_insert[MAX_INSERT_LENGTH+1];
1232 /* Flags if we've processed certain parts already */
1233 int prototype_header_read = 0;
1234 int prototype_footer_read = 0;
1235 int table_header_read = 0;
1236 int table_footer_read = 0;
1237 int ophandler_header_read = 0;
1238 int ophandler_footer_read = 0;
1239 int table_body_read = 0;
1240 int ophandler_body_read = 0;
1242 printf("\n\t\tMusashi v%s 68000, 68010, 68EC020, 68020 emulator\n", g_version);
1243 printf("\t\tCopyright 1998-2000 Karl Stenerud (karl@mame.net)\n\n");
1245 /* Check if output path and source for the input file are given */
1249 strcpy(output_path, argv[1]);
1251 for(ptr = strchr(output_path, '\\'); ptr; ptr = strchr(ptr, '\\'))
1253 if(output_path[strlen(output_path)-1] != '/')
1254 strcat(output_path, "/");
1256 strcpy(g_input_filename, argv[2]);
1260 /* Open the files we need */
1261 sprintf(filename, "%s%s", output_path, FILENAME_PROTOTYPE);
1262 if((g_prototype_file = fopen(filename, "wt")) == NULL)
1263 perror_exit("Unable to create prototype file (%s)\n", filename);
1265 sprintf(filename, "%s%s", output_path, FILENAME_TABLE);
1266 if((g_table_file = fopen(filename, "wt")) == NULL)
1267 perror_exit("Unable to create table file (%s)\n", filename);
1269 sprintf(filename, "%s%s", output_path, FILENAME_OPS_AC);
1270 if((g_ops_ac_file = fopen(filename, "wt")) == NULL)
1271 perror_exit("Unable to create ops ac file (%s)\n", filename);
1273 sprintf(filename, "%s%s", output_path, FILENAME_OPS_DM);
1274 if((g_ops_dm_file = fopen(filename, "wt")) == NULL)
1275 perror_exit("Unable to create ops dm file (%s)\n", filename);
1277 sprintf(filename, "%s%s", output_path, FILENAME_OPS_NZ);
1278 if((g_ops_nz_file = fopen(filename, "wt")) == NULL)
1279 perror_exit("Unable to create ops nz file (%s)\n", filename);
1281 if((g_input_file=fopen(g_input_filename, "rt")) == NULL)
1282 perror_exit("can't open %s for input", g_input_filename);
1285 /* Get to the first section of the input file */
1287 while(strcmp(section_id, ID_INPUT_SEPARATOR) != 0)
1288 if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
1289 error_exit("Premature EOF while reading input file");
1291 /* Now process all sections */
1294 if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
1295 error_exit("Premature EOF while reading input file");
1296 if(strcmp(section_id, ID_PROTOTYPE_HEADER) == 0)
1298 if(prototype_header_read)
1299 error_exit("Duplicate prototype header");
1300 read_insert(temp_insert);
1301 fprintf(g_prototype_file, "%s\n\n", temp_insert);
1302 prototype_header_read = 1;
1304 else if(strcmp(section_id, ID_TABLE_HEADER) == 0)
1306 if(table_header_read)
1307 error_exit("Duplicate table header");
1308 read_insert(temp_insert);
1309 fprintf(g_table_file, "%s", temp_insert);
1310 table_header_read = 1;
1312 else if(strcmp(section_id, ID_OPHANDLER_HEADER) == 0)
1314 if(ophandler_header_read)
1315 error_exit("Duplicate opcode handler header");
1316 read_insert(temp_insert);
1317 fprintf(g_ops_ac_file, "%s\n\n", temp_insert);
1318 fprintf(g_ops_dm_file, "%s\n\n", temp_insert);
1319 fprintf(g_ops_nz_file, "%s\n\n", temp_insert);
1320 ophandler_header_read = 1;
1322 else if(strcmp(section_id, ID_PROTOTYPE_FOOTER) == 0)
1324 if(prototype_footer_read)
1325 error_exit("Duplicate prototype footer");
1326 read_insert(prototype_footer_insert);
1327 prototype_footer_read = 1;
1329 else if(strcmp(section_id, ID_TABLE_FOOTER) == 0)
1331 if(table_footer_read)
1332 error_exit("Duplicate table footer");
1333 read_insert(table_footer_insert);
1334 table_footer_read = 1;
1336 else if(strcmp(section_id, ID_OPHANDLER_FOOTER) == 0)
1338 if(ophandler_footer_read)
1339 error_exit("Duplicate opcode handler footer");
1340 read_insert(ophandler_footer_insert);
1341 ophandler_footer_read = 1;
1343 else if(strcmp(section_id, ID_TABLE_BODY) == 0)
1345 if(!prototype_header_read)
1346 error_exit("Table body encountered before prototype header");
1347 if(!table_header_read)
1348 error_exit("Table body encountered before table header");
1349 if(!ophandler_header_read)
1350 error_exit("Table body encountered before opcode handler header");
1353 error_exit("Duplicate table body");
1356 table_body_read = 1;
1358 else if(strcmp(section_id, ID_OPHANDLER_BODY) == 0)
1360 if(!prototype_header_read)
1361 error_exit("Opcode handlers encountered before prototype header");
1362 if(!table_header_read)
1363 error_exit("Opcode handlers encountered before table header");
1364 if(!ophandler_header_read)
1365 error_exit("Opcode handlers encountered before opcode handler header");
1366 if(!table_body_read)
1367 error_exit("Opcode handlers encountered before table body");
1369 if(ophandler_body_read)
1370 error_exit("Duplicate opcode handler section");
1372 process_opcode_handlers();
1374 ophandler_body_read = 1;
1376 else if(strcmp(section_id, ID_END) == 0)
1378 /* End of input file. Do a sanity check and then write footers */
1379 if(!prototype_header_read)
1380 error_exit("Missing prototype header");
1381 if(!prototype_footer_read)
1382 error_exit("Missing prototype footer");
1383 if(!table_header_read)
1384 error_exit("Missing table header");
1385 if(!table_footer_read)
1386 error_exit("Missing table footer");
1387 if(!table_body_read)
1388 error_exit("Missing table body");
1389 if(!ophandler_header_read)
1390 error_exit("Missing opcode handler header");
1391 if(!ophandler_footer_read)
1392 error_exit("Missing opcode handler footer");
1393 if(!ophandler_body_read)
1394 error_exit("Missing opcode handler body");
1396 print_opcode_output_table(g_table_file);
1398 fprintf(g_prototype_file, "%s\n\n", prototype_footer_insert);
1399 fprintf(g_table_file, "%s\n\n", table_footer_insert);
1400 fprintf(g_ops_ac_file, "%s\n\n", ophandler_footer_insert);
1401 fprintf(g_ops_dm_file, "%s\n\n", ophandler_footer_insert);
1402 fprintf(g_ops_nz_file, "%s\n\n", ophandler_footer_insert);
1408 error_exit("Unknown section identifier: %s", section_id);
1412 /* Close all files and exit */
1413 fclose(g_prototype_file);
1414 fclose(g_table_file);
1415 fclose(g_ops_ac_file);
1416 fclose(g_ops_dm_file);
1417 fclose(g_ops_nz_file);
1418 fclose(g_input_file);
1420 printf("Generated %d opcode handlers from %d primitives\n", g_num_functions, g_num_primitives);
1427 /* ======================================================================== */
1428 /* ============================== END OF FILE ============================= */
1429 /* ======================================================================== */