From 97c386b7cd2d3074e8609513ef85218268635cb3 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 17 Jun 2024 17:03:14 +0200 Subject: Don’t create a new builder every iteration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/codegen.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/codegen.c b/src/codegen.c index dd21ad7..1db5625 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -20,8 +20,8 @@ static size_t codegenexpr(LLVMBuilderRef, struct ast, struct lexemes, void codegen(struct ast ast, struct lexemes toks) { - exit(EXIT_SUCCESS); LLVMModuleRef mod = LLVMModuleCreateWithName("oryx"); + LLVMBuilderRef builder = LLVMCreateBuilder(); for (size_t i = 0; i < ast.len;) { if (ast.kinds[i] != ASTCDECL) @@ -59,7 +59,6 @@ codegen(struct ast ast, struct lexemes toks) LLVMValueRef fn = LLVMAddFunction(mod, fnname, fnproto); LLVMBasicBlockRef entry = LLVMAppendBasicBlock(fn, "entry"); - LLVMBuilderRef builder = LLVMCreateBuilder(); LLVMPositionBuilderAtEnd(builder, entry); free(fnname); @@ -67,9 +66,10 @@ codegen(struct ast ast, struct lexemes toks) for (i = ast.kids[body].lhs; i <= ast.kids[body].rhs;) i = codegenstmt(builder, ast, toks, i); - LLVMDisposeBuilder(builder); } + LLVMDisposeBuilder(builder); + char *error = NULL; LLVMVerifyModule(mod, LLVMAbortProcessAction, &error); LLVMDisposeMessage(error); -- cgit v1.2.3