This commit is contained in:
nora 2023-05-23 17:09:08 +02:00
parent 542c0daf6a
commit 86b924f5e3
7 changed files with 171 additions and 67 deletions

View file

@ -4,7 +4,7 @@ use super::LoweringCx;
use crate::{
ir::{
self, BasicBlock, BbIdx, BinKind, Branch, ConstValue, Func, Layout, Operand, Register,
RegisterData, Statement, StatementKind, TyLayout,
RegisterData, Statement, StatementKind, TyLayout, UnaryKind,
},
ty::{Ty, TyKind},
};
@ -85,6 +85,25 @@ impl<'a, 'cx> FuncBuilder<'a, 'cx> {
reg
}
pub fn unary(
&mut self,
kind: UnaryKind,
rhs: Operand,
span: Span,
result_tyl: TyLayout<'cx>,
) -> Register {
let reg = self.new_reg(None, result_tyl);
let stmt = StatementKind::UnaryOperation {
kind,
rhs,
result: reg,
};
self.cur_bb_mut()
.statements
.push(Statement { span, kind: stmt });
reg
}
pub fn load(&mut self, tyl: TyLayout<'cx>, ptr_reg: Register, span: Span) -> Register {
let reg = self.new_reg(None, tyl.clone());
let stmt = StatementKind::Load {