From 84f3fdff26b411b02d1694c6317c2c0754211f4b Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Tue, 12 Mar 2024 16:34:02 +0100 Subject: [PATCH] name mangling --- README.md | 1 + crates/concrete_codegen_mlir/src/codegen.rs | 8 +++++--- crates/concrete_driver/src/lib.rs | 2 +- crates/concrete_ir/src/lib.rs | 12 ++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d5f66c9..bb543fa 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/crates/concrete_codegen_mlir/src/codegen.rs b/crates/concrete_codegen_mlir/src/codegen.rs index c509996..faa1c33 100644 --- a/crates/concrete_codegen_mlir/src/codegen.rs +++ b/crates/concrete_codegen_mlir/src/codegen.rs @@ -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::>()?; - 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)), @@ -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, diff --git a/crates/concrete_driver/src/lib.rs b/crates/concrete_driver/src/lib.rs index 7eaae20..95ba0f4 100644 --- a/crates/concrete_driver/src/lib.rs +++ b/crates/concrete_driver/src/lib.rs @@ -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, diff --git a/crates/concrete_ir/src/lib.rs b/crates/concrete_ir/src/lib.rs index 4200995..c015940 100644 --- a/crates/concrete_ir/src/lib.rs +++ b/crates/concrete_ir/src/lib.rs @@ -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)]