Skip to main content

vicis_core/ir/function/instruction/
builder.rs

1use super::{InstructionId, Opcode, Operand, Ret};
2use crate::ir::{function::builder::Builder as FuncBuilder, value::ValueId};
3// use rustc_hash::FxHashSet;
4
5pub struct Builder<'a: 'short, 'short> {
6    func_builder: &'short mut FuncBuilder<'a>,
7}
8
9impl<'a: 'short, 'short> Builder<'a, 'short> {
10    pub fn new(func_builder: &'short mut FuncBuilder<'a>) -> Self {
11        Self { func_builder }
12    }
13
14    pub fn ret(&mut self, val: ValueId) -> InstructionId {
15        let cur_block = self.func_builder.cur_block.unwrap();
16        let ty = self.func_builder.func.result_ty;
17        let inst = Opcode::Ret
18            .with_block(cur_block)
19            .with_operand(Operand::Ret(Ret { ty, val: Some(val) }));
20        let inst = self.func_builder.func.data.create_inst(inst);
21        self.func_builder.func.layout.append_inst(inst, cur_block);
22        inst
23    }
24}