EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

C to assembly compiler - How do I handle this situation?

Started by Kris Neot July 4, 2005
My simple CPU will be designed to customly fit my decoding, thus requiring a
custom
instruction set. I need a compiler that can "take in my instruction set" and
compile the
RS decoding software (in generic C) into assembly codes. Is this possible?



On Mon, 4 Jul 2005 18:22:01 +0800, "Kris Neot" <Kris.Neot@hotmail.com>
wrote:

>My simple CPU will be designed to customly fit my decoding, thus requiring a >custom >instruction set. I need a compiler that can "take in my instruction set" and >compile the >RS decoding software (in generic C) into assembly codes. Is this possible?
Yes. The Gnu compilers (gcc) have a generic front-end and a processor specific back-end. If you don't want to tackle re-targeting a gcc cross-compiler, there are other options. You could start from another small device compiller like BDS C http://www.bdsoft.com/resources/bdsc.html or the Small Device C Compiler http://sdcc.sourceforge.net/ and change the back-end to emit your specific machine code. Or, go the lex/yacc route and write your own parser and generator. Level of difficulty = high if you want to create a fully compliant C99 compiler. Much lower if you can get away with a C-like language subset. -- Rich Webb Norfolk, VA
On Mon, 4 Jul 2005 18:22:01 +0800 in comp.arch.embedded, "Kris Neot"
<Kris.Neot@hotmail.com> wrote:

>My simple CPU will be designed to customly fit my decoding, thus requiring a >custom >instruction set. I need a compiler that can "take in my instruction set" and >compile the >RS decoding software (in generic C) into assembly codes. Is this possible?
Here are some possibilities: http://sdcc.sourceforge.net/ Small Device C Compiler http://gcc.gnu.org/ The GCC compiler http://anyc.sourceforge.net/ Any C http://www.cs.princeton.edu/software/lcc/ lcc, A Retargetable Compiler for ANSI C http://www.bloodshed.net/c/smallc22.zip Small C Compiler http://www.tendra.org/ The TenDRA project hope that helps Joe
On Mon, 4 Jul 2005 18:22:01 +0800, Kris Neot wrote:

>My simple CPU will be designed to customly fit my decoding, thus requiring a >custom >instruction set. I need a compiler that can "take in my instruction set" and >compile the >RS decoding software (in generic C) into assembly codes. Is this possible?
If I read this correctly, you have a C program that needs to be converted to a new assembly language. Don't you also need an assembler? Anyway, it sounds like a fair amount of work. The OpenWatcom C/C++/Fortran compilers have a frontend and a (tighly coupled, no intermediate language) codegenerator, which outputs object code directly (not assembler). A new code generator could be created, but it is not for the faint-hearted - expect a fair amount time studying the current implementations. If your assembly looks like one of those for the x86, Dec Alpha, PPC or MIPS CPUs you have something to start from. If you decide to extend OpenWatcom, visit the 'contributors' group at news.openwatcom.org Mat Nieuwenhoven


Kris Neot wrote:

>My simple CPU will be designed to customly fit my decoding, >thus requiring a custom instruction set. I need a compiler >that can "take in my instruction set" and compile the >RS decoding software (in generic C) into assembly codes. >Is this possible?
It is possible, but not wise. Writing or adapting a compiler is a lot of work, but the reward at the end is the ability to turn any C program into an executable that runs on your chip. If you only need one program, hire a human with the right skills (or learn them yourself) and have him do the "compiling" by hand. I would also question the need for a custom instruction set. Could you explain why you think that no standard architecture will do the job for you?
On Mon, 4 Jul 2005 18:22:01 +0800, "Kris Neot" <Kris.Neot@hotmail.com>
wrote:

>My simple CPU will be designed to customly fit my decoding, thus requiring a
Decoding of what?
>custom >instruction set. I need a compiler that can "take in my instruction set" and >compile the >RS decoding software (in generic C) into assembly codes.
What is RS decoding? Reed-Solomon decoding?
>Is this possible?
Of course anything is possible, but just how "simple" is this CPU? Depending on how much code you're going to write for it, I wouldn't even bother creating an assembler. Just use equates and macros written for an assembler for another micro to create the object code for your CPU. Have a macro for each instruction mnemonic. ----- http://www.mindspring.com/~benbradley
Kris Neot wrote:

> My simple CPU will be designed to customly fit my decoding, thus requiring a > custom > instruction set. I need a compiler that can "take in my instruction set" and > compile the > RS decoding software (in generic C) into assembly codes. Is this possible?
Let me make sure I understand... You're clever enough to design your own CPU, but you're not motivated to port the C code that the CPU must run over to it's assembly language? It seems to me that if you are so interested in performace that you build your own CPU, you'd be concerned with inefficiencies introduced with translating the C code to assembly.
"Mat Nieuwenhoven" <mnieuw@dontincludethis.zap.a2000.nl> wrote in message
news:zavrhjqbagvapyhqrguvfmncnay.ij4jd10.pminews@news.text.chello.nl...
> On Mon, 4 Jul 2005 18:22:01 +0800, Kris Neot wrote: > > >My simple CPU will be designed to customly fit my decoding, thus
requiring a
> >custom > >instruction set. I need a compiler that can "take in my instruction set"
and
> >compile the > >RS decoding software (in generic C) into assembly codes. Is this
possible?
> > If I read this correctly, you have a C program that needs to be converted
to
> a new assembly language. Don't you also need an assembler? > Anyway, it sounds like a fair amount of work. The OpenWatcom C/C++/Fortran > compilers have a frontend and a (tighly coupled, no intermediate language) > codegenerator, which outputs object code directly (not assembler). A new
code
> generator could be created, but it is not for the faint-hearted - expect a > fair amount time studying the current implementations. If your assembly
looks
> like one of those for the x86, Dec Alpha, PPC or MIPS CPUs you have
something
> to start from. If you decide to extend OpenWatcom, visit the
'contributors'
> group at news.openwatcom.org > > Mat Nieuwenhoven > >
Thank you Mat. I was aware that one can write an assembler in Perl or Tcl, thus, it won't be a difficulty for me since the methodology is predictable and known to me. Compiler is all new to me. I think, my instruction set will be a subset of 8086 (all expanded to 32-bit wide), removing some instructions like RRC, etc, and invent something like 32-bit multiplier and xor, hardware look up table (8b in/8b out), etc.
"Ben Bradley" <ben_nospam_bradley@frontiernet.net> wrote in message
news:4svic1dmpp20k081oqhd3gennl1loif6le@4ax.com...
> On Mon, 4 Jul 2005 18:22:01 +0800, "Kris Neot" <Kris.Neot@hotmail.com> > wrote: > > >My simple CPU will be designed to customly fit my decoding, thus
requiring a
> > Decoding of what? > > >custom > >instruction set. I need a compiler that can "take in my instruction set"
and
> >compile the > >RS decoding software (in generic C) into assembly codes. > > What is RS decoding? Reed-Solomon decoding? > > >Is this possible? > > Of course anything is possible, but just how "simple" is this CPU? > Depending on how much code you're going to write for it, I wouldn't > even bother creating an assembler. Just use equates and macros written > for an assembler for another micro to create the object code for your > CPU. Have a macro for each instruction mnemonic. > > > ----- > http://www.mindspring.com/~benbradley
Yes, Reed Solomon codes. I think it will make a pretty handsome opencores.org project to demonstrate all my skills. :)
"Jim Stewart" <jstewart@jkmicro.com> wrote in message
news:772dnUKtL-a9K1TfRVn-sA@comcast.com...
> Kris Neot wrote: > > > My simple CPU will be designed to customly fit my decoding, thus
requiring a
> > custom > > instruction set. I need a compiler that can "take in my instruction set"
and
> > compile the > > RS decoding software (in generic C) into assembly codes. Is this
possible?
> > Let me make sure I understand... > > You're clever enough to design your own CPU, > but you're not motivated to port the C code > that the CPU must run over to it's assembly > language? > > It seems to me that if you are so interested > in performace that you build your own CPU, > you'd be concerned with inefficiencies > introduced with translating the C code to > assembly. > > >
Ok, I am hardware engineer, much of my previous work in designing ASIC and FPGA, designing a 32-bit CPU that uses ARM instrctions is only a matter of time for me. However translating C into ARM codes is new to me and I would like to spend more time on the hardware part. Also, RS decoding isn't easy either. My question is, is it likely that any compiler allows limiting the choice of assembly codes?

The 2024 Embedded Online Conference