codegen: emit vardecl initializer

This commit is contained in:
Luna 2019-09-27 22:49:33 -03:00
parent d235ce0d13
commit 81fd718403

View file

@ -339,7 +339,6 @@ pub const Codegen = struct {
_ = llvm.LLVMBuildUnreachable(builder);
},
// TODO
.VarDecl => |vardecl| {
// we alaready inferred the type of the variable in the
// analyze pass and the current scope contains the variable's
@ -352,14 +351,15 @@ pub const Codegen = struct {
var fn_symbol = self.getFnSymbol(self.current_function_name.?);
_ = llvm.LLVMBuildAlloca(
// TODO add llvm value ref to var metadata as well
var variable = llvm.LLVMBuildAlloca(
builder,
try self.typeToLLVM(var_metadata.typ),
name_cstr.ptr,
);
// TODO generate the store for the initializer
//var llvm_expr = try self.emitExpr(vardecl.value);
var llvm_expr = try self.emitExpr(builder, vardecl.value);
_ = llvm.LLVMBuildStore(builder, llvm_expr, variable);
},
else => {