nac3core/toplevel: added personality symbol config

This commit is contained in:
pca006132 2021-09-25 21:44:00 +08:00
parent dd998c8afc
commit 693ac7d336
5 changed files with 14 additions and 0 deletions

View File

@ -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");

View File

@ -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);

View File

@ -132,6 +132,7 @@ impl TopLevelComposer {
self.unifier.get_shared_unifier(),
self.primitives_ty,
)])),
personality_symbol: None
}
}

View File

@ -84,4 +84,5 @@ pub enum TopLevelDef {
pub struct TopLevelContext {
pub definitions: Arc<RwLock<Vec<Arc<RwLock<TopLevelDef>>>>>,
pub unifiers: Arc<RwLock<Vec<(SharedUnifier, PrimitiveStore)>>>,
pub personality_symbol: Option<String>,
}

View File

@ -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 {