summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-08-01 02:18:41 +1200
committerDavid Phillips <david@sighup.nz>2018-08-01 02:18:41 +1200
commit70c76b708308c72956e83163b2819be69f725a7e (patch)
tree6faa1532b641104a84207caa342617f52c8f5a06
parent74808af82e455a944e689ba53945ebd8485d4f4f (diff)
downloadhence-70c76b708308c72956e83163b2819be69f725a7e.tar.xz
Change emit to be general, add filename to output
-rw-r--r--parser.c21
-rw-r--r--parser.h2
-rw-r--r--simulator.c2
3 files changed, 11 insertions, 14 deletions
diff --git a/parser.c b/parser.c
index 987f26d..618df1a 100644
--- a/parser.c
+++ b/parser.c
@@ -12,15 +12,11 @@
static FILE* fd;
static struct token *cursor;
+static const char *filename;
-#ifdef emit_error
-#warning "Remember to remove the global emit_error"
-#undef emit_error
-#endif /* ifdef emit_error */
-
-#define emit_error(...) fprintf(stderr, "Error (%zd,%zd): ", cursor->loc.line, cursor->loc.column);\
- fprintf(stderr, __VA_ARGS__);\
- indicate_file_area(fd, cursor->loc.line, cursor->loc.column, cursor->span)
+#define emit(...) fprintf(stderr, "%s at (%zd,%zd): ", filename, cursor->loc.line, cursor->loc.column);\
+ fprintf(stderr, __VA_ARGS__);\
+ indicate_file_area(fd, cursor->loc.line, cursor->loc.column, cursor->span)
//static struct op_lookup uop_handlers[] = {
@@ -49,7 +45,7 @@ expect(enum TOKEN_TYPE e) {
if (cursor->type != e) {
expected_desc = get_token_description(e);
observed_desc = get_token_description(cursor->type);
- emit_error("Expected %s, got %s\n", expected_desc, observed_desc);
+ emit("Error: Expected %s, got %s\n", expected_desc, observed_desc);
return 1;
}
@@ -62,9 +58,10 @@ kerchunk() {
}
int
-parse(FILE *f, struct token *t) {
+parse(const char *fname, FILE *f, struct token *t) {
char *token_desc = "(internal error)";
fd = f;
+ filename = fname;
cursor = t;
if (expect(TOK_MODULE)) {
@@ -75,7 +72,7 @@ parse(FILE *f, struct token *t) {
if (expect(TOK_IDENT)) {
return 1;
}
- emit_error("Debug: module is named %s\n", cursor->value);
+ emit("Debug: module is named %s\n", cursor->value);
kerchunk();
if (expect(TOK_EOL)) {
@@ -91,7 +88,7 @@ parse(FILE *f, struct token *t) {
/* FIXME implement everything */
default:
token_desc = get_token_description(cursor->type);
- emit_error("Unexpected %s\n", token_desc);
+ emit("Error: Unexpected %s\n", token_desc);
return 1;
}
}
diff --git a/parser.h b/parser.h
index 1446650..6e28dbf 100644
--- a/parser.h
+++ b/parser.h
@@ -1 +1 @@
-int parse(FILE*, struct token *);
+int parse(const char*, FILE*, struct token *);
diff --git a/simulator.c b/simulator.c
index bbea893..1b33aec 100644
--- a/simulator.c
+++ b/simulator.c
@@ -24,7 +24,7 @@ int main(int argc, char **argv) {
}
struct token *tok = lex_file(fd);
- int p = parse(fd, tok);
+ int p = parse(argv[1], fd, tok);
// gate_set_input("a", LOGIC_LOW);
// gate_set_input("b", LOGIC_LOW);