From 9126afa2da0e1635d78429075cc44ca576f68169 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 24 Nov 2022 11:08:33 +0100 Subject: new hlt block terminator It is handy to express when the end of a block cannot be reached. If a hlt terminator is executed, it traps the program. We don't go the llvm way and specify execution semantics as undefined behavior. --- amd64/emit.c | 3 +++ amd64/isel.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'amd64') diff --git a/amd64/emit.c b/amd64/emit.c index a034a66..9e5996b 100644 --- a/amd64/emit.c +++ b/amd64/emit.c @@ -582,6 +582,9 @@ amd64_emitfn(Fn *fn, FILE *f) emitins(*i, fn, f); lbl = 1; switch (b->jmp.type) { + case Jhlt: + fprintf(f, "\tud2\n"); + break; case Jret0: if (fn->dynalloc) fprintf(f, diff --git a/amd64/isel.c b/amd64/isel.c index 63c304a..6d62275 100644 --- a/amd64/isel.c +++ b/amd64/isel.c @@ -465,7 +465,9 @@ seljmp(Blk *b, Fn *fn) Ins *fi; Tmp *t; - if (b->jmp.type == Jret0 || b->jmp.type == Jjmp) + if (b->jmp.type == Jret0 + || b->jmp.type == Jjmp + || b->jmp.type == Jhlt) return; assert(b->jmp.type == Jjnz); r = b->jmp.arg; -- cgit 1.4.1