forked from M-Labs/nac3
1
0
Fork 0

put alloca in init block

This commit is contained in:
pca006132 2021-08-09 16:37:28 +08:00
parent cc0692a34c
commit 4db871c244
2 changed files with 9 additions and 8 deletions

View File

@ -1,17 +1,16 @@
use std::convert::TryInto;
use crate::{top_level::CodeGenContext, typecheck::typedef::Type};
use inkwell::{
types::BasicTypeEnum,
values::{BasicValueEnum, PointerValue},
};
use inkwell::values::{BasicValueEnum, PointerValue};
use rustpython_parser::ast::{Expr, ExprKind, Stmt, StmtKind};
impl<'ctx> CodeGenContext<'ctx> {
fn gen_var(&mut self, ty: Type) -> PointerValue<'ctx> {
// should we build the alloca in an initial block?
// put the alloca in init block
let current = self.builder.get_insert_block().unwrap();
self.builder.position_at_end(self.init_bb);
let ty = self.get_llvm_type(ty);
self.builder.build_alloca(ty, "tmp")
let ptr = self.builder.build_alloca(ty, "tmp");
self.builder.position_at_end(current);
ptr
}
fn parse_pattern(&mut self, pattern: &Expr<Option<Type>>) -> PointerValue<'ctx> {

View File

@ -68,6 +68,8 @@ pub struct CodeGenContext<'ctx> {
pub var_assignment: HashMap<String, PointerValue<'ctx>>,
pub type_cache: HashMap<Type, BasicTypeEnum<'ctx>>,
pub primitives: PrimitiveStore,
// stores the alloca for variables
pub init_bb: BasicBlock<'ctx>,
// where continue and break should go to respectively
// the first one is the test_bb, and the second one is bb after the loop
pub loop_bb: Option<(BasicBlock<'ctx>, BasicBlock<'ctx>)>,