aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2024-06-17 17:03:14 +0200
committerThomas Voss <mail@thomasvoss.com> 2024-06-17 17:03:14 +0200
commit97c386b7cd2d3074e8609513ef85218268635cb3 (patch)
treeec9ef53d8cfcacb6c48d423a015e19015e5c8d88 /src
parenta1657b2baebb8569395c1314bb1f9bdeab32ea6d (diff)
Don’t create a new builder every iteration
Diffstat (limited to 'src')
-rw-r--r--src/codegen.c6
1 files changed, 3 insertions, 3 deletions
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);