codegen: emit load instruction for (now-stack) params
- comp_ctx: make ParameterMap use ptrs to Parameter
This commit is contained in:
parent
518d2daeb4
commit
21dcb3e65d
3 changed files with 15 additions and 7 deletions
BIN
hello
Executable file
BIN
hello
Executable file
Binary file not shown.
|
@ -236,11 +236,16 @@ pub const Codegen = struct {
|
||||||
return switch (metadata.using) {
|
return switch (metadata.using) {
|
||||||
.Function => blk: {
|
.Function => blk: {
|
||||||
var param = metadata.from_function.?.parameters.get(vari.lexeme).?.value;
|
var param = metadata.from_function.?.parameters.get(vari.lexeme).?.value;
|
||||||
// var llvm_func = self.llvm_table.get(self.current_function_name.?).?.value;
|
|
||||||
// break :blk llvm.LLVMGetParam(llvm_func, @intCast(c_uint, param.idx));
|
|
||||||
|
|
||||||
std.debug.warn("fn param alloca {} {}\n", param.name, param.llvm_alloca);
|
var buf = try self.allocator.alloc(u8, 512);
|
||||||
break :blk param.llvm_alloca.?;
|
errdefer self.allocator.free(buf);
|
||||||
|
|
||||||
|
var load_str = try std.fmt.bufPrint(buf, "{}_loaded", param.name);
|
||||||
|
|
||||||
|
var load_cstr = try std.cstr.addNullByte(self.allocator, load_str);
|
||||||
|
errdefer self.allocator.free(load_cstr);
|
||||||
|
|
||||||
|
break :blk llvm.LLVMBuildLoad(builder, param.llvm_alloca.?, load_cstr.ptr);
|
||||||
},
|
},
|
||||||
|
|
||||||
.Scope => @panic("TODO local variables"),
|
.Scope => @panic("TODO local variables"),
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub const Parameter = struct {
|
||||||
llvm_alloca: llvm.LLVMValueRef = null,
|
llvm_alloca: llvm.LLVMValueRef = null,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ParameterMap = std.StringHashMap(Parameter);
|
pub const ParameterMap = std.StringHashMap(*Parameter);
|
||||||
|
|
||||||
// functions, for our purposes, other than symbols, have:
|
// functions, for our purposes, other than symbols, have:
|
||||||
// - a return type
|
// - a return type
|
||||||
|
@ -274,11 +274,14 @@ pub const CompilationContext = struct {
|
||||||
var param_map = ParameterMap.init(self.allocator);
|
var param_map = ParameterMap.init(self.allocator);
|
||||||
|
|
||||||
for (decl.params.toSlice()) |param, idx| {
|
for (decl.params.toSlice()) |param, idx| {
|
||||||
_ = try param_map.put(param.name.lexeme, Parameter{
|
var param_sym = try self.allocator.create(Parameter);
|
||||||
|
|
||||||
|
param_sym.* = Parameter{
|
||||||
.name = param.name.lexeme,
|
.name = param.name.lexeme,
|
||||||
.idx = idx,
|
.idx = idx,
|
||||||
.typ = param_types.at(idx),
|
.typ = param_types.at(idx),
|
||||||
});
|
};
|
||||||
|
_ = try param_map.put(param.name.lexeme, param_sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
const lex = decl.func_name.lexeme;
|
const lex = decl.func_name.lexeme;
|
||||||
|
|
Loading…
Reference in a new issue