summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-26 23:59:38 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2025-01-26 23:59:38 +0100
commitd0f4fbbfb9d2896141fe1d7d9ada7a54253881fd (patch)
tree86e08463fd5b54d1728c5712ab069d86c72249ce
parentCodegen: PoC cleanup (diff)
downloadinterpreter-d0f4fbbfb9d2896141fe1d7d9ada7a54253881fd.tar.gz
interpreter-d0f4fbbfb9d2896141fe1d7d9ada7a54253881fd.tar.bz2
interpreter-d0f4fbbfb9d2896141fe1d7d9ada7a54253881fd.zip
Codegen: PoC hello world
-rw-r--r--src/codegen.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 9adca93..d10aa88 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -65,6 +65,19 @@ pub const CodeGen = struct {
         const main_entry = core.LLVMAppendBasicBlock(main_func, "entrypoint");
         core.LLVMPositionBuilderAtEnd(builder, main_entry);
 
+        const format_str = "Hello, World!\n";
+        const format_str_ptr = core.LLVMBuildGlobalStringPtr(builder, format_str, "format_str_ptr");
+
+        var print_function_params = [_]types.LLVMTypeRef{
+            core.LLVMPointerType(core.LLVMInt8Type(), 0),
+        };
+        const print_func_type = core.LLVMFunctionType(core.LLVMVoidType(), &print_function_params, print_function_params.len, 0);
+        const print_func = core.LLVMAddFunction(self.llvm_module, "printf", print_func_type);
+        var print_func_args = [_]types.LLVMValueRef{
+            format_str_ptr,
+        };
+        _ = core.LLVMBuildCall2(builder, print_func_type, print_func, &print_func_args, print_func_args.len, "print_call");
+
         var exit_func_params = [_]types.LLVMTypeRef{
             core.LLVMInt32Type(),
         };