fix llvm_table shenanigans
This commit is contained in:
parent
2357de5a04
commit
5771877457
1 changed files with 7 additions and 4 deletions
|
@ -176,12 +176,14 @@ pub const Codegen = struct {
|
||||||
.Call => |call| {
|
.Call => |call| {
|
||||||
const name = call.callee.*.Variable.lexeme;
|
const name = call.callee.*.Variable.lexeme;
|
||||||
|
|
||||||
var llvm_func = self.llvm_table.get(name);
|
var llvm_func_entry = self.llvm_table.getEntry(name);
|
||||||
if (llvm_func == null) {
|
if (llvm_func_entry == null) {
|
||||||
std.debug.warn("Function '{}' not found\n", .{name});
|
std.debug.warn("Function '{}' not found\n", .{name});
|
||||||
return CompileError.EmitError;
|
return CompileError.EmitError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const llvm_func = llvm_func_entry.?.value;
|
||||||
|
|
||||||
var args = LLVMValueList.init(self.allocator);
|
var args = LLVMValueList.init(self.allocator);
|
||||||
errdefer args.deinit();
|
errdefer args.deinit();
|
||||||
|
|
||||||
|
@ -194,7 +196,7 @@ pub const Codegen = struct {
|
||||||
|
|
||||||
return llvm.LLVMBuildCall(
|
return llvm.LLVMBuildCall(
|
||||||
builder,
|
builder,
|
||||||
llvm_func.?,
|
llvm_func,
|
||||||
args_slice.ptr,
|
args_slice.ptr,
|
||||||
@intCast(c_uint, args_slice.len),
|
@intCast(c_uint, args_slice.len),
|
||||||
"call",
|
"call",
|
||||||
|
@ -432,7 +434,8 @@ pub const Codegen = struct {
|
||||||
);
|
);
|
||||||
|
|
||||||
var func = llvm.LLVMAddFunction(mod, name_cstr.ptr, llvm_ret_type);
|
var func = llvm.LLVMAddFunction(mod, name_cstr.ptr, llvm_ret_type);
|
||||||
_ = try self.llvm_table.put(name, func);
|
std.debug.warn("inserting function '{}' to llvm table\n", .{name});
|
||||||
|
try self.llvm_table.put(name, func);
|
||||||
|
|
||||||
var buf = try self.allocator.alloc(u8, 512);
|
var buf = try self.allocator.alloc(u8, 512);
|
||||||
var entry_lbl = try std.fmt.bufPrint(buf, "fn_{}_entry", .{name});
|
var entry_lbl = try std.fmt.bufPrint(buf, "fn_{}_entry", .{name});
|
||||||
|
|
Loading…
Reference in a new issue