#define assert_preproc(expect_dst, expect_ret, input) \
{ \
+ ulas.pass = ULAS_PASS_RESOLVE; \
char dstbuf[ULAS_LINEMAX]; \
memset(dstbuf, 0, ULAS_LINEMAX); \
FILE *src = fmemopen((input), strlen((input)), "re"); \
printf("[source: %s; expect: %s]\n", in_path, expect_path); \
ulaslstout = stdout; \
struct ulas_config cfg = ulas_cfg_from_env(); \
+ cfg.verbose = 1; \
char dstbuf[ULAS_FULLEN]; \
char expect[ULAS_FULLEN]; \
FILE *expectf = fopen(expect_path, "re"); \
if (cfg.argc) {
ulas.filename = cfg.argv[0];
+ ulas.initial_filename = cfg.argv[0];
}
+ ulas.pass = ULAS_PASS_FINAL;
ulas.toks = ulas_tokbuf();
ulas.exprs = ulas_exprbuf();
ulas.syms = ulas_symbuf();
}
-void ulas_nextpass(void) { ulas.scope = 0; }
+void ulas_nextpass(void) {
+ ulas.scope = 0;
+ ulas.line = 0;
+ ulas.icntr = 0;
+ ulas.address = 0;
+ ulas.filename = ulas.initial_filename;
+}
void ulas_free(void) {
ulas_strfree(&ulas.tok);
preprocdst = tmpfile();
}
- if (ulas_preproc(preprocdst, ulasin) == -1) {
- rc = -1;
- goto cleanup;
+ ulas.pass = ULAS_PASS_RESOLVE;
+ while (ulas.pass > 0) {
+ ulas_nextpass();
+
+ if (ulascfg.verbose) {
+ fprintf(ulaserr, "[Pass %d]\n", ulas.pass);
+ }
+
+ if (ulas_preproc(preprocdst, ulasin) == -1) {
+ rc = -1;
+ goto cleanup;
+ }
+
+ ulas.pass -= 1;
}
if (cfg.preproc_only) {
// init
struct ulas_preproc pp = ulas_preprocinit();
- ulas_nextpass();
-
- long prevseek = 0;
+ long prevseek = ftell(asmsrc);
// preproc
while ((rc = ulas_preprocnext(&pp, dst, src, buf, ULAS_LINEMAX)) > 0) {
if (ulascfg.preproc_only) {
}
void ulas_asmlst(const char *line, const char *outbuf, unsigned long n) {
- if (ulaslstout) {
+ // only write to dst on final pass
+ if (ulaslstout && ulas.pass == ULAS_PASS_FINAL) {
fprintf(ulaslstout, "%08X", ulas.address);
// always pad at least n bytes
}
void ulas_asmout(FILE *dst, const char *outbuf, unsigned long n) {
- fwrite(outbuf, 1, n, dst);
+ // only write to dst on final pass
+ if (ulas.pass == ULAS_PASS_FINAL) {
+ fwrite(outbuf, 1, n, dst);
+ }
}
int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) {
}
}
- // only write to dst on final pass
- if (ulas.pass == ULAS_PASS_FINAL) {
- ulas_asmout(dst, outbuf, towrite);
- ulas_asmlst(start, outbuf, towrite);
- }
+ ulas_asmout(dst, outbuf, towrite);
+ ulas_asmlst(start, outbuf, towrite);
+
ulas.address += towrite;
fail: