WIP: pass-system for disas calls
authorLukas Krickl <lukas@krickl.dev>
Thu, 22 Feb 2024 05:43:46 +0000 (06:43 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 22 Feb 2024 05:43:46 +0000 (06:43 +0100)
src/ulas.c
src/uldas.c

index d6ac609c2fcaf01108187a7db3a76652a275a971..ef62a7bf8f990a018c6e3f3385e8cbf514de3587 100644 (file)
@@ -171,42 +171,45 @@ int ulas_main(struct ulas_config cfg) {
   }
   FILE *preprocdst = NULL;
 
-  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;
-    }
+  // 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;
+  }
 
-    while (ulas.pass >= 0) {
-      if (ulascfg.verbose) {
-        fprintf(ulaserr, "[Pass %d]\n", ulas.pass);
-      }
+  while (ulas.pass >= 0) {
+    if (ulascfg.verbose) {
+      fprintf(ulaserr, "[Pass %d]\n", ulas.pass);
+    }
 
-      ulas_nextpass();
+    ulas_nextpass();
 
-      // 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();
-      }
+    // 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 (!ulascfg.disas) {
       if (ulas_preproc(preprocdst, ulasin) == -1) {
         rc = -1;
         goto cleanup;
       }
-
-      if (ulas.pass > ULAS_PASS_FINAL) {
-        fclose(preprocdst);
-        preprocdst = NULL;
-        rewind(ulasin);
+    } else {
+      if (ulas_dasm(ulasin, ulasout) == -1) {
+        rc = -1;
+        goto cleanup;
       }
-      ulas.pass -= 1;
     }
-  } else {
-    rc = ulas_dasm(ulasin, ulasout);
+
+    if (ulas.pass > ULAS_PASS_FINAL) {
+      fclose(preprocdst);
+      preprocdst = NULL;
+      rewind(ulasin);
+    }
+    ulas.pass -= 1;
   }
 
 cleanup:
index 0472ff42bf2815e023acc4b09a8d0c2d6ed270f6..5202b1b119fbac89c0d79d06313b7f7592a7d23a 100644 (file)
@@ -1,5 +1,8 @@
 #include "uldas.h"
 
 int ulas_dasm(FILE *src, FILE *dst) {
+  // pass 1: run and collect labels 
+  // pass 2: run and output to file
+
   return 0;
 }