WIP: added starting point for disassembly step
authorLukas Krickl <lukas@krickl.dev>
Mon, 19 Feb 2024 17:54:36 +0000 (18:54 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 19 Feb 2024 17:54:36 +0000 (18:54 +0100)
makefile
src/main.c
src/ulas.c
src/ulas.h
src/uldas.c [new file with mode: 0644]
src/uldas.h [new file with mode: 0644]

index 2a57102b1da92eaed8f1ffb50d9a6e3f87b91853..7703521b501766e6020d82bf82d89ce88655e8cd 100644 (file)
--- 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
index 996e8a6830bccbc39ac6a410f0902d7f79faf347..b346ffb3951b7cde735f0feb1773b3847393c68f 100644 (file)
@@ -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:
index 3605d49bf2a81171e9c2dc6157303de8fee6786e..0211b7616cee9cd026e18e1cd008d126f817c67a 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <assert.h>
 #include <sys/time.h>
+#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:
index 747c5e1ea3352dd74cf3c542d2168631e19bc298..29c28c295ecc769fd83b1f7893688f76a68196d1 100644 (file)
@@ -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 (file)
index 0000000..0472ff4
--- /dev/null
@@ -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 (file)
index 0000000..0e9ed00
--- /dev/null
@@ -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