Skip to content

Commit

Permalink
name mangling
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Mar 12, 2024
1 parent 9741a8f commit 84f3fdf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Make sure you have installed the dependencies:
- git
- Rust
- LLVM 17 with MLIR enabled
- libgit2

If building LLVM from source, you'll need additional tools:
- g++, clang++, or MSVC with versions listed on [LLVM's documentation](https://llvm.org/docs/GettingStarted.html#host-c-toolchain-both-compiler-and-standard-library)
Expand Down
8 changes: 5 additions & 3 deletions crates/concrete_codegen_mlir/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ fn compile_function(ctx: FunctionCodegenCtx) -> Result<(), CodegenError> {
.iter()
.map(|x| compile_rvalue(&ctx, mlir_block, x, &locals).map(|x| x.0))
.collect::<Result<_, _>>()?;
let fn_symbol =
FlatSymbolRefAttribute::new(ctx.context(), &target_fn_body.name); // todo: good name resolution
let fn_symbol = FlatSymbolRefAttribute::new(
ctx.context(),
&target_fn_body.get_mangled_name(),
);
let ret_type = match &target_fn_body_sig.1.kind {
TyKind::Unit => None,
_ => Some(compile_type(ctx.module_ctx, &target_fn_body_sig.1)),
Expand Down Expand Up @@ -443,7 +445,7 @@ fn compile_function(ctx: FunctionCodegenCtx) -> Result<(), CodegenError> {

let func_op = func::func(
ctx.context(),
StringAttribute::new(ctx.context(), &body.name),
StringAttribute::new(ctx.context(), &body.get_mangled_name()),
TypeAttribute::new(func_type.into()),
region,
&fn_attributes,
Expand Down
2 changes: 1 addition & 1 deletion crates/concrete_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod db;
pub mod linker;

#[derive(Parser, Debug)]
#[command(author, version, about = "concrete", long_about = None, bin_name = "concrete")]
#[command(author, version, about = "The Concrete Programming Language", long_about = None, bin_name = "concrete")]
pub struct Cli {
#[command(subcommand)]
command: Commands,
Expand Down
12 changes: 12 additions & 0 deletions crates/concrete_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ impl FnBody {
.filter(|x| matches!(x.kind, LocalKind::Arg))
.collect()
}

pub fn get_mangled_name(&self) -> String {
if self.is_extern {
return self.name.clone();
}

if self.name == "main" {
"main".to_string()
} else {
format!("{}@{}@{}", self.name, self.id.program_id, self.id.id)
}
}
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit 84f3fdf

Please sign in to comment.