aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c13
-rw-r--r--minias.h4
-rw-r--r--parse.c9
-rw-r--r--util.c11
4 files changed, 20 insertions, 17 deletions
diff --git a/main.c b/main.c
index bc67bb6..395b5f6 100644
--- a/main.c
+++ b/main.c
@@ -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:
diff --git a/minias.h b/minias.h
index cb0bb85..c16caf0 100644
--- a/minias.h
+++ b/minias.h
@@ -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);
diff --git a/parse.c b/parse.c
index eebadde..15fcc24 100644
--- a/parse.c
+++ b/parse.c
@@ -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;
}
diff --git a/util.c b/util.c
index 9ed1c50..70a4cc0 100644
--- a/util.c
+++ b/util.c
@@ -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);