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
}
Unreachable => {
// used in exception handling
env.builder.build_unreachable();
env.context.i64_type().const_zero().into()
}
Switch {
branches,
default_branch,

View File

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

View File

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

View File

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

View File

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

View File

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