Skip to content

Commit c7dadf8

Browse files
authored
fix(codegen): update ty size_of and local allocations (#4)
2 parents ab4696d + f62afca commit c7dadf8

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/passes/codegen.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ impl<'ctx, 'mir, 'ink> Codegen<'ctx, 'mir, 'ink> {
119119

120120
// Declare all locals.
121121
for (i, (binding, ty)) in function.locals.iter().enumerate() {
122+
let ink_ty = self.basic_ty(*ty);
122123
let alloca = match binding {
123124
Some(binding) => builder.build_alloca(
124-
self.basic_ty(*ty),
125+
ink_ty,
125126
self.ctx.strings.get(self.ctx.scopes.to_string(*binding)),
126127
),
127-
None => builder.build_alloca(self.basic_ty(*ty), format!("local_{i}").as_str()),
128+
None => builder.build_alloca(ink_ty, format!("local_{i}").as_str()),
128129
}
129130
.unwrap();
130131

src/ty/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ impl Types {
116116
Type::I8 => 1,
117117
Type::U8 => 1,
118118
Type::Boolean => 1,
119-
Type::Ref(_) => todo!("pointer size"),
120-
Type::Function { .. } => todo!("pointer size"),
119+
// WARN: Should be linked to target.
120+
Type::Ref(_) => std::mem::size_of::<usize>(),
121+
// WARN: Should be linked to target.
122+
Type::Function { .. } => std::mem::size_of::<usize>(),
121123
Type::Tuple(type_ids) => type_ids.clone().iter().map(|ty| self.size_of(*ty)).sum(),
122124
}
123125
}

0 commit comments

Comments
 (0)