Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Jan 18, 2024
1 parent 37a040c commit a08d915
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 66 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/concrete_codegen_mlir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concrete_ast = { path = "../concrete_ast"}
concrete_session = { path = "../concrete_session"}
itertools = "0.12.0"
llvm-sys = "170.0.1"
melior = { version = "0.15.0", features = ["ods-dialects"] }
melior = { version = "0.15.2", features = ["ods-dialects"] }
mlir-sys = "0.2.1"
tracing.workspace = true

Expand Down
65 changes: 2 additions & 63 deletions crates/concrete_codegen_mlir/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::{collections::HashMap, error::Error};
use bumpalo::Bump;
use concrete_ast::{
expressions::{
ArithOp, BinaryOp, CmpOp, Expression, FnCallOp, IfExpr, LogicOp, PathOp, PathSegment,
ValueExpr,
ArithOp, BinaryOp, CmpOp, Expression, FnCallOp, IfExpr, LogicOp, PathOp, ValueExpr,
},
functions::FunctionDef,
modules::{Module, ModuleDefItem},
Expand Down Expand Up @@ -598,67 +597,7 @@ fn compile_assign_stmt<'ctx, 'parent: 'ctx>(
Some(&local.type_spec),
)?;

if info.target.extra.is_empty() {
block.append_operation(memref::store(value, local.value, &[], location));
} else {
let mut store_target = block
.append_operation(memref::load(local.value, &[], location))
.result(0)?
.into();

let mut segment_iter = info.target.extra.iter().peekable();

while let Some(segment) = segment_iter.next() {
match segment {
PathSegment::FieldAccess(_) => todo!(),
PathSegment::ArrayIndex(index) => {
let index = compile_value_expr(
session, context, scope_ctx, helper, block, index, None,
)?;
let index_ty = Type::index(context);
let index = block
.append_operation(melior::dialect::index::castu(index, index_ty, location))
.result(0)?
.into();

if let TypeSpec::Array {
of_type: _,
size,
is_ref: _,
span,
} = &local.type_spec
{
let location = get_location(context, session, span.from);

#[allow(clippy::if_same_then_else)]
if size.is_some() {
// todo: check inbounds?
store_target = block
.append_operation(memref::load(store_target, &[index], location))
.result(0)?
.into();
} else {
store_target = block
.append_operation(memref::load(store_target, &[index], location))
.result(0)?
.into();
}

if segment_iter.peek().is_none() {
block.append_operation(memref::store(
value,
store_target,
&[index],
location,
));
}
} else {
panic!("type should be a array when indexing a value");
}
}
}
}
}
block.append_operation(memref::store(value, local.value, &[], location));

Ok(())
}
Expand Down

0 comments on commit a08d915

Please sign in to comment.