Skip to content

Commit

Permalink
call the special startup function
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 14, 2023
1 parent 86b69ab commit c1f6d55
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions self_hosted/create_llvm_ir.jou
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,18 @@ class AstToIR:
for i = 0; i < body->nstatements; i++:
self->do_statement(&body->statements[i])

def call_the_special_startup_function(self) -> None:
if WINDOWS:
name = "_jou_windows_startup"
elif MACOS:
name = "_jou_macos_startup"
else:
return

functype = LLVMFunctionType(LLVMVoidType(), NULL, 0, False as int)
func = LLVMAddFunction(self->module, name, functype)
LLVMBuildCall2(self->builder, functype, func, NULL, 0, "")

def define_function_or_method(self, funcdef: AstFunctionOrMethod*, self_type: Type*) -> None:
assert self->function_or_method_types == NULL
self->function_or_method_types = self->file_types->find_defined_function_or_method(funcdef->signature.name, self_type)
Expand All @@ -823,6 +835,9 @@ class AstToIR:
self->llvm_function = self->declare_function(sig)
self->new_block("start")

if (WINDOWS or MACOS) and strcmp(sig->name, "main") == 0 and not sig->is_method():
self->call_the_special_startup_function()

# Allocate all local variables at the start of the function.
assert self->n_local_vars == 0
assert self->local_vars == NULL
Expand Down

0 comments on commit c1f6d55

Please sign in to comment.