Compare commits
No commits in common. "6de0884dc13b648bcd0f8191f7beb6c76b1af3d5" and "049908044ac16c0d152657af1e1b96846ec6fd47" have entirely different histories.
6de0884dc1
...
049908044a
|
@ -84,7 +84,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap();
|
||||
let end_store = self.gen_store_target(ctx, &end, Some("end_store.addr"))?;
|
||||
let end_store = self.gen_store_target(ctx, &end)?;
|
||||
ctx.builder.build_store(end_store, max);
|
||||
}
|
||||
if let Some(start) = self.start.clone() {
|
||||
|
@ -140,7 +140,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
node: ExprKind::Name { id: start, ctx: name_ctx.clone() },
|
||||
custom: Some(ctx.primitives.int64),
|
||||
};
|
||||
let start = self.gen_store_target(ctx, &start_expr, Some("start.addr"))?;
|
||||
let start = self.gen_store_target(ctx, &start_expr)?;
|
||||
ctx.builder.build_store(start, now);
|
||||
Ok(Some(start_expr)) as Result<_, String>
|
||||
},
|
||||
|
@ -153,7 +153,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
node: ExprKind::Name { id: end, ctx: name_ctx.clone() },
|
||||
custom: Some(ctx.primitives.int64),
|
||||
};
|
||||
let end = self.gen_store_target(ctx, &end_expr, Some("end.addr"))?;
|
||||
let end = self.gen_store_target(ctx, &end_expr)?;
|
||||
ctx.builder.build_store(end, now);
|
||||
self.end = Some(end_expr);
|
||||
self.name_counter += 1;
|
||||
|
@ -204,7 +204,7 @@ impl<'b> CodeGenerator for ArtiqCodeGenerator<'b> {
|
|||
.try_as_basic_value()
|
||||
.left()
|
||||
.unwrap();
|
||||
let outer_end = self.gen_store_target(ctx, old_end, Some("outer_end.addr"))?;
|
||||
let outer_end = self.gen_store_target(ctx, old_end)?;
|
||||
ctx.builder.build_store(outer_end, max);
|
||||
}
|
||||
self.start = old_start;
|
||||
|
|
|
@ -810,7 +810,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
let zero_size_t = size_t.const_zero();
|
||||
let zero_32 = int32.const_zero();
|
||||
|
||||
let index = generator.gen_var_alloc(ctx, size_t.into(), Some("index.addr"))?;
|
||||
let index = generator.gen_var_alloc(ctx, size_t.into())?;
|
||||
ctx.builder.build_store(index, zero_size_t);
|
||||
|
||||
let elem_ty = ctx.get_llvm_type(generator, elt.custom.unwrap());
|
||||
|
@ -853,7 +853,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
list_content =
|
||||
ctx.build_gep_and_load(list, &[zero_size_t, zero_32]).into_pointer_value();
|
||||
|
||||
let i = generator.gen_store_target(ctx, target, Some("i.addr"))?;
|
||||
let i = generator.gen_store_target(ctx, target)?;
|
||||
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
ctx.builder.position_at_end(test_bb);
|
||||
|
@ -888,7 +888,7 @@ pub fn gen_comprehension<'ctx, 'a, G: CodeGenerator>(
|
|||
list = allocate_list(generator, ctx, elem_ty, length);
|
||||
list_content =
|
||||
ctx.build_gep_and_load(list, &[zero_size_t, zero_32]).into_pointer_value();
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("counter.addr"))?;
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into())?;
|
||||
// counter = -1
|
||||
ctx.builder.build_store(counter, size_t.const_int(u64::max_value(), true));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
|
|
|
@ -87,9 +87,8 @@ pub trait CodeGenerator {
|
|||
&mut self,
|
||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
ty: BasicTypeEnum<'ctx>,
|
||||
name: Option<&str>,
|
||||
) -> Result<PointerValue<'ctx>, String> {
|
||||
gen_var(ctx, ty, name)
|
||||
gen_var(ctx, ty)
|
||||
}
|
||||
|
||||
/// Return a pointer pointing to the target of the expression.
|
||||
|
@ -97,12 +96,11 @@ pub trait CodeGenerator {
|
|||
&mut self,
|
||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
pattern: &Expr<Option<Type>>,
|
||||
name: Option<&str>,
|
||||
) -> Result<PointerValue<'ctx>, String>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
gen_store_target(self, ctx, pattern, name)
|
||||
gen_store_target(self, ctx, pattern)
|
||||
}
|
||||
|
||||
/// Generate code for an assignment expression.
|
||||
|
|
|
@ -24,13 +24,12 @@ use std::convert::TryFrom;
|
|||
pub fn gen_var<'ctx, 'a>(
|
||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
ty: BasicTypeEnum<'ctx>,
|
||||
name: Option<&str>,
|
||||
) -> Result<PointerValue<'ctx>, String> {
|
||||
// put the alloca in init block
|
||||
let current = ctx.builder.get_insert_block().unwrap();
|
||||
// position before the last branching instruction...
|
||||
ctx.builder.position_before(&ctx.init_bb.get_last_instruction().unwrap());
|
||||
let ptr = ctx.builder.build_alloca(ty, name.unwrap_or(""));
|
||||
let ptr = ctx.builder.build_alloca(ty, "tmp");
|
||||
ctx.builder.position_at_end(current);
|
||||
Ok(ptr)
|
||||
}
|
||||
|
@ -39,7 +38,6 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||
generator: &mut G,
|
||||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
pattern: &Expr<Option<Type>>,
|
||||
name: Option<&str>,
|
||||
) -> Result<PointerValue<'ctx>, String> {
|
||||
// very similar to gen_expr, but we don't do an extra load at the end
|
||||
// and we flatten nested tuples
|
||||
|
@ -47,7 +45,7 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||
ExprKind::Name { id, .. } => match ctx.var_assignment.get(id) {
|
||||
None => {
|
||||
let ptr_ty = ctx.get_llvm_type(generator, pattern.custom.unwrap());
|
||||
let ptr = generator.gen_var_alloc(ctx, ptr_ty, name)?;
|
||||
let ptr = generator.gen_var_alloc(ctx, ptr_ty)?;
|
||||
ctx.var_assignment.insert(*id, (ptr, None, 0));
|
||||
ptr
|
||||
}
|
||||
|
@ -76,7 +74,7 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||
ctx.ctx.i32_type().const_zero(),
|
||||
ctx.ctx.i32_type().const_int(index as u64, false),
|
||||
],
|
||||
name.unwrap_or(""),
|
||||
"attr",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +135,7 @@ pub fn gen_store_target<'ctx, 'a, G: CodeGenerator>(
|
|||
let arr_ptr = ctx
|
||||
.build_gep_and_load(v, &[i32_type.const_zero(), i32_type.const_zero()])
|
||||
.into_pointer_value();
|
||||
ctx.builder.build_gep(arr_ptr, &[index], name.unwrap_or(""))
|
||||
ctx.builder.build_gep(arr_ptr, &[index], "loadarrgep")
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
@ -193,7 +191,7 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
let ptr = generator.gen_store_target(ctx, target, Some("target.addr"))?;
|
||||
let ptr = generator.gen_store_target(ctx, target)?;
|
||||
if let ExprKind::Name { id, .. } = &target.node {
|
||||
let (_, static_value, counter) = ctx.var_assignment.get_mut(id).unwrap();
|
||||
*counter += 1;
|
||||
|
@ -239,8 +237,8 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||
if ctx.unifier.unioned(iter.custom.unwrap(), ctx.primitives.range) {
|
||||
// setup
|
||||
let iter_val = iter_val.into_pointer_value();
|
||||
let i = generator.gen_var_alloc(ctx, int32.into(), Some("for.i.addr"))?;
|
||||
let user_i = generator.gen_store_target(ctx, target, Some("for.user_i.addr"))?;
|
||||
let i = generator.gen_var_alloc(ctx, int32.into())?;
|
||||
let user_i = generator.gen_store_target(ctx, target)?;
|
||||
let (start, end, step) = destructure_range(ctx, iter_val);
|
||||
ctx.builder.build_store(i, ctx.builder.build_int_sub(start, step, "start_init"));
|
||||
ctx.builder.build_unconditional_branch(test_bb);
|
||||
|
@ -272,7 +270,7 @@ pub fn gen_for<'ctx, 'a, G: CodeGenerator>(
|
|||
);
|
||||
ctx.builder.position_at_end(body_bb);
|
||||
} else {
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("for.counter.addr"))?;
|
||||
let counter = generator.gen_var_alloc(ctx, size_t.into())?;
|
||||
// counter = -1
|
||||
ctx.builder.build_store(counter, size_t.const_int(u64::max_value(), true));
|
||||
let len = ctx
|
||||
|
@ -657,7 +655,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
|
|||
let mut final_data = None;
|
||||
let has_cleanup = !finalbody.is_empty();
|
||||
if has_cleanup {
|
||||
let final_state = generator.gen_var_alloc(ctx, ptr_type.into(), Some("try.final_state.addr"))?;
|
||||
let final_state = generator.gen_var_alloc(ctx, ptr_type.into())?;
|
||||
final_data = Some((final_state, Vec::new(), Vec::new()));
|
||||
if let Some((continue_target, break_target)) = ctx.loop_target {
|
||||
let break_proxy = ctx.ctx.append_basic_block(current_fun, "try.break");
|
||||
|
@ -823,7 +821,7 @@ pub fn gen_try<'ctx, 'a, G: CodeGenerator>(
|
|||
ctx.builder.position_at_end(handler_bb);
|
||||
if let Some(name) = name {
|
||||
let exn_ty = ctx.get_llvm_type(generator, type_.as_ref().unwrap().custom.unwrap());
|
||||
let exn_store = generator.gen_var_alloc(ctx, exn_ty, Some("try.exn_store.addr"))?;
|
||||
let exn_store = generator.gen_var_alloc(ctx, exn_ty)?;
|
||||
ctx.var_assignment.insert(*name, (exn_store, None, 0));
|
||||
ctx.builder.build_store(exn_store, exn.as_basic_value());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue