diff options
author | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-03-30 12:04:43 -0400 |
---|---|---|
committer | Quentin Carbonneaux <quentin.carbonneaux@yale.edu> | 2016-03-31 09:15:50 -0400 |
commit | 729aa97b799f72afdec3604f96526760701f36bc (patch) | |
tree | 35761b52e15fe48abe779a07766852717e4e9d6c /util.c | |
parent | beec05cd3b6c85af3f3cc8956f4583d9027d569d (diff) | |
download | roux-729aa97b799f72afdec3604f96526760701f36bc.tar.gz |
cleanup error handling
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/util.c b/util.c index 65b3ff8..1654491 100644 --- a/util.c +++ b/util.c @@ -1,4 +1,5 @@ #include "all.h" +#include <stdarg.h> typedef struct Bitset Bitset; typedef struct Vec Vec; @@ -28,9 +29,14 @@ static void **pool = ptr; static int nptr = 1; void -diag(char *s) +die_(char *file, char *s, ...) { - fputs(s, stderr); + va_list ap; + + fprintf(stderr, "%s: dying: ", file); + va_start(ap, s); + vfprintf(stderr, s, ap); + va_end(ap); fputc('\n', stderr); abort(); } @@ -42,7 +48,7 @@ emalloc(size_t n) p = calloc(1, n); if (!p) - diag("emalloc: out of memory"); + die("emalloc, out of memory"); return p; } @@ -95,7 +101,7 @@ void emit(int op, int k, Ref to, Ref arg0, Ref arg1) { if (curi == insb) - diag("emit: too many instructions"); + die("emit, too many instructions"); *--curi = (Ins){ .op = op, .cls = k, .to = to, .arg = {arg0, arg1} @@ -210,8 +216,7 @@ addcon(Con *c0, Con *c1) *c0 = *c1; else { if (c1->type == CAddr) { - if (c0->type == CAddr) - diag("addcon: adding two addresses"); + assert(c0->type != CAddr && "adding two addresses"); c0->type = CAddr; strcpy(c0->label, c1->label); } |