diff options
| -rw-r--r-- | main.c | 13 | ||||
| -rw-r--r-- | minias.h | 4 | ||||
| -rw-r--r-- | parse.c | 9 | ||||
| -rw-r--r-- | util.c | 11 |
4 files changed, 20 insertions, 17 deletions
@@ -27,8 +27,18 @@ static Section *data = NULL; static Section *textrel = NULL; static Section *datarel = NULL; +char *filename = "<stdin>"; size_t curlineno = 0; +void lfatal(const char *fmt, ...) { + va_list ap; + fprintf(stderr, "%s:%ld: ", filename, curlineno); + va_start(ap, fmt); + vwarn(fmt, ap); + va_end(ap); + exit(1); +} + static Symbol *getsym(const char *name) { Symbol **ps, *s; struct hashtablekey htk; @@ -639,6 +649,9 @@ static void assemble(void) { curlineno++; v = l->v; switch (v->kind) { + case ASM_SYNTAX_ERROR: + lfatal("syntax error"); + break; case ASM_BLANK: break; case ASM_DIR_GLOBL: @@ -329,8 +329,6 @@ union Parsev { int64_t i64; }; -extern size_t curlineno; - /* parse.c */ typedef struct AsmLine AsmLine; @@ -344,7 +342,7 @@ AsmLine *parse(void); /* util.c */ -void lfatal(const char *fmt, ...); +void vwarn(const char *fmt, va_list ap); void fatal(const char *fmt, ...); void unreachable(void); @@ -120,13 +120,10 @@ AsmLine *parse(void) { yycontext ctx; memset(&ctx, 0, sizeof(yycontext)); + result = NULL; prevl = NULL; - curlineno = 0; while (yyparse(&ctx)) { - curlineno += 1; - if (ctx.v.kind == ASM_SYNTAX_ERROR) - lfatal("syntax error\n"); l = zalloc(sizeof(AsmLine)); l->v = internparsev(&ctx.v); if (prevl) @@ -135,5 +132,9 @@ AsmLine *parse(void) { result = l; prevl = l; } + + if (!result) + fatal("io error"); + return result; } @@ -1,6 +1,6 @@ #include "minias.h" -static void vwarn(const char *fmt, va_list ap) { +void vwarn(const char *fmt, va_list ap) { vfprintf(stderr, fmt, ap); if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { putc(' ', stderr); @@ -10,15 +10,6 @@ static void vwarn(const char *fmt, va_list ap) { } } -void lfatal(const char *fmt, ...) { - va_list ap; - fprintf(stderr, "%ld: ", curlineno); - va_start(ap, fmt); - vwarn(fmt, ap); - va_end(ap); - exit(1); -} - void fatal(const char *fmt, ...) { va_list ap; va_start(ap, fmt); |
