forked from M-Labs/nac3
[core] codegen/expr: Materialize implicit globals
Required for when globals are read without the use of a global declaration.
This commit is contained in:
parent
42a2f243b5
commit
2bb788e4bb
|
@ -2886,7 +2886,31 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
|
|||
Some((_, Some(static_value), _)) => ValueEnum::Static(static_value.clone()),
|
||||
None => {
|
||||
let resolver = ctx.resolver.clone();
|
||||
resolver.get_symbol_value(*id, ctx, generator).unwrap()
|
||||
let value = resolver.get_symbol_value(*id, ctx, generator).unwrap();
|
||||
|
||||
let globals = ctx
|
||||
.top_level
|
||||
.definitions
|
||||
.read()
|
||||
.iter()
|
||||
.filter_map(|def| {
|
||||
if let TopLevelDef::Variable { simple_name, ty, .. } = &*def.read() {
|
||||
Some((*simple_name, *ty))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
if let Some((_, ty)) = globals.iter().find(|(name, _)| name == id) {
|
||||
let ptr = value
|
||||
.to_basic_value_enum(ctx, generator, *ty)
|
||||
.map(BasicValueEnum::into_pointer_value)?;
|
||||
|
||||
ctx.builder.build_load(ptr, id.to_string().as_str()).map(Into::into).unwrap()
|
||||
} else {
|
||||
value
|
||||
}
|
||||
}
|
||||
},
|
||||
ExprKind::List { elts, .. } => {
|
||||
|
|
Loading…
Reference in New Issue