[LLVMdev] llvm-gcc and -emit-llvm
dpatel at apple.com
Wed Jun 11 07:46:43 PDT 2008
On Jun 9, 2008, at 11:32 AM, Jonathan Turner wrote:
> Just thought I'd mention this to keep other people from stubbing
> their toes on it...
> Using llvm-gcc/llvm-g++ and -emit-llvm, you need to make sure to
> pass -S as well, like so:
> ./llvm-g++ -S -emit-llvm hello.cpp
> not: /llvm-g++ -emit-llvm hello.cpp
> I'm sure that's old news to most of the people on the list, but I
> thought it couldn't hurt to mention it in case other people happen
> upon it.
> A question might be, can the -emit-llvm emit the llvm first before
> it goes into the linking phase? That way the users can at least get
> something on the screen of what they're looking for, or maybe a
> warning saying "to emit llvm, you need to pass the -S flag"?
This logic is follows gcc tool chain. If you want to read llvm IR
then you follow the steps to get assembly text file from the compiler,
but add one additional flag.
$ gcc -c foo.cpp <---- gcc generates binary object file.
$ gcc -S foo.cpp <---- gcc generates human readable assembly file.
$ llvm-gcc --emit-llvm -c foo.cpp <---- llvm-gcc generates binary
llvm IR file.
$ llvm-gcc --emit-llvm -S foo.cpp <---- llvm-gcc generates human
readable LLVM IR file.
$ gcc foo.cpp -o foo <--- gcc generated binary object file is linked
by the linker to generate final binary.
$ llvm-gcc --emit-llvm foo.cpp -o foo <--- llvm-gcc generated binary
LLVM IR file is linked by the linker to generate final binary. This
requires the linker that accepts LLVM IR.
More information about the llvm-dev