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

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?

Reply to
Kris Neot
Loading thread data ...

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

formatting link
or the Small Device C Compiler
formatting link
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
Reply to
Rich Webb

Here are some possibilities:

formatting link
Small Device C Compiler
formatting link
The GCC compiler
formatting link
Any C
formatting link
lcc, A Retargetable Compiler for ANSI C
formatting link
Small C Compiler
formatting link
The TenDRA project

hope that helps

Joe

Reply to
Joseph Power

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

Reply to
Mat Nieuwenhoven

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?

Reply to
Guy Macon

Decoding of what?

What is RS decoding? Reed-Solomon decoding?

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.

-----

formatting link

Reply to
Ben Bradley

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.

Reply to
Jim Stewart

requiring a

and

possible?

to

code

looks

something

'contributors'

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.

Reply to
Kris Neot

requiring a

and

Yes, Reed Solomon codes. I think it will make a pretty handsome opencores.org project to demonstrate all my skills. :)

Reply to
Kris Neot

requiring a

and

possible?

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?

Reply to
Kris Neot

requiring a

and

possible?

Compiler for ANSI C

project

Thank you Joe, I will read them.

Reply to
Kris Neot

requiring a

and

possible?

Thank you Rich, your information is of much use to me.

Reply to
Kris Neot

Yes, I am sure there is, but it's daunting job to fully implement an instruction set when some of them are not necessary.

Reply to
Kris Neot

Then how about implementing a Trap/SWI, on non-covered opcodes, so you can do them in SW, should you ever strike one.

That allows a std tool flow, for whatever CPU you choose to subset, and you code to avoid the inefficent ones, but it is not a drop-dead if you do hit them. For the new opcodes, you can use Macros, or carefull ASM mapping.

You could also look at Randall Hyde's High level Assembler.

formatting link
for a very good example, of what CAN be done in the space between vanilla assemblers, and Compilers.

-jg

Reply to
Jim Granville

I read in your other posts that you're a hardware engineer. I suggest you stay away from Watcom then for this project, it is way too complicated to add a new CPU. I guess an experienced C programmer unfamiliar with Watcom would need many months to fully add a new hardware platform, and that is after it is available. Not worth it for a single project.

Mat Nieuwenhoven

Reply to
Mat Nieuwenhoven

Take some care with this part: ARM are pretty strict about what they consider to be breaches of their intellectual property. However, if you were to do your re-implementation based solely on the correct published document, then you would probably be in the clear. In particular, I suggest you avoid all the Thumb stuff without checking for patents.

You want to look at gcc for this. (It's been a while, but:) if you remove the instructions from the "md" (machine description) file, then it won't generate them. Conversely, if you add new instructions, you can add template-based matching to select when to use your new instructions.

cheers, Rich.

--
rich walker         |  Shadow Robot Company | rw@shadow.org.uk
technical director     251 Liverpool Road   |
 Click to see the full signature
Reply to
Rich Walker

lcc (cited above and designed to be easily retargetable) usually requires only modest work to build a new machine description, if that's the direction the OP decides upon.

--Toby

Reply to
toby

As long as you do not try to sell the thing you have produced to anybody, there should be no problems of using patented designs in any country I know of.

The principle with patents has traditionally been that by publishing your idea you get in exchange an exclusive _commercial_ access right to it.

Paul

Reply to
Paul Keinanen

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.