From 331166778e96279cb7580c1c425b121b5ac76bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Gonz=C3=A1lez=20Calder=C3=B3n?= Date: Thu, 9 May 2024 12:01:09 -0300 Subject: [PATCH] Add reference to constant in function body --- crates/concrete_ir/src/lowering.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/concrete_ir/src/lowering.rs b/crates/concrete_ir/src/lowering.rs index 3410c6b..d3683f0 100644 --- a/crates/concrete_ir/src/lowering.rs +++ b/crates/concrete_ir/src/lowering.rs @@ -1535,7 +1535,29 @@ fn lower_value_expr( ValueExpr::ConstStr(_, _) => todo!(), ValueExpr::Path(info) => match lower_path(builder, info) { Ok((place, place_ty, _span)) => (Rvalue::Use(Operand::Place(place.clone())), place_ty), - Err(err @ LoweringError::UseOfUndeclaredVariable { .. }) => return Err(err), + Err(err @ LoweringError::UseOfUndeclaredVariable { .. }) => { + let mod_body = builder.get_module_body(); + + let constant_id = + if let Some(constant_id) = mod_body.symbols.constants.get(&info.first.name) { + *constant_id + } else { + return Err(err); + }; + + let constant_value = builder + .ctx + .body + .constants + .get(&constant_id) + .expect("constant should exist") + .value + .clone(); + + let ty = constant_value.ty.clone(); + + (Rvalue::Use(Operand::Const(constant_value)), ty) + } Err(err) => return Err(err), }, })