From 36566268c9ead4a3d53730e66460a38a92820f3d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 14 Apr 2019 18:54:50 +1200 Subject: Small tidy up of headers, misc output --- output.c | 4 +--- parse.c | 4 ---- util.h | 17 +++++++++++++++++ 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); -- cgit v1.1