From: Lukas Krickl Date: Mon, 20 Nov 2023 17:24:14 +0000 (+0100) Subject: WIP: added FILE* for symbol and listing buffer X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=814ca6d105e598dec9228fb5e3b6261d53006445;p=ulas%2F.git WIP: added FILE* for symbol and listing buffer --- diff --git a/include/ulas.h b/include/ulas.h index 5feb5ab..a1b2a9e 100644 --- a/include/ulas.h +++ b/include/ulas.h @@ -74,6 +74,8 @@ struct ulas_config { int argc; char *output_path; + char *lst_path; + char *sym_path; int verbose; int preproc_only; @@ -149,8 +151,8 @@ struct ulas { // used whenever a new unique number might be needed int icntr; - FILE *verbout; - FILE *symsout; + FILE *lstout; + FILE *symout; }; extern struct ulas ulas; diff --git a/src/main.c b/src/main.c index bb38dee..b1e618a 100644 --- a/src/main.c +++ b/src/main.c @@ -12,7 +12,7 @@ #define ULAS_OPTS "hvVp" // args with value -#define ULAS_OPTS_ARG "o:" +#define ULAS_OPTS_ARG "o:l:s:" #define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc); @@ -24,6 +24,8 @@ void ulas_help(void) { ULAS_HELP("v", "verbose output"); ULAS_HELP("p", "Stop after preprocessor"); ULAS_HELP("o=path", "Output file"); + ULAS_HELP("l=path", "Listing file"); + ULAS_HELP("s=path", "Symbols file"); } void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); } @@ -49,6 +51,12 @@ void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) { case 'p': cfg->preproc_only = 1; break; + case 's': + cfg->sym_path = strndup(optarg, ULAS_PATHMAX); + break; + case 'l': + cfg->sym_path = strndup(optarg, ULAS_PATHMAX); + break; case '?': break; default: @@ -75,5 +83,13 @@ int main(int argc, char **argv) { free(cfg.output_path); } + if (cfg.sym_path) { + free(cfg.sym_path); + } + + if (cfg.lst_path) { + free(cfg.lst_path); + } + return res; } diff --git a/src/ulas.c b/src/ulas.c index 451968d..94c309b 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -35,6 +35,7 @@ void ulas_init(struct ulas_config cfg) { ulas.toks = ulas_tokbuf(); ulas.exprs = ulas_exprbuf(); + ulas.symout = stdout; } void ulas_free(void) { @@ -98,6 +99,16 @@ cleanup: fclose(ulasout); } + if (cfg.sym_path) { + fclose(ulas.symout); + ulas.symout = NULL; + } + + if (cfg.lst_path) { + fclose(ulas.lstout); + ulas.lstout = NULL; + } + if (cfg.argc > 0) { fclose(ulasin); } @@ -1303,7 +1314,10 @@ int ulas_intexpr(const char **line, unsigned long n, int *rc) { return ulas_intexpreval(expr, rc); } -int ulas_asmimisc(FILE *dst, const char *line, unsigned long n) {} +int ulas_asmimisc(char *dst, unsigned long max, const char *line, + unsigned long n) { + return 0; +} // assembles an instruction, writes bytes into dst // returns bytes written or -1 on error @@ -1311,12 +1325,15 @@ int ulas_asminstr(char *dst, unsigned long max, const char *line, unsigned long n) { int rc = 0; + if ((rc = ulas_asmimisc(dst, max, line, n))) { + } + return rc; } int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { // this buffer is written both to dst and to verbose output - char *outbuf[ULAS_OUTBUFMAX]; + char outbuf[ULAS_OUTBUFMAX]; memset(outbuf, 0, ULAS_OUTBUFMAX); long towrite = 0; @@ -1379,8 +1396,10 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { fwrite(outbuf, 1, towrite, dst); - // TODO: verbose output
\tline - fprintf(dst, "%08X\t%s", ulas.address, start); + if (ulas.symout) { + // TODO: verbose output
\tline + fprintf(ulas.symout, "%08X\t%s", ulas.address, start); + } fail: return rc;