aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <[email protected]>2016-03-30 12:04:43 -0400
committerQuentin Carbonneaux <[email protected]>2016-03-31 09:15:50 -0400
commit729aa97b799f72afdec3604f96526760701f36bc (patch)
tree35761b52e15fe48abe779a07766852717e4e9d6c /util.c
parentbeec05cd3b6c85af3f3cc8956f4583d9027d569d (diff)
cleanup error handling
Diffstat (limited to 'util.c')
-rw-r--r--util.c17
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);
}