Skip to content

Commit

Permalink
progress with ir
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Feb 1, 2024
1 parent 17d23fb commit 7c8b4c1
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 140 deletions.
6 changes: 3 additions & 3 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"

members = [ "crates/concrete","crates/concrete_ast", "crates/concrete_codegen_mlir", "crates/concrete_driver", "crates/concrete_mir", "crates/concrete_parser", "crates/concrete_session", "crates/concrete_type_checker"]
members = [ "crates/concrete","crates/concrete_ast", "crates/concrete_codegen_mlir", "crates/concrete_driver", "crates/concrete_ir", "crates/concrete_parser", "crates/concrete_session", "crates/concrete_type_checker"]

[profile.release]
lto = true
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_ast/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum TypeSpec {
},
Array {
of_type: Box<Self>,
size: u64,
size: u128,
is_ref: Option<RefType>,
span: Span,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_codegen_mlir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
bumpalo = { version = "3.14.0", features = ["std"] }
concrete_ast = { path = "../concrete_ast"}
concrete_mir = { version = "0.1.0", path = "../concrete_mir" }
concrete_ir = { version = "0.1.0", path = "../concrete_ir" }
concrete_session = { path = "../concrete_session"}
itertools = "0.12.0"
llvm-sys = "170.0.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concrete_session = { path = "../concrete_session"}
concrete_codegen_mlir = { path = "../concrete_codegen_mlir"}
salsa = { git = "https://github.com/salsa-rs/salsa.git", package = "salsa-2022" }
ariadne = { version = "0.4.0", features = ["auto-color"] }
concrete_mir = { version = "0.1.0", path = "../concrete_mir" }
concrete_ir = { version = "0.1.0", path = "../concrete_ir" }

[dev-dependencies]
tempfile = "3.9.0"
10 changes: 5 additions & 5 deletions crates/concrete_driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ariadne::Source;
use clap::Parser;
use concrete_codegen_mlir::linker::{link_binary, link_shared_lib};
use concrete_mir::build_mir;
use concrete_ir::lower_program;
use concrete_parser::{error::Diagnostics, ProgramSource};
use concrete_session::{
config::{DebugInfo, OptLevel},
Expand Down Expand Up @@ -31,7 +31,7 @@ pub struct CompilerArgs {

/// Prints the middle ir.
#[arg(long, default_value_t = false)]
print_mir: bool,
print_ir: bool,
}

pub fn main() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -66,10 +66,10 @@ pub fn main() -> Result<(), Box<dyn Error>> {
println!("{:#?}", program);
}

let program_mir = build_mir(&program);
let program_ir = lower_program(&program);

if args.print_mir {
println!("{:#?}", program_mir);
if args.print_ir {
println!("{:#?}", program_ir);
}

let cwd = std::env::current_dir()?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "concrete_mir"
name = "concrete_ir"
version = "0.1.0"
edition = "2021"

Expand Down
77 changes: 77 additions & 0 deletions crates/concrete_ir/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use std::collections::HashMap;

use crate::{BlockIndex, DefId, FnBody, Local, LocalIndex, Ty};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct IdGenerator {
pub current_id: usize,
pub module_id: usize,
}

impl IdGenerator {
pub const fn new(module_id: usize) -> Self {
Self {
current_id: 0,
module_id: 0,
}
}

pub fn next_id(&mut self) -> usize {
self.current_id += 1;
self.current_id
}

pub fn next_defid(&mut self) -> DefId {
let id = self.next_id();

DefId {
module_id: self.module_id,
index: id,
}
}
}

#[derive(Debug, Clone, Default)]
pub struct BuildCtx {
pub module_name_to_id: HashMap<String, usize>,
pub modules: HashMap<usize, ModuleCtx>,
pub functions: HashMap<DefId, FnBody>,
pub module_id_counter: usize,
}

#[derive(Debug, Clone, Default)]
pub struct ModuleCtx {
pub id: usize,
pub func_name_to_id: HashMap<String, DefId>,
pub gen: IdGenerator,
}

#[derive(Debug, Clone)]
pub struct FnBodyBuilder {
pub local_module: usize,
pub body: FnBody,
pub ret_local: Option<LocalIndex>,
pub local_map: HashMap<String, LocalIndex>,
pub current_block: BlockIndex,
pub ctx: BuildCtx,
}

impl FnBodyBuilder {
pub fn get_local(&self, name: &str) -> Option<&(Local, Ty)> {
self.body.locals.get(*(self.local_map.get(name)?))
}

pub fn get_current_module(&mut self) -> &ModuleCtx {
self.ctx
.modules
.get(&self.local_module)
.expect("current module should exist")
}

pub fn get_current_module_mut(&mut self) -> &mut ModuleCtx {
self.ctx
.modules
.get_mut(&self.local_module)
.expect("current module should exist")
}
}
Loading

0 comments on commit 7c8b4c1

Please sign in to comment.