aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-05 09:32:17 +0200
committerlemon <lsof@mailbox.org>2023-06-05 09:32:17 +0200
commitefc0cf8039cbff5e0f0d52fd7414c7186129b6ac (patch)
tree27aabd39ebe1c778f052edaf7088eded379f0108
parent6ce2ac20e1d9095281a233aeb778d0fa2c82dd74 (diff)
command line switch for debug options
-rw-r--r--abi0.c11
-rw-r--r--common.h5
-rw-r--r--ir.c3
-rw-r--r--irdump.c4
-rw-r--r--main.c11
-rw-r--r--parse.c7
-rw-r--r--regalloc.c5
7 files changed, 34 insertions, 12 deletions
diff --git a/abi0.c b/abi0.c
index 099364a..3236e63 100644
--- a/abi0.c
+++ b/abi0.c
@@ -217,8 +217,8 @@ abi0(struct function *fn)
struct call *call = &calltab.p[ins->r.idx];
static union ref newargsbuf[32];
static union irtype newtypsbuf[32];
- vec_of(union ref) newargs;
- vec_of(union irtype) newtyps;
+ vec_of(union ref) newargs = VINIT(newargsbuf, arraylength(newargsbuf));
+ vec_of(union irtype) newtyps = VINIT(newtypsbuf, arraylength(newtypsbuf));
bool structbyval;
int vararg;
@@ -226,8 +226,6 @@ abi0(struct function *fn)
vararg = call->vararg;
vinit(&abiargs, abiargsbuf, arraylength(abiargsbuf));
- vinit(&newargs, newargsbuf, arraylength(newargsbuf));
- vinit(&newtyps, newtypsbuf, arraylength(newtypsbuf));
if (!(structbyval = call->sret))
for (int i = 0; i < call->narg; ++i)
if ((structbyval = call->typs[i].isagg))
@@ -356,6 +354,11 @@ abi0(struct function *fn)
}
}
} while ((blk = blk->lnext) != fn->entry);
+
+ if (ccopt.dbg.a) {
+ efmt("after abi0:\n");
+ irdump(fn, fn->name);
+ }
}
/* vim:set ts=3 sw=3 expandtab: */
diff --git a/common.h b/common.h
index 1b40000..5ebbcd8 100644
--- a/common.h
+++ b/common.h
@@ -96,6 +96,11 @@ struct option {
bool pedant;
bool trigraph;
bool nocolor;
+ struct {
+ bool p : 1, /* after parsing */
+ a : 1, /* after abi0 */
+ r : 1; /* after regalloc */
+ } dbg;
};
extern struct option ccopt;
diff --git a/ir.c b/ir.c
index ba46a97..cb4cc27 100644
--- a/ir.c
+++ b/ir.c
@@ -1,5 +1,4 @@
#include "ir.h"
-#include "common.h"
uchar type2cls[NTYPETAG];
uchar cls2siz[KF8+1];
@@ -385,8 +384,6 @@ irfini(struct function *fn)
if (!nerror) {
abi0(fn);
regalloc(fn);
- efmt("after regalloc:\n");
- irdump(fn, fn->name);
}
freefn(fn);
diff --git a/irdump.c b/irdump.c
index 27f3edc..aa815e4 100644
--- a/irdump.c
+++ b/irdump.c
@@ -1,4 +1,3 @@
-#include "common.h"
#include "ir.h"
extern struct xcon conht[];
@@ -150,7 +149,7 @@ irdump(struct function *fn, const char *fname)
struct block *blk;
efmt("function %s : %ty\n", fname, fn->fnty);
- if (fn->abiarg || fn->retty.t != TYVOID) {
+ if (fn->abiarg || fn->nabiret) {
efmt("abi: (");
for (int i = 0; i < fn->nabiarg; ++i) {
if (i > 0) efmt(", ");
@@ -173,6 +172,7 @@ irdump(struct function *fn, const char *fname)
do {
dumpblk(fn, blk);
} while ((blk = blk->lnext) != fn->entry);
+ efmt("\n");
}
/* vim:set ts=3 sw=3 expandtab: */
diff --git a/main.c b/main.c
index d56cd50..d91188f 100644
--- a/main.c
+++ b/main.c
@@ -12,10 +12,11 @@ flushstd(void)
ioflush(&bstderr);
}
+/* parse an argument of the form 'opt=abcd'
+ * e.g. arg="foo=bar123"; opt="foo"; returns "bar123" */
static const char *
optval(const char *arg, const char *opt)
{
- /* arg="foo=bar123"; opt="foo"; returns "bar123" */
uint n1 = strlen(arg), n2 = strlen(opt);
if (n1 < n2+1 || memcmp(arg, opt, n2) != 0 || arg[n2] != '=')
return NULL;
@@ -41,6 +42,14 @@ optparse(const char **file, const char **targ, char **args)
else goto Bad;
} else if (!strcmp(arg, "pedantic")) {
ccopt.pedant = 1;
+ } else if (*arg == 'd' && arg[1]) {
+ /* see common.h§struct option */
+ while (*++arg) switch (*arg | 32) {
+ case 'p': ccopt.dbg.p = 1; break;
+ case 'a': ccopt.dbg.a = 1; break;
+ case 'r': ccopt.dbg.r = 1; break;
+ default: warn(NULL, "-d: invalid debug flag %'c", *arg);
+ }
} else Bad: warn(NULL, "invalid option: %'s", arg-1);
}
}
diff --git a/parse.c b/parse.c
index 2fc26be..4ed63c7 100644
--- a/parse.c
+++ b/parse.c
@@ -2582,7 +2582,6 @@ parse(struct parser *pr)
}
continue;
}
- if (decl.name) efmt("%s : %tq\n", decl.name, decl.ty, decl.qual);
if (st.funcdef) {
const struct typedata *td = &typedata[decl.ty.dat];
struct function fn = { pr->fnarena, decl.name, .globl = decl.scls != SCSTATIC };
@@ -2591,7 +2590,8 @@ parse(struct parser *pr)
putdecl(pr, &decl);
irinit(&fn);
function(pr, &fn, st.pnames, st.pspans);
- /* if (!nerror) irdump(&fn, decl.name); */
+ if (!nerror && ccopt.dbg.p)
+ irdump(&fn, decl.name);
irfini(&fn);
} else if (decl.name) {
putdecl(pr, &decl);
@@ -2603,6 +2603,9 @@ parse(struct parser *pr)
if (!eval(&ini, EVSTATICINI))
error(&ini.span, "cannot evaluate expression statically");
}
+ if (ccopt.dbg.p) efmt("var %s : %tq\n", decl.name, decl.ty, decl.qual);
+ } else {
+ if (ccopt.dbg.p) efmt("type %ty\n", decl.ty);
}
freearena(pr->fnarena);
freearena(pr->exarena);
diff --git a/regalloc.c b/regalloc.c
index 92d2b30..5810079 100644
--- a/regalloc.c
+++ b/regalloc.c
@@ -110,6 +110,11 @@ regalloc(struct function *fn)
if (ins->r.t) use(blk, ins->op, hint1, &ins->r);
}
} while ((blk = blk->lprev) != last);
+
+ if (ccopt.dbg.r) {
+ efmt("after regalloc:\n");
+ irdump(fn, fn->name);
+ }
}
/* vim:set ts=3 sw=3 expandtab: */