summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-08-12 23:08:21 +0300
committerOxore <oxore@protonmail.com>2023-08-12 23:08:21 +0300
commitcda87361df953b15ab2e3af3c12cabfd2a82afbf (patch)
tree6fec34bb11ac8ef165657fca9a19cbf78e214961
parentb63c89c477adeb6a0f065938ef4c164ebb6676ba (diff)
Impl .short and .word directive emission
-rw-r--r--main.c44
1 files 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;
}