add unreachable instruction to the mono IR

This commit is contained in:
Folkert 2021-01-01 02:26:56 +01:00
parent ccd302cbe9
commit 6bc0cf33a5
6 changed files with 22 additions and 2 deletions

View file

@ -1366,6 +1366,13 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
value value
} }
Unreachable => {
// used in exception handling
env.builder.build_unreachable();
env.context.i64_type().const_zero().into()
}
Switch { Switch {
branches, branches,
default_branch, default_branch,

View file

@ -335,6 +335,7 @@ where
Stmt::Ret(sym) => { Stmt::Ret(sym) => {
self.set_last_seen(*sym, stmt); self.set_last_seen(*sym, stmt);
} }
Stmt::Unreachable => {}
Stmt::Inc(sym, following) => { Stmt::Inc(sym, following) => {
self.set_last_seen(*sym, stmt); self.set_last_seen(*sym, stmt);
self.scan_ast(following); self.scan_ast(following);

View file

@ -166,7 +166,7 @@ impl<'a> ParamMap<'a> {
} }
Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"), Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Ret(_) | Jump(_, _) | RuntimeError(_) => { Ret(_) | Unreachable | Jump(_, _) | RuntimeError(_) => {
// these are terminal, do nothing // these are terminal, do nothing
} }
} }
@ -470,7 +470,7 @@ impl<'a> BorrowInfState<'a> {
} }
Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"), Inc(_, _) | Dec(_, _) => unreachable!("these have not been introduced yet"),
Ret(_) | RuntimeError(_) => { Ret(_) | RuntimeError(_) | Unreachable => {
// these are terminal, do nothing // these are terminal, do nothing
} }
} }

View file

@ -35,6 +35,8 @@ pub fn occuring_variables(stmt: &Stmt<'_>) -> (MutSet<Symbol>, MutSet<Symbol>) {
result.insert(*symbol); result.insert(*symbol);
} }
Unreachable => {}
Inc(symbol, cont) | Dec(symbol, cont) => { Inc(symbol, cont) | Dec(symbol, cont) => {
result.insert(*symbol); result.insert(*symbol);
stack.push(cont); stack.push(cont);
@ -673,6 +675,8 @@ impl<'a> Context<'a> {
} }
} }
Unreachable => (stmt, MutSet::default()),
Jump(j, xs) => { Jump(j, xs) => {
let empty = MutSet::default(); let empty = MutSet::default();
let j_live_vars = match self.jp_live_vars.get(j) { let j_live_vars = match self.jp_live_vars.get(j) {
@ -813,6 +817,8 @@ pub fn collect_stmt(
vars vars
} }
Unreachable => vars,
RuntimeError(_) => vars, RuntimeError(_) => vars,
} }
} }

View file

@ -754,6 +754,7 @@ pub enum Stmt<'a> {
ret_layout: Layout<'a>, ret_layout: Layout<'a>,
}, },
Ret(Symbol), Ret(Symbol),
Unreachable,
Inc(Symbol, &'a Stmt<'a>), Inc(Symbol, &'a Stmt<'a>),
Dec(Symbol, &'a Stmt<'a>), Dec(Symbol, &'a Stmt<'a>),
Join { Join {
@ -1103,6 +1104,8 @@ impl<'a> Stmt<'a> {
.append(symbol_to_doc(alloc, *symbol)) .append(symbol_to_doc(alloc, *symbol))
.append(";"), .append(";"),
Unreachable => alloc.text("unreachable;"),
Switch { Switch {
cond_symbol, cond_symbol,
branches, branches,
@ -4436,6 +4439,8 @@ fn substitute_in_stmt_help<'a>(
} }
} }
Unreachable => None,
RuntimeError(_) => None, RuntimeError(_) => None,
} }
} }

View file

@ -187,6 +187,7 @@ fn insert_jumps<'a>(
None => None, None => None,
}, },
Unreachable => None,
Ret(_) => None, Ret(_) => None,
Jump(_, _) => None, Jump(_, _) => None,
RuntimeError(_) => None, RuntimeError(_) => None,