From 480745b19fe8fd7e39090df41c57949e98447a7b Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Thu, 14 Dec 2023 05:50:07 +0100 Subject: [PATCH] Added basic symbol output --- include/ulas.h | 2 ++ src/test.c | 1 + src/ulas.c | 52 ++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/include/ulas.h b/include/ulas.h index 4c65f03..1b9ec11 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -460,6 +460,8 @@ struct ulas_sym *ulas_symbolresolve(const char *name, int scope, int *rc); int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, int constant); +int ulas_symbolout(FILE *dst, struct ulas_sym *s); + // tokenisze according to pre-defined rules // returns the amount of bytes of line that were // consumed or -1 on error diff --git a/src/test.c b/src/test.c index 8948322..6a19d54 100644 --- a/src/test.c +++ b/src/test.c @@ -366,6 +366,7 @@ void test_symscope(void) { { \ printf("[source: %s; expect: %s]\n", in_path, expect_path); \ ulaslstout = stdout; \ + ulassymout = stdout; \ struct ulas_config cfg = ulas_cfg_from_env(); \ cfg.verbose = 1; \ char dstbuf[ULAS_FULLEN]; \ diff --git a/src/ulas.c b/src/ulas.c index 507e0b0..09cae35 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -295,12 +295,16 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, // def new symbol struct ulas_sym new_sym = {strdup(name), tok, scope, ulas.pass, constant}; ulas_symbufpush(&ulas.syms, new_sym); + + rc = ulas_symbolout(ulassymout, &new_sym); } else if (existing->lastdefin != ulas.pass || !existing->constant) { // redefine if not defined this pass existing->lastdefin = ulas.pass; ulas_tokfree(&existing->tok); existing->tok = tok; existing->constant = constant; + + rc = ulas_symbolout(ulassymout, existing); } else { // exists.. cannot have duplicates! rc = -1; @@ -309,6 +313,29 @@ int ulas_symbolset(const char *cname, int scope, struct ulas_tok tok, return rc; } +int ulas_symbolout(FILE *dst, struct ulas_sym *s) { + if (!dst || ulas.pass != ULAS_PASS_FINAL) { + return 0; + } + + int rc = 0; + fprintf(dst, "%s\t\t= ", s->name); + switch (s->tok.type) { + case ULAS_INT: + fprintf(dst, "%d", ulas_valint(&s->tok, &rc)); + break; + case ULAS_STR: + fprintf(dst, "%s", ulas_valstr(&s->tok, &rc)); + break; + default: + fprintf(dst, ""); + break; + } + fprintf(dst, "\n"); + + return rc; +} + #define WELD_TOKISTERM write #define WELD_TOKCOND (i < n && write < n && line[i]) @@ -2400,8 +2427,7 @@ int ulas_asmdirincbin(FILE *dst, const char **line, unsigned long n, int *rc) { } int ulas_asmdiradv(FILE *dst, const char **line, unsigned long n, int *rc) { - ULAS_EVALEXPRS(ulas.address += - ulas_intexpr(line, strnlen(*line, n), rc)); + ULAS_EVALEXPRS(ulas.address += ulas_intexpr(line, strnlen(*line, n), rc)); return 0; } @@ -2439,15 +2465,21 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { } if (ulas.tok.buf[0] == ULAS_TOK_ASMDIR_BEGIN) { - const char *dirstrs[] = {ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET, - ULAS_ASMSTR_BYTE, ULAS_ASMSTR_STR, - ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD, - ULAS_ASMSTR_INCBIN, ULAS_ASMSTR_DEF, - ULAS_ASMSTR_CHKSM, ULAS_ASMSTR_ADV, NULL}; + const char *dirstrs[] = {ULAS_ASMSTR_ORG, + ULAS_ASMSTR_SET, + ULAS_ASMSTR_BYTE, + ULAS_ASMSTR_STR, + ULAS_ASMSTR_FILL, + ULAS_ASMSTR_PAD, + ULAS_ASMSTR_INCBIN, + ULAS_ASMSTR_DEF, + ULAS_ASMSTR_CHKSM, + ULAS_ASMSTR_ADV, + NULL}; enum ulas_asmdir dirs[] = { - ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, - ULAS_ASMDIR_STR, ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD, - ULAS_ASMDIR_INCBIN, ULAS_ASMDIR_DEF, ULAS_ASMDIR_CHKSM, ULAS_ASMDIR_ADV}; + ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, ULAS_ASMDIR_STR, + ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD, ULAS_ASMDIR_INCBIN, ULAS_ASMDIR_DEF, + ULAS_ASMDIR_CHKSM, ULAS_ASMDIR_ADV}; enum ulas_asmdir dir = ULAS_ASMDIR_NONE; -- 2.30.2