so... jai :D

This commit is contained in:
agra
2026-02-04 01:34:30 +02:00
commit 55fc5790e4
60 changed files with 15876 additions and 0 deletions

25
src/builtins.zig Normal file
View File

@@ -0,0 +1,25 @@
const llvm = @import("llvm_api.zig");
const c = llvm.c;
pub const Builtins = struct {
printf_fn: c.LLVMValueRef,
calloc_fn: c.LLVMValueRef,
pub fn init(module: c.LLVMModuleRef, ctx: c.LLVMContextRef) Builtins {
const ptr_type = c.LLVMPointerTypeInContext(ctx, 0);
const i64_type = c.LLVMInt64TypeInContext(ctx);
const i32_type = c.LLVMInt32TypeInContext(ctx);
// Declare: int printf(const char*, ...)
var printf_params = [_]c.LLVMTypeRef{ptr_type};
const printf_type = c.LLVMFunctionType(i32_type, &printf_params, 1, 1);
const printf_fn = c.LLVMAddFunction(module, "printf", printf_type);
// Declare: void* calloc(size_t count, size_t size)
var calloc_params = [_]c.LLVMTypeRef{ i64_type, i64_type };
const calloc_type = c.LLVMFunctionType(ptr_type, &calloc_params, 2, 0);
const calloc_fn = c.LLVMAddFunction(module, "calloc", calloc_type);
return .{ .printf_fn = printf_fn, .calloc_fn = calloc_fn };
}
};