Clang can accept source files through a pipe if a language is specified with the -x
flag.
cat hello_world.c | clang -x c -o hello_world
Clang can also compile LLVM IR and bitcode to object files
clang hello_world.c -S -emit-llvm && clang -o hello_world hello_world.ll
I want to compile LLVM IR or bitcode passed via a pipe. However, I can't find any documentation on exactly what parameters the -x
option accepts. I can use c
, c++
, but clang doesn't recognize llvm
or bitcode
.
What can I give to -x
so Clang will accept IR or bitcode?
Clang uses the LLVM compiler as its back end and it has been included in the release of the LLVM since the LLVM 2.6. Clang is also built to be a drop-in replacement for GCC command. In its design, the Clang compiler has been constructed to work very similarly to GCC to ensure that portability is maximized.
LLVM is a backend compiler meant to build compilers on top of it. It deals with optimizations and production of code adapted to the target architecture. CLang is a front end which parses C, C++ and Objective C code and translates it into a representation suitable for LLVM.
LLVM IR can be cross-platform, with the obvious exceptions others have listed. However, that does not mean Clang generates cross-platform code. As you note, the preprocessor is almost universally used to only pass parts of the code to the C/C++ compiler, depending on the platform.
Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.
The language flag you're looking for is ir
. For example:
clang hello_world.c -S -emit-llvm -o - | clang -x ir -o hello_world -
works for me (clang version 3.5, trunk 200156).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With