WIP: asm step
authorLukas Krickl <lukas@krickl.dev>
Mon, 13 Nov 2023 13:14:02 +0000 (14:14 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 13 Nov 2023 13:14:02 +0000 (14:14 +0100)
include/ulas.h
src/ulas.c

index b1df17707f7201e079669d50e42a5ac6edf88b6b..d5d41784459fb4b713dba40cbbd1ec3d3a9a14d1 100644 (file)
@@ -291,9 +291,13 @@ char *ulas_preprocexpand(struct ulas_preproc *pp, const char *raw_line,
                          size_t *n);
 
 /**
- * Assembly step 
+ * Assembly step
  */
 
+// returns 0 if no more data can be read
+//         > 0 if data was read
+//         -1 on error
+int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n);
 int ulas_asm(FILE *dst, FILE *src);
 
 #endif
index 8aca72d9d1bf7551e3e2f405a68680c674568460..630b472bc640e9a60b21383fde3524c58e230f1b 100644 (file)
@@ -689,8 +689,35 @@ int ulas_preproc(FILE *dst, FILE *src) {
  * Assembly step
  */
 
+int ulas_asmnext(FILE *dst, FILE *src, char *buf, int n) {
+  int rc = 1;
+  if (fgets(buf, n, src) != NULL) {
+    ulas.line++;
+
+    fprintf(dst, "%s", buf);
+    // size_t buflen = strlen(buf);
+  } else {
+    rc = 0;
+  }
+  return rc;
+}
+
 int ulas_asm(FILE *dst, FILE *src) {
+  char buf[ULAS_LINEMAX];
+  memset(buf, 0, ULAS_LINEMAX);
   int rc = 0;
 
+  // init
+  struct ulas_preproc pp = ulas_preprocinit();
+
+  // preproc
+  while ((rc = ulas_asmnext(dst, src, buf, ULAS_LINEMAX)) > 0) {
+  }
+
+  // cleanup
+  ulas_preprocfree(&pp);
+
+  return rc;
+
   return rc;
 }