aboutsummaryrefslogtreecommitdiff
path: root/src/prc1/warn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/prc1/warn.c')
-rw-r--r--src/prc1/warn.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/prc1/warn.c b/src/prc1/warn.c
index 93635db..9fb535e 100644
--- a/src/prc1/warn.c
+++ b/src/prc1/warn.c
@@ -1,6 +1,7 @@
#include "warn.h"
#include "cgen.h"
#include "dbg.h"
+#include "fn.h"
#include "parse.h"
#include "prv.h"
#include "stmt.h"
@@ -9,6 +10,8 @@
#include <stdlib.h>
#include <string.h>
+#if 0
+
static int finalize(const struct lex *l, const struct prv *p,
const struct print *pr)
{
@@ -30,7 +33,7 @@ static int finalize(const struct lex *l, const struct prv *p,
.u.warn.p = *pr
};
- dbg("\t\tadding warn statement with %zu entries%s\n", pr->nentries,
+ dbg("\t\tadd warn statement with %zu entries%s\n", pr->nentries,
pr->println ? "" : ", no lf");
return 0;
}
@@ -135,13 +138,27 @@ int warn_cgen(const struct warn *w, struct cgen *c)
return 0;
}
+#endif
-void warn_free(struct warn *w)
+int warn_cgen(const struct print *pr, struct cgen *c)
{
- print_free(&w->p);
+ return print_cgen(pr, c, "stderr");
}
int warn(const struct lex *l, struct prv *p)
{
- return print(l, p, finalize);
+ struct fn *fn = fn_cur(p);
+ size_t n = fn->nstmts + 1;
+ struct stmt *stmts = realloc(fn->stmts, n * sizeof *stmts);
+
+ if (!stmts)
+ {
+ perror("realloc(3)");
+ return -1;
+ }
+
+ dbg("\t\tadd warn statement\n");
+ stmts[fn->nstmts++] = (struct stmt){.type = WARN, .u.print = {0}};
+ fn->stmts = stmts;
+ return print(l, p);
}