From 2ca9a54daaa0a955dabf38862cd777be359252e0 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 15 Nov 2025 19:53:47 +0100 Subject: ir: 'trap' jump; c: __builtin_trap; lex: __has_builtin --- ir/builder.c | 8 ++++++++ ir/dump.c | 2 +- ir/ir.h | 3 ++- ir/regalloc.c | 4 ++-- 4 files changed, 13 insertions(+), 4 deletions(-) (limited to 'ir') diff --git a/ir/builder.c b/ir/builder.c index 640c1fd..1d73314 100644 --- a/ir/builder.c +++ b/ir/builder.c @@ -207,11 +207,19 @@ putcondbranch(struct function *fn, union ref arg, struct block *t, struct block void putreturn(struct function *fn, union ref r0, union ref r1) { + assert(fn->curblk); adduse(fn->curblk, USERJUMP, r0); adduse(fn->curblk, USERJUMP, r1); putjump(fn, Jret, r0, r1, NULL, NULL); } +void +puttrap(struct function *fn) +{ + assert(fn->curblk); + putjump(fn, Jtrap, NOREF, NOREF, NULL, NULL); +} + #undef putjump /* vim:set ts=3 sw=3 expandtab: */ diff --git a/ir/dump.c b/ir/dump.c index 2245d3f..2e54310 100644 --- a/ir/dump.c +++ b/ir/dump.c @@ -176,7 +176,7 @@ dumpinst(const struct instr *ins) void dumpblk(struct function *fn, struct block *blk) { - static const char *jnames[] = { 0, "b", "ret" }; + static const char *jnames[] = { 0, "b", "ret", "trap" }; int i; efmt(" @%d:\n", blk->id); for (i = 0; i < blk->phi.n; ++i) { diff --git a/ir/ir.h b/ir/ir.h index 22b920f..f453c51 100644 --- a/ir/ir.h +++ b/ir/ir.h @@ -113,7 +113,7 @@ struct instr { union ref l, r; /* args */ }; -enum jumpkind { JXXX, Jb, Jret, }; +enum jumpkind { JXXX, Jb, Jret, Jtrap, }; struct block { int id; @@ -263,6 +263,7 @@ void useblk(struct function *, struct block *); void putbranch(struct function *, struct block *); void putcondbranch(struct function *, union ref arg, struct block *t, struct block *f); void putreturn(struct function *, union ref r0, union ref r1); +void puttrap(struct function *); /** fold.c **/ bool foldbinop(union ref *to, enum op, enum irclass, union ref l, union ref r); diff --git a/ir/regalloc.c b/ir/regalloc.c index f43bcc7..ca3ddcc 100644 --- a/ir/regalloc.c +++ b/ir/regalloc.c @@ -1134,10 +1134,10 @@ fini(struct rega *ra) * b @blk * @blk: * NOP - * ret + * ret/trap */ assert(p->s1 == blk); - p->jmp.t = Jret; + p->jmp.t = blk->jmp.t; p->s1 = NULL; } else if (blk->s1) { /* simplify: -- cgit v1.2.3