On 21.09.2016 17:27, Philipp Klaus Krause wrote: > 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
For opt-3.8, sdcc-stm8 (or sdcc-z80 or whatever) is an unknown target triple, so it assumes the host architecture. This breaks the simplification of libcalls, since e.g. some printf() calls get converted to putchar(), but we get a putchar() that takes a 32-bit int. This results in stack corruption later. For now, I recommend to use opt-3.8 -O2 -disable-simplify-libcalls -S Philipp ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user