To allow the use of langauges other than C and to evaluate the effect of LLVM optimizations for 8-bit targets, I created an experimental toolchain that allows the use of LLVM clang and opt with 8-bit microcontrollers via the LLVm C backend and SDCC.
The toolchain is still in a very early stage and likely has many issues, especially around corner cases. How to get it working: * Install SDCC * Install LLVM 3.8 (e.g. using apt-get on Debian). * Get my cfe fork (https://github.com/spth/clang) and build it (e.g. mkdir build; cmake ..; make) * Get the cbe fork (https://github.com/Ace17/llvm-cbe) and build it (see instructions in README.md) To compile a test.c C file with it for STM8: * Compile C source to LLVM IR: clang/build/bin/clang -fno-signed-char -target sdcc-stm8 -S -emit-llvm -isystem /usr/local/share/sdcc/include test.c This should give you a test.ll file * Compile LLVM IR to C: llvm-cbe/bin/llvm-cbe test.ll This should give you a test.cbe.c file * Compile to binary: sdcc -msmt8 test.cbe.c The above process should result in a working binary file just as if the original C file had been compiled with SDCC directly. However the binary will probably be less optimized as SDCC is not yet able to optimize out all the overhead generated in the translations. But if you optimize the LLVM IR before converting it to C, you might well get a more optimized result than with plain SDCC. To optimize, use e.g. opt-3.8 -O2 The files compiled using the above process can be freely linked with files compiled using SDCC directly. Known issues: * No support for SDCC extensions in clang * Probably different compiler-defined behaviour in some corner cases * No support for some features that are not supported by SDCC (most prominently variable-length arrays and alloca()). * Only stm8, z80, z180, gbz80, r2k, r3ka, tlcs90 SDCC backends supported. Untested: * Support for languages other than C * floating-point support Philipp ------------------------------------------------------------------------------ _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user