From: Lukas Krickl Date: Mon, 19 Feb 2024 17:54:36 +0000 (+0100) Subject: WIP: added starting point for disassembly step X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=93dee6ce9846d5eded25e267be594fe21b366c7d;p=ulas%2F.git WIP: added starting point for disassembly step --- diff --git a/makefile b/makefile index 2a57102..7703521 100644 --- a/makefile +++ b/makefile @@ -22,7 +22,7 @@ TEST_BNAME=testulas BIN_INSTALL_DIR=/usr/local/bin MAN_INSTALL_DIR=/usr/local/man -_OBJ = $(MAIN) ulas.o archs.o +_OBJ = $(MAIN) ulas.o archs.o uldas.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) all: bin test diff --git a/src/main.c b/src/main.c index 996e8a6..b346ffb 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ #define ULAS_VER "0.0.1" // args without value -#define ULAS_OPTS "hvVp" +#define ULAS_OPTS "hvVpd" // args with value #define ULAS_OPTS_ARG "o:l:s:i:w:" @@ -43,6 +43,7 @@ void ulas_help(void) { ULAS_HELP("l=path", "Listing file"); ULAS_HELP("s=path", "Symbols file"); ULAS_HELP("i=path", "Add include search path"); + ULAS_HELP("d", "Disassemble a file"); ULAS_HELP("w=warning", "Toggle warnings: a=all, o=overflow"); } @@ -86,6 +87,9 @@ void ulas_getopt(int argc, char **argv, struct ulas_config *cfg) { case 'w': cfg->warn_level ^= warnings[(int)optarg[0]]; break; + case 'd': + cfg->disas = 1; + break; case '?': break; default: diff --git a/src/ulas.c b/src/ulas.c index 3605d49..0211b76 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -5,6 +5,7 @@ #include #include #include +#include "uldas.h" FILE *ulasin = NULL; FILE *ulasout = NULL; @@ -168,40 +169,44 @@ int ulas_main(struct ulas_config cfg) { ULASDBG("input: %s\n", cfg.argv[0]); ulasin = ulas_fopen(cfg.argv[0], "re", stdin); } - - // only do 2 pass if we have a file as input - // because we cannot really rewind stdout - if (!cfg.preproc_only && ulasin != stdin) { - ulas.pass = ULAS_PASS_RESOLVE; - } - FILE *preprocdst = NULL; - while (ulas.pass >= 0) { - if (ulascfg.verbose) { - fprintf(ulaserr, "[Pass %d]\n", ulas.pass); + + if (!ulascfg.disas) { + // only do 2 pass if we have a file as input + // because we cannot really rewind stdout + if (!cfg.preproc_only && ulasin != stdin) { + ulas.pass = ULAS_PASS_RESOLVE; } - ulas_nextpass(); + while (ulas.pass >= 0) { + if (ulascfg.verbose) { + fprintf(ulaserr, "[Pass %d]\n", ulas.pass); + } - // FIXME: it would be nice if we could do the 2 pass by clearing the - // tmpfile instead of making an entierly new one - if (cfg.preproc_only) { - preprocdst = ulasout; - } else { - preprocdst = tmpfile(); - } + ulas_nextpass(); - if (ulas_preproc(preprocdst, ulasin) == -1) { - rc = -1; - goto cleanup; - } + // FIXME: it would be nice if we could do the 2 pass by clearing the + // tmpfile instead of making an entierly new one + if (cfg.preproc_only) { + preprocdst = ulasout; + } else { + preprocdst = tmpfile(); + } - if (ulas.pass > ULAS_PASS_FINAL) { - fclose(preprocdst); - preprocdst = NULL; - rewind(ulasin); + if (ulas_preproc(preprocdst, ulasin) == -1) { + rc = -1; + goto cleanup; + } + + if (ulas.pass > ULAS_PASS_FINAL) { + fclose(preprocdst); + preprocdst = NULL; + rewind(ulasin); + } + ulas.pass -= 1; } - ulas.pass -= 1; + } else { + rc = ulas_dasm(ulasin, ulasout); } cleanup: diff --git a/src/ulas.h b/src/ulas.h index 747c5e1..29c28c2 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -130,6 +130,7 @@ struct ulas_config { int verbose; int preproc_only; + int disas; // all include search paths char **incpaths; diff --git a/src/uldas.c b/src/uldas.c new file mode 100644 index 0000000..0472ff4 --- /dev/null +++ b/src/uldas.c @@ -0,0 +1,5 @@ +#include "uldas.h" + +int ulas_dasm(FILE *src, FILE *dst) { + return 0; +} diff --git a/src/uldas.h b/src/uldas.h new file mode 100644 index 0000000..0e9ed00 --- /dev/null +++ b/src/uldas.h @@ -0,0 +1,13 @@ +#ifndef ULDAS_H_ +#define ULDAS_H_ + +/** + * Disassembly module + */ +#include "ulas.h" +#include "archs.h" + +// Disassemble a file based on the current arch +int ulas_dasm(FILE *src, FILE *dst); + +#endif