put alloca in init block
This commit is contained in:
parent
cc0692a34c
commit
4db871c244
|
@ -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> {
|
||||
|
|
|
@ -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>)>,
|
||||
|
|
Loading…
Reference in New Issue