WIP: added FILE* for symbol and listing buffer
authorLukas Krickl <lukas@krickl.dev>
Mon, 20 Nov 2023 17:24:14 +0000 (18:24 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 20 Nov 2023 17:24:14 +0000 (18:24 +0100)
include/ulas.h
src/main.c
src/ulas.c

index 5feb5ab2ee797de40f3c483c81a91131ccb5a0c3..a1b2a9e7e3f620b5cf5e8d0b3c4ba0664afb822c 100644 (file)
@@ -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;
index bb38dee0bea1b8e388864552c48a0a55b410c867..b1e618a4a6a7fc84848cf5a69971e4d1721a2c4c 100644 (file)
@@ -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;
 }
index 451968d947fec380dc13000f7589d091702347e8..94c309b571ae8765096df3ed409c6cd678fa68f8 100644 (file)
@@ -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 <address> <bytes>\tline
-  fprintf(dst, "%08X\t%s", ulas.address, start);
+  if (ulas.symout) {
+    // TODO: verbose output <address> <bytes>\tline
+    fprintf(ulas.symout, "%08X\t%s", ulas.address, start);
+  }
 
 fail:
   return rc;