Skip to content

Most things in LLVM are created through a static method call instead of directly using a constructor. One reason is that an existing object can be returned instead of creating a new instance.

"Create a FunctionType taking no parameters." A better translation would be: "Create a FunctionType taking no fixed/positional parameters."

After creating the function you get:

; ModuleID = 'uranium_module'
source_filename = "main.ura"

declare void @main()

After adding the basic block:

; ModuleID = 'uranium_module'
source_filename = "main.ura"

define void @main() {
main_block:
}

After adding the builder, the block and the return statement:

; ModuleID = 'uranium_module'
source_filename = "main.ura"

define void @main() {
main_block:
  ret void
}

And finally, after installing, compiling, reading docs and tutorials... I can compile the generated code!! I use 2> to redirect the stderr to a file. I redirect stderr because the output generated by our program in done by mainModule.dump(); and it writes to stderr.

make
./uc 2> main.ll
lli main.ll

And the output of the last command is... nothing! 🎉 Why is that a reason to celebrate? That's good because without the main function or without the return void statement the output was an execution error.

What's next?

I cannot check the correct behaviour of the generated code becase I'm not doing anything in our code. Returning and integer to check that the program is working properly will be the next step. See you in the next post!

References