[z88dk-dev] llvm front-end from sdcc devs

Bridge to the z88dk-developers mailing list
Post Reply
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

[z88dk-dev] llvm front-end from sdcc devs

Post by alvin »

If you don't follow their mailing list:
https://sourceforge.net/p/sdcc/mailman/ ... /35382805/

It's a crazy idea that deserves some attention. Although llvm is being used to generate C that is then compiled normally using sdcc (or sccz80 if it can do it), in the case of C to C translation, llvm may be doing more optimizations than sdcc currently. But even more interestingly you could use llvm to translate other languages to C which is then compiled per normal for the z80.

The caveat is that the current llvm usage cannot understand sdcc attributes like z88dk_fastcall, z88dk_callee, preserves_regs, smallc and sdcc cannot compile all llvm c code as llvm completely supports c standards including features not supported by sdcc.

However I don't think these are problems for us, not counting the missing smallc attribute which the llvm front end will not be generating without changes. (This is a problem for the way the classic c lib compiles sdcc code currently but the new c lib compiles don't use smallc).

We make add all the z88dk_fastcall, z88dk_callee, preserves_regs attributes to the library code at the sdcc compile level. Which means an llvm->sdcc compile will automatically gain benefit from z88dk_fastcall, z88dk_callee, preserves_regs in library code. User code, however, will not be able to use those attributes in C fed through llvm. However you can mix llvm and sdcc/sccz80 code so if the user has some functions using z88dk_fastcall, z88dk_callee, preserves_regs he can compile that directly with sdcc/sccz80 and do the rest via llvm.

Anyway I think it is fairly easy to add quickly to the new c lib side at least. It might be quite interesting to see how far we can go with Pascal / Fortran / C++ etc compilation.



------------------------------------------------------------------------------
Philipp Klaus Krause

Post by Philipp Klaus Krause »

If you want to test the LLVM-based toolchain, beware of these three
bugs, which I ran into already, so they are probably a common problem
(There might well be more that I haven't found yet):

https://sourceforge.net/p/sdcc/bugs/2551/
https://sourceforge.net/p/sdcc/bugs/2548/
https://github.com/Ace17/llvm-cbe/issues/3

Philipp


------------------------------------------------------------------------------
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Yes cheers. I will try to find time to look at it this weekend. If things work out I will put a zcc front end on it and we can try llvm compilation.

Is anyone else having a look?



------------------------------------------------------------------------------
Philipp Klaus Krause

Post by Philipp Klaus Krause »

Since it consists of multiple projects, and neither one seemed the right
place for putting the information for the whole toolchain, I've put up a
simple website for the toolchain:

http://www.colecovision.eu/llvm+sdcc/

For now it just has basic instructions for building and using the
LLVM+SDCC toolchain (with examples for C and STM8). I might extend it
with more information / content later.

Philipp


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Thanks Philip. I'll try to put together the time to finish this off in the next couple of days. What we will need are windows and mac osx binaries so that llvm and cbe can be packaged for those targets. Do you intend to build that sort of thing for sdcc? If not, I'll try to get it compiling here.

I don't think there are any technical issues for either the new c lib or the classic one, except that llvm must be given plain headers without any attributes (no fastcall, callee, etc). For the new c lib this is easy since the headers are generated from a common prototype using a script. For the classic lib I think there may be some work involved but I will do this for the new c lib first and we can see how well it goes.

The first step is C to C translation by llvm/cbe using the plain headers. But then the second step is sdcc to z80 using the sdcc headers so all the fastcall/callee goodness in the library will still be present in llvm compiles.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Post Reply