From cda87361df953b15ab2e3af3c12cabfd2a82afbf Mon Sep 17 00:00:00 2001 From: Oxore Date: Sat, 12 Aug 2023 23:08:21 +0300 Subject: Impl .short and .word directive emission --- main.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index d6b3dba..6635844 100644 --- a/main.c +++ b/main.c @@ -3022,10 +3022,13 @@ static void emit_directive_same( } for (size_t i = 0; i < dir->num_tokens; i++) { const struct token token = lex->tokbuf[dir->first_token + i]; + if (i != 0) { + fprintf(s, " "); + } if (token.type == TT_ID) { emit_token_id(lex, &token, s); } else { - fprintf(s, "%.*s ", (int)token.length, lex->input + token.offset); + fprintf(s, "%.*s", (int)token.length, lex->input + token.offset); } } } @@ -3046,7 +3049,38 @@ static void emit_directive_byte( } for (size_t i = 0; i < dir->num_tokens; i++) { const struct token token = lex->tokbuf[dir->first_token + i]; - fprintf(s, "%.*s ", (int)token.length, lex->input + token.offset); + if (i != 0) { + fprintf(s, " "); + } + if (token.type == TT_ID) { + emit_token_id(lex, &token, s); + fprintf(s, " "); + } else { + fprintf(s, "%.*s", (int)token.length, lex->input + token.offset); + } + } +} + +static void emit_directive_short( + const struct lex *const lex, + const struct directive *const dir, + FILE *const s) +{ + if (dir->num_tokens < 1) { + // We won't emit this because it is invalid + return; + } + fprintf(s, "\t.short\t"); + for (size_t i = 0; i < dir->num_tokens; i++) { + const struct token token = lex->tokbuf[dir->first_token + i]; + if (i != 0) { + fprintf(s, " "); + } + if (token.type == TT_ID) { + emit_token_id(lex, &token, s); + } else { + fprintf(s, "%.*s", (int)token.length, lex->input + token.offset); + } } } @@ -3096,7 +3130,7 @@ static int assem_emit(struct assem *const self, FILE *const stream) fprintf(stream, ".%c", opsize_to_char(opsize)); } if (instr.arg1.type != ARG_NONE) { - fprintf(stream, " "); + fprintf(stream, "\t"); emit_arg(lex, &instr.arg1, stream); if (instr.arg2.type != ARG_NONE) { fprintf(stream, ", "); @@ -3116,6 +3150,10 @@ static int assem_emit(struct assem *const self, FILE *const stream) case DT_BYTE: emit_directive_byte(lex, dir, stream); break; + case DT_SHORT: + case DT_WORD: + emit_directive_short(lex, dir, stream); + break; default: break; } -- cgit v1.2.3