Giovanni Di Guardo
2007-May-16 12:33 UTC
[LLVMdev] Back End for a stack based architecture
Hi all, I was asked to write a C compiler back end for a dated stack based architecture, i.e. once whose instructions operate only on the top elements of a stack and doesn't use arguments, something like the JVM. I looked at some open source compilers (gcc, sdcc, tinyc and LLVM). To me LLVM seems promising (and I likes C++). Because I'm new here I need your help to understand if: 1) LLVM could be used to target stack based architecture 2) is possible but LLVM is not the best solution for that kind of architecture (in this case any hint for the rigth compiler is very appreciated) thanks, Giovanni
On 5/16/07, Giovanni Di Guardo <gdiguardo at gmail.com> wrote:> 1) LLVM could be used to target stack based architectureThere is nothing stopping you from doing so. Probably the common code generation infrastructure won't work for you without extra work. I suspect that you could either write a custom code generator (like the C backend) which doesn't use the common code generation stuff, or you could fake it. By that I mean, model your arch as a register based arch for instruction selection, then do a post pass over it to stackify it instead of running the normal register allocator. Andrew
If you want to get something up and running relatively quickly. You can model the backend after X86 X87 FP math. See X86InstrFPStack.td, X86FloatingPoint.cpp Basically add a fake register class and then "stackify" it with a post-allocation pass. Play around with it to see if something like this fits your need. Evan On May 16, 2007, at 5:33 AM, Giovanni Di Guardo wrote:> Hi all, > > I was asked to write a C compiler back end for a dated stack based > architecture, i.e. once whose instructions operate only on the top > elements of a stack and doesn't use arguments, something like the JVM. > > I looked at some open source compilers (gcc, sdcc, tinyc and LLVM). To > me LLVM seems promising (and I likes C++). > > Because I'm new here I need your help to understand if: > > 1) LLVM could be used to target stack based architecture > > 2) is possible but LLVM is not the best solution for that kind of > architecture (in this case any hint for the rigth compiler is very > appreciated) > > thanks, > > Giovanni > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev