Reputation: 3205
I'm writing a compiler in OCaml that compiles to LLVM IR. The current program is very simple:
num main() {
return 0;
}
When I run it with my compiler, I get the following LLVM IR code:
; ModuleID = 'PixMix'
source_filename = "PixMix"
@fmt = private unnamed_addr constant [4 x i8] c"%d\0A\00"
@fmt.1 = private unnamed_addr constant [4 x i8] c"%s\0A\00"
declare i32 @printf(i8*, ...)
define double @main() {
entry:
ret double 0.000000e+00
}
However, if I pass it to lli
, I'm told that the return type is invalid. Looking at that code, main
is defined as a double
and it's returning a double
, so why is lli
telling me that the return type is messed up?
Upvotes: 2
Views: 444
Reputation: 37227
The issue is that the entry point function (main
by default, but the name can be controlled by the -entry-function
flag) is expected to have a certain signature, similar to what main
looks like in C or C++. In particular, it should either return void
or an integer type. You can read the implementation of the check to make sure the IR you generate satisfies it.
Upvotes: 2