3
votes

I'm working on LLVM/Clang fork (for AVR). How can i force Clang Driver to use LLVM assembler instead of system one?

MBA-Anton:bin asmirnov$ ./clang++ -I/Applications/avr.app/Contents/Resources/Java/hardware/avr/cores/avr -I/Applications/avr.app/Contents/Resources/Java/hardware/avr/variants/standard /var/folders/64/fwfkm1k51zbd4_c5lwpsbljh0000gn/T/build5450310618632673119.tmp/Blink.cpp -o /tmp/Blink.avr.hex -I /Applications/avr.app//Contents/Resources/Java/hardware/tools/avr/avr/include/ --target=avr -O1 -v

And it uses LLVM clang compiler (not system, correct):

clang version 3.6.0 (https://github.com/4ntoine/clang.git 0d08deedd548d964f63cf896ae9acb8d878a5fd8)     (https://github.com/dylanmckay/avr-llvm.git 447b58bced825fa7bea31f3882f277535cc9fca6)
Target: avr
Thread model: posix
"/Users/asmirnov/Documents/dev/src/llvm_dylan/installed/bin/clang" -cc1 ...

But system assembler (incorrect):

"/usr/bin/as" -o ...

It should use LLVM's llvm-as as it "knows" AVR target (opcodes, etc). How can i force it use LLVM's assembler?

1
Can you try passing the -integrated-as option and check again? If it works, I will post it as an answer.mmtauqir
with -integrated-as it starts using g++ and system linker (ld) after clang compiler for some reason: "/usr/bin/g++" ... "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" ... and it's completely incorrect4ntoine
after further investigation i've found using integrated assembler was correct answer. The only difference i had to override toolchain method to use integrated assembler by default4ntoine

1 Answers

0
votes

You can use clang to emit LLVM IR code by using the option -emit-llvm.

Let's say you want to compile a C file into LLVM IR:

clang -emit-llvm -c file.c

It will create a LLVM bytecode file file.bc. You will be able to compile the file with llc.