summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2019-04-14 18:54:50 +1200
committerDavid Phillips <david@sighup.nz>2019-08-03 12:43:46 +1200
commit36566268c9ead4a3d53730e66460a38a92820f3d (patch)
tree55fbb6bb3341d9a8ef068604b0db6a610732f13d
parent0b7bf68ade7a646377acbc7eb535ba1133d18475 (diff)
downloadtoy-cpu-assembler-36566268c9ead4a3d53730e66460a38a92820f3d.tar.xz
Small tidy up of headers, misc output
-rw-r--r--output.c4
-rw-r--r--parse.c4
-rw-r--r--util.h17
3 files changed, 18 insertions, 7 deletions
diff --git a/output.c b/output.c
index ff22956..2afb5fe 100644
--- a/output.c
+++ b/output.c
@@ -141,7 +141,7 @@ int output_single(FILE *f, struct label *labels, size_t labels_count, struct ins
len = generate_single_jr_type(&i, inst.inst.jr);
break;
case INST_TYPE_JI:
- if ( inst.inst.ji.imm_is_ident
+ if ( inst.inst.ji.imm_is_ident
&& look_up_label(labels, labels_count, &inst.inst.ji.imm.value, inst.inst.ji.imm.label))
return 1;
@@ -193,8 +193,6 @@ int output(FILE *fout, struct label *labels, size_t label_count, struct instruct
fprintf(fout, "v2.0 raw\n");
#endif
- printf("output: have %d instructions\n", insts_count);
-
for (i = 0; i < insts_count; i++)
if (output_single(fout, labels, label_count, insts[i]))
return 1;
diff --git a/parse.c b/parse.c
index 6ce7f67..3e9041c 100644
--- a/parse.c
+++ b/parse.c
@@ -578,10 +578,6 @@ int parse(const char *filename_local, FILE* fd_local, struct label **labels_loca
}
}
- for (i = 0; i < labels_count; i++) {
- fprintf(stderr, "Label %s: 0x%04x\n", labels[i].name, labels[i].byte_offset);
- }
-
*instructions = insts;
*instructions_count = insts_count;
diff --git a/util.h b/util.h
index 21d3d30..4225357 100644
--- a/util.h
+++ b/util.h
@@ -3,6 +3,23 @@
#include "lex.h"
+#define GENERATE_PROTO_STR_LOOKUP_FUNC(name, lookup, type) \
+const char* name(type x);
+
+#define GENERATE_PROTO_NUM_LOOKUP_FUNC(name, lookup, type) \
+int name(const char *x, type *res);
+
+GENERATE_PROTO_STR_LOOKUP_FUNC(get_asm_from_oper, oper_to_asm, enum OPER);
+GENERATE_PROTO_STR_LOOKUP_FUNC(get_asm_from_j, j_to_asm, enum JCOND);
+GENERATE_PROTO_STR_LOOKUP_FUNC(get_asm_from_b, b_to_asm, enum JCOND);
+GENERATE_PROTO_STR_LOOKUP_FUNC(get_asm_from_reg, reg_to_asm, enum REG);
+GENERATE_PROTO_STR_LOOKUP_FUNC(get_token_description, token_to_desc, enum TOKEN_TYPE);
+
+GENERATE_PROTO_NUM_LOOKUP_FUNC(get_oper_from_asm, oper_to_asm, enum OPER);
+GENERATE_PROTO_NUM_LOOKUP_FUNC(get_j_from_asm, j_to_asm, enum JCOND);
+GENERATE_PROTO_NUM_LOOKUP_FUNC(get_b_from_asm, b_to_asm, enum JCOND);
+GENERATE_PROTO_NUM_LOOKUP_FUNC(get_reg_from_asm, reg_to_asm, enum REG);
+
const char * get_token_description(enum TOKEN_TYPE t);
void indicate_file_area(FILE* fd, size_t line, size_t column, size_t span);