summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2023-08-12 21:03:57 +0300
committerOxore <oxore@protonmail.com>2023-08-12 21:18:23 +0300
commitd30df7b755345fdffa8025511275a27b100c69d6 (patch)
treeecf18c32582219d8de224992e6320a74eb30b62c
parent3e584a3df6bede3ae545ae530c619ba6eecc97c9 (diff)
Impl globl, align, text and file directive emission
-rw-r--r--main.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/main.c b/main.c
index f6b9560..5e07ac0 100644
--- a/main.c
+++ b/main.c
@@ -19,7 +19,7 @@
#endif
#ifndef TRACE_PARSER
-#define TRACE_PARSER 1
+#define TRACE_PARSER 0
#endif
#if defined(__GNUC__) || defined(__clang__)
@@ -2947,6 +2947,22 @@ static void emit_arg(
}
}
+static void emit_directive_same(
+ const struct lex *const lex,
+ const struct directive *const dir,
+ FILE *const s)
+{
+ const struct token name_token = lex->tokbuf[dir->name_token];
+ fprintf(s, "\t%.*s", (int)name_token.length, lex->input + name_token.offset);
+ if (dir->num_tokens) {
+ fprintf(s, "\t");
+ }
+ 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);
+ }
+}
+
static int assem_emit(struct assem *const self, FILE *const stream)
{
const struct lex *const lex = self->pars->lex;
@@ -2978,6 +2994,18 @@ static int assem_emit(struct assem *const self, FILE *const stream)
emit_arg(lex, &instr.arg2, stream);
}
}
+ } else if (stmt->type == ST_DIRECTIVE) {
+ const struct directive *dir = &stmt->directive;
+ switch (dir->type) {
+ case DT_ALIGN:
+ case DT_FILE:
+ case DT_GLOBL:
+ case DT_TEXT:
+ emit_directive_same(lex, dir, stream);
+ break;
+ default:
+ break;
+ }
}
if (stmt->comment_token) {
const struct token token = lex->tokbuf[stmt->comment_token];