Reputation: 6403
I have been writing some verilog code to create simple microprocessor simulation that has its own instruction set. So far, I have been compiling all my code in head and using hex editors to produce binary files that can be used as starting program memory. Now I need to make some popular language (like C or BASIC) compilable into my instruction set, and as writing own compiler seems to be very difficult and longtime task, I'm looking for compiler that can be extended in some way or which´s source code can be simply rewritten for different instructions.
Is there any way to do this? Does such compiler exist?
Upvotes: 2
Views: 55
Reputation: 27962
With anything like C, that will be a very complex task. Even more complicated than writing a compiler of some simple language. However, if you want to go this way, look at GCC. It's open source and designed to be extensible for new platforms. Further, it supports combining multiple front-ends (programming languages) and back-ends (generators for target platforms).
However, if your activity is just to learn something and not actually design a new production microprocessor, I'd rather choose a subset of some simple language (such as Pascal) and write a simple compiler. You can end up with some 10k – 20k lines of code and will be a lot of fun as well.
Upvotes: 2
Reputation: 9377
You could write a backend for a retargetable compiler such as gcc or llvm. See, for example, http://llvm.org/docs/WritingAnLLVMBackend.html or http://gcc.gnu.org/onlinedocs/gccint/Back-End.html.
Upvotes: 4