From 693ac7d336299c32c24974ac9dd7a7b2074b3520 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sat, 25 Sep 2021 21:44:00 +0800 Subject: [PATCH] nac3core/toplevel: added personality symbol config --- nac3core/src/codegen/mod.rs | 8 ++++++++ nac3core/src/codegen/test.rs | 2 ++ nac3core/src/toplevel/composer.rs | 1 + nac3core/src/toplevel/mod.rs | 1 + nac3core/src/typecheck/type_inferencer/test.rs | 2 ++ 5 files changed, 14 insertions(+) diff --git a/nac3core/src/codegen/mod.rs b/nac3core/src/codegen/mod.rs index a78f1a4ba..e01c130ba 100644 --- a/nac3core/src/codegen/mod.rs +++ b/nac3core/src/codegen/mod.rs @@ -308,6 +308,14 @@ pub fn gen_func<'ctx>( let fn_val = module.get_function(symbol).unwrap_or_else(|| module.add_function(symbol, fn_type, None)); + if let Some(personality) = &top_level_ctx.personality_symbol { + let personality = module.get_function(&personality).unwrap_or_else(|| { + let ty = context.i32_type().fn_type(&[], true); + module.add_function(&personality, ty, None) + }); + fn_val.set_personality_function(personality); + } + let init_bb = context.append_basic_block(fn_val, "init"); builder.position_at_end(init_bb); let body_bb = context.append_basic_block(fn_val, "body"); diff --git a/nac3core/src/codegen/test.rs b/nac3core/src/codegen/test.rs index 86e55aae1..be4f5d945 100644 --- a/nac3core/src/codegen/test.rs +++ b/nac3core/src/codegen/test.rs @@ -115,6 +115,7 @@ fn test_primitives() { let top_level = Arc::new(TopLevelContext { definitions: Arc::new(RwLock::new(std::mem::take(&mut *top_level.definitions.write()))), unifiers: Arc::new(RwLock::new(vec![(unifier.get_shared_unifier(), primitives)])), + personality_symbol: None }); let unifier = (unifier.get_shared_unifier(), primitives); @@ -302,6 +303,7 @@ fn test_simple_call() { let top_level = Arc::new(TopLevelContext { definitions: Arc::new(RwLock::new(std::mem::take(&mut *top_level.definitions.write()))), unifiers: Arc::new(RwLock::new(vec![(unifier.get_shared_unifier(), primitives)])), + personality_symbol: None }); let unifier = (unifier.get_shared_unifier(), primitives); diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index f57016f24..5e351bc2a 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -132,6 +132,7 @@ impl TopLevelComposer { self.unifier.get_shared_unifier(), self.primitives_ty, )])), + personality_symbol: None } } diff --git a/nac3core/src/toplevel/mod.rs b/nac3core/src/toplevel/mod.rs index e61bc08d4..a415e50a0 100644 --- a/nac3core/src/toplevel/mod.rs +++ b/nac3core/src/toplevel/mod.rs @@ -84,4 +84,5 @@ pub enum TopLevelDef { pub struct TopLevelContext { pub definitions: Arc>>>>, pub unifiers: Arc>>, + pub personality_symbol: Option, } diff --git a/nac3core/src/typecheck/type_inferencer/test.rs b/nac3core/src/typecheck/type_inferencer/test.rs index 2f8fdb671..24dc2df16 100644 --- a/nac3core/src/typecheck/type_inferencer/test.rs +++ b/nac3core/src/typecheck/type_inferencer/test.rs @@ -102,6 +102,7 @@ impl TestEnvironment { top_level: TopLevelContext { definitions: Default::default(), unifiers: Default::default(), + personality_symbol: None, }, unifier, function_data: FunctionData { @@ -277,6 +278,7 @@ impl TestEnvironment { let top_level = TopLevelContext { definitions: Arc::new(top_level_defs.into()), unifiers: Default::default(), + personality_symbol: None }; let resolver = Arc::new(Box::new(Resolver {