Skip to content

Commit

Permalink
Add lower_constant implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed May 9, 2024
1 parent f4c9ff5 commit 501c902
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 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, ConstBody, 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,
};

use self::errors::LoweringError;
Expand Down Expand Up @@ -182,8 +182,36 @@ 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> {
let _ = (ctx, info, id);
fn lower_constant(
mut ctx: BuildCtx,
info: &ConstantDef,
module_id: DefId,
) -> Result<BuildCtx, LoweringError> {
let name = info.decl.name.name.clone();

let id = {
let module = ctx
.body
.modules
.get(&module_id)
.expect("module should exist");
*module
.symbols
.constants
.get(&name)
.expect("constant should exist")
};

let value = lower_constant_expression(&info.value)?;

let body = ConstBody { id, name, value };

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

Ok(ctx)
}

fn lower_constant_expression(value: &Expression) -> Result<ConstData, LoweringError> {
todo!()
}

Expand Down

0 comments on commit 501c902

Please sign in to comment.