git.haldean.org x6502 / bab6f75
Revert removal of generate_debug_names.py Looks like the AWK script submitted straight-up doesn't work (serves me right for merging a pull request without testing it first). I don't know AWK, so I'm going back to the one I know. Systems that don't have Python installed can install Python. Will Haldean Brown 8 years ago
3 changed file(s) with 41 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
00 CC=clang
11 COPTS=-o x6502 -O3 -lpthread -Wall
22 DEBUGOPTS=-DDEBUG -O0 -g
3 PYTHON=python
34
45 all: release
56
6 debug-names.h: generate_debug_names opcodes.h
7 ./generate_debug_names < opcodes.h > debug-names.h
7 debug-names.h: generate_debug_names.py opcodes.h
8 $(PYTHON) generate_debug_names.py > debug-names.h
89
910 release: debug-names.h *.c *.h
1011 $(CC) $(COPTS) *.c
+0
-32
generate_debug_names less more
0 #!/bin/sh
1
2 cat <<EOF
3 // AUTOGENERATED BY $(echo $0), DO NOT MODIFY
4
5 #ifndef __6502_DEBUG_NAMES__
6 #define __6502_DEBUG_NAMES__
7
8 #include <stdint.h>
9
10 char *inst_names[0x100];
11 char names_initialized = 0;
12
13 void init_names() {
14 if (names_initialized) {
15 return;
16 }
17 names_initialized = 1;
18
19 for (int i = 0; i < 0xFF; i++) {
20 inst_names[i] = "unknown";
21 }
22 EOF
23
24 awk '/^#define (.+)[[:blank:]]+(0x[[:xdigit:]]{2})/ { printf " inst_names[%s] = \"%s\";\n", $3, $2 }'
25
26 cat <<EOF
27 }
28
29 #endif
30 EOF
31
0 #!/usr/bin/env python
1
2 def is_opcode(line):
3 return line.startswith('#define') and 'OPCODE' not in line
4
5 opcode_map = {}
6 with open('opcodes.h') as f:
7 for line in f:
8 if is_opcode(line):
9 _, op, code = line.strip().split()
10 opcode_map[code] = op
11
12 print '''
13 // AUTOGENERATED BY generate_debug_names.py, DO NOT MODIFY
14
15 #ifndef __6502_DEBUG_NAMES__
16 #define __6502_DEBUG_NAMES__
17
18 #include <stdint.h>
19
20 char *inst_names[0x100];
21 char names_initialized = 0;
22
23 void init_names() {
24 if (names_initialized) {
25 return;
26 }
27 names_initialized = 1;
28
29 for (int i = 0; i < 0xFF; i++) {
30 inst_names[i] = "unknown";
31 }
32 %s
33 }
34
35 #endif
36 ''' % '\n'.join(' inst_names[%s] = "%s";' % (code, op)
37 for code, op in opcode_map.items())