Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Clang accept LLVM IR or bitcode via pipe?

Tags:

clang

llvm-ir

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?

like image 851
davidglanzman Avatar asked Jul 11 '14 15:07

davidglanzman


People also ask

Does Clang use LLVM?

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.

Is LLVM same as Clang?

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.

Is LLVM IR cross platform?

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.

Which linker does Clang use?

Clang can be configured to use one of several different linkers: GNU ld. GNU gold. LLVM's lld.


1 Answers

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).

like image 110
Kyle Lacy Avatar answered Oct 16 '22 02:10

Kyle Lacy