json_v0_bridge: add new_block() helper; refactor block creation in logical/try/loop; allow(dead_code) wrappers to quieten unused warnings (no behavior change)
This commit is contained in:
@ -103,6 +103,13 @@ fn next_block_id(f: &MirFunction) -> BasicBlockId {
|
|||||||
BasicBlockId::new(mx)
|
BasicBlockId::new(mx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a fresh basic block and insert it into the function.
|
||||||
|
fn new_block(f: &mut MirFunction) -> BasicBlockId {
|
||||||
|
let id = next_block_id(f);
|
||||||
|
f.add_block(BasicBlock::new(id));
|
||||||
|
id
|
||||||
|
}
|
||||||
|
|
||||||
fn lower_throw(
|
fn lower_throw(
|
||||||
env: &BridgeEnv,
|
env: &BridgeEnv,
|
||||||
f: &mut MirFunction,
|
f: &mut MirFunction,
|
||||||
@ -238,12 +245,9 @@ fn lower_expr_with_scope<S: VarScope>(
|
|||||||
}
|
}
|
||||||
ExprV0::Logical { op, lhs, rhs } => {
|
ExprV0::Logical { op, lhs, rhs } => {
|
||||||
let (l, cur_after_l) = lower_expr_with_scope(env, f, cur_bb, lhs, vars)?;
|
let (l, cur_after_l) = lower_expr_with_scope(env, f, cur_bb, lhs, vars)?;
|
||||||
let rhs_bb = next_block_id(f);
|
let rhs_bb = new_block(f);
|
||||||
let fall_bb = BasicBlockId::new(rhs_bb.0 + 1);
|
let fall_bb = new_block(f);
|
||||||
let merge_bb = BasicBlockId::new(rhs_bb.0 + 2);
|
let merge_bb = new_block(f);
|
||||||
f.add_block(BasicBlock::new(rhs_bb));
|
|
||||||
f.add_block(BasicBlock::new(fall_bb));
|
|
||||||
f.add_block(BasicBlock::new(merge_bb));
|
|
||||||
let is_and = matches!(op.as_str(), "&&" | "and");
|
let is_and = matches!(op.as_str(), "&&" | "and");
|
||||||
if let Some(bb) = f.get_block_mut(cur_after_l) {
|
if let Some(bb) = f.get_block_mut(cur_after_l) {
|
||||||
if is_and {
|
if is_and {
|
||||||
@ -464,6 +468,7 @@ fn lower_args_with_scope<S: VarScope>(
|
|||||||
Ok((out, cur))
|
Ok((out, cur))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn lower_expr(
|
fn lower_expr(
|
||||||
env: &BridgeEnv,
|
env: &BridgeEnv,
|
||||||
f: &mut MirFunction,
|
f: &mut MirFunction,
|
||||||
@ -485,6 +490,7 @@ fn lower_expr_with_vars(
|
|||||||
lower_expr_with_scope(env, f, cur_bb, e, &mut scope)
|
lower_expr_with_scope(env, f, cur_bb, e, &mut scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn lower_args(
|
fn lower_args(
|
||||||
env: &BridgeEnv,
|
env: &BridgeEnv,
|
||||||
f: &mut MirFunction,
|
f: &mut MirFunction,
|
||||||
@ -603,20 +609,16 @@ fn lower_stmt_with_vars(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let base_vars = vars.clone();
|
let base_vars = vars.clone();
|
||||||
let try_bb = next_block_id(f);
|
let try_bb = new_block(f);
|
||||||
f.add_block(BasicBlock::new(try_bb));
|
|
||||||
let catch_clause = &catches[0];
|
let catch_clause = &catches[0];
|
||||||
let catch_bb = next_block_id(f);
|
let catch_bb = new_block(f);
|
||||||
f.add_block(BasicBlock::new(catch_bb));
|
|
||||||
let finally_bb = if !finally.is_empty() {
|
let finally_bb = if !finally.is_empty() {
|
||||||
let id = next_block_id(f);
|
let id = new_block(f);
|
||||||
f.add_block(BasicBlock::new(id));
|
|
||||||
Some(id)
|
Some(id)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let exit_bb = next_block_id(f);
|
let exit_bb = new_block(f);
|
||||||
f.add_block(BasicBlock::new(exit_bb));
|
|
||||||
let handler_target = finally_bb.unwrap_or(exit_bb);
|
let handler_target = finally_bb.unwrap_or(exit_bb);
|
||||||
let exception_value = f.next_value_id();
|
let exception_value = f.next_value_id();
|
||||||
if let Some(bb) = f.get_block_mut(cur_bb) {
|
if let Some(bb) = f.get_block_mut(cur_bb) {
|
||||||
@ -890,12 +892,9 @@ fn lower_stmt_with_vars(
|
|||||||
Ok(merge_bb)
|
Ok(merge_bb)
|
||||||
}
|
}
|
||||||
StmtV0::Loop { cond, body } => {
|
StmtV0::Loop { cond, body } => {
|
||||||
let cond_bb = next_block_id(f);
|
let cond_bb = new_block(f);
|
||||||
let body_bb = BasicBlockId::new(cond_bb.0 + 1);
|
let body_bb = new_block(f);
|
||||||
let exit_bb = BasicBlockId::new(cond_bb.0 + 2);
|
let exit_bb = new_block(f);
|
||||||
f.add_block(BasicBlock::new(cond_bb));
|
|
||||||
f.add_block(BasicBlock::new(body_bb));
|
|
||||||
f.add_block(BasicBlock::new(exit_bb));
|
|
||||||
if let Some(bb) = f.get_block_mut(cur_bb) {
|
if let Some(bb) = f.get_block_mut(cur_bb) {
|
||||||
if !bb.is_terminated() {
|
if !bb.is_terminated() {
|
||||||
bb.add_instruction(MirInstruction::Jump { target: cond_bb });
|
bb.add_instruction(MirInstruction::Jump { target: cond_bb });
|
||||||
|
|||||||
Reference in New Issue
Block a user