From 98aa213f41bee062529abb987eadab56219e8bb5 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Sun, 12 Jul 2020 06:19:38 -0700 Subject: [PATCH] ainedit: fix bugs identified in #2 Treat CR characters as whitespace and remove redundant/buggy string hash table from asm.c. --- src/tools/ainedit/asm.c | 32 ++------------------------------ src/tools/ainedit/asm_lexer.l | 2 +- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/src/tools/ainedit/asm.c b/src/tools/ainedit/asm.c index 0a970e2..ef5ca91 100644 --- a/src/tools/ainedit/asm.c +++ b/src/tools/ainedit/asm.c @@ -109,7 +109,6 @@ struct asm_state { int32_t func; int32_t func_stack[ASM_FUNC_STACK_SIZE]; int32_t lib; - struct hash_table *str_ht; }; const_pure int32_t asm_instruction_width(int opcode) @@ -126,22 +125,6 @@ static void init_asm_state(struct asm_state *state, struct ain *ain, uint32_t fl state->flags = flags; state->func = -1; state->lib = -1; - state->str_ht = ht_create(4096); - - for (intptr_t i = 0; i < ain->nr_strings; i++) { - struct ht_slot *p = ht_put(state->str_ht, ain->strings[i]->text); - if (p->value) { - char *u = encode_text_for_print(ain->strings[i]->text); - WARNING("Duplicate string in ain file: \"%s\"", u); - free(u); - } - p->value = (void*)(i+1); - } -} - -static void fini_asm_state(struct asm_state *state) -{ - ht_free(state->str_ht); } static void asm_write_opcode(struct asm_state *state, uint16_t opcode) @@ -253,18 +236,9 @@ static void realloc_message_table(struct ain *ain, int i) static int asm_add_string(struct asm_state *state, const char *str) { char *sjis = encode_text(str); - struct ht_slot *p = ht_put(state->str_ht, sjis); - if (p->value) { - free(sjis); - return (intptr_t)p->value - 1; - } - - int i = state->ain->nr_strings; - realloc_string_table(state->ain, i); - state->ain->strings[i] = make_string(sjis, strlen(sjis)); - p->key = state->ain->strings[i]->text; + int no = ain_add_string(state->ain, sjis); free(sjis); - return i; + return no; } static uint32_t asm_resolve_arg(struct asm_state *state, enum opcode opcode, enum instruction_argtype type, const char *arg) @@ -941,6 +915,4 @@ void asm_assemble_jam(const char *filename, struct ain *ain, uint32_t flags) ain->code_size = state.buf_ptr; validate_ain(ain); - - fini_asm_state(&state); } diff --git a/src/tools/ainedit/asm_lexer.l b/src/tools/ainedit/asm_lexer.l index 1267a51..261de41 100644 --- a/src/tools/ainedit/asm_lexer.l +++ b/src/tools/ainedit/asm_lexer.l @@ -42,7 +42,7 @@ id_char [^ \t\r\n:;\"] %% -[ \t] ; +[ \t\r] ; ;[^\n]*\n asm_line++; return NEWLINE; \n asm_line++; return NEWLINE; [a-zA-Z0-9_-]+: asm_lval.string = make_string(asm_text, asm_leng-1); return LABEL;