Skip to content

Commit

Permalink
Add lower constant dummy impl
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed May 7, 2024
1 parent 73164c3 commit 9eb2dd8
Showing 1 changed file with 72 additions and 6 deletions.
78 changes: 72 additions & 6 deletions crates/concrete_ir/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use concrete_ast::{
};

use crate::{
AdtBody, BasicBlock, BinOp, ConstData, ConstKind, ConstValue, DefId, FloatTy, FnBody, IntTy,
Local, LocalKind, LogOp, Mutability, Operand, Place, PlaceElem, ProgramBody, Rvalue, Statement,
StatementKind, SwitchTargets, Terminator, TerminatorKind, Ty, TyKind, UintTy, ValueTree,
VariantDef,
AdtBody, BasicBlock, BinOp, ConstData, ConstKind, ConstValue, ConstantBody, DefId, FloatTy,
FnBody, IntTy, Local, LocalKind, LogOp, Mutability, Operand, Place, PlaceElem, ProgramBody,
Rvalue, Statement, StatementKind, SwitchTargets, Terminator, TerminatorKind, Ty, TyKind,
UintTy, ValueTree, VariantDef,
};

use self::errors::LoweringError;
Expand Down Expand Up @@ -182,8 +182,74 @@ fn lower_module(mut ctx: BuildCtx, module: &Module, id: DefId) -> Result<BuildCt
Ok(ctx)
}

fn lower_constant(ctx: BuildCtx, info: &ConstantDef, id: DefId) -> Result<BuildCtx, LoweringError> {
todo!()
fn lower_constant(
mut ctx: BuildCtx,
constant: &ConstantDef,
module_id: DefId,
) -> Result<BuildCtx, LoweringError> {
let mut body = ConstantBody {
id: {
let body = ctx.body.modules.get(&module_id).unwrap();
*body
.symbols
.constants
.get(&constant.decl.name.name)
.unwrap()
},
name: constant.decl.name.name.clone(),
basic_block: BasicBlock {
statements: Vec::new(),
terminator: Box::new(Terminator {
span: None,
kind: TerminatorKind::Return,
}),
},
locals: Vec::new(),
};

let (value, value_ty) = match &constant.value {
Expression::Value(value, _) => match value {
ValueExpr::ConstInt(number, _) => (
Rvalue::Use(Operand::Const(ConstData {
ty: Ty {
span: None,
kind: TyKind::Int(IntTy::I32),
},
data: ConstKind::Value(ValueTree::Leaf(ConstValue::I32(
(*number).try_into().expect("value out of range"),
))),
})),
Ty {
span: None,
kind: TyKind::Int(IntTy::I32),
},
),
_ => unreachable!(),
},
_ => unreachable!(),
};

body.locals.push(Local {
span: None,
debug_name: None,
ty: value_ty,
kind: LocalKind::ReturnPointer,
});

body.basic_block.statements.push(Statement {
span: None,
kind: StatementKind::Assign(
Place {
local: 0,
projection: Vec::new(),
},
value,
),
});

ctx.body.constants.insert(body.id, body);

Ok(ctx)
}

fn lower_struct(
Expand Down

0 comments on commit 9eb2dd8

Please sign in to comment.