Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a compiler back-end to generate assembly for user defined hw architecture, from C code

I am working on a project where I have to define a new processor hardware architecture. I need a compiler to generate assembly code for this target (it has its own instruction set).

Programs for this processor will be written in C.

My idea to do this is to parse the C code and generate an Abstract Syntax Tree (AST), then from the AST generate the assembly.

Certainly I'd like to reuse existing components (no need to rewrite a C parser I hope), but what tools or frameworks may I use to accomplish this task?

Thanks.

like image 766
Vincenzo Pii Avatar asked Jan 18 '23 07:01

Vincenzo Pii


1 Answers

Take a look at LLVM.

It consists of seperate modules which can be created individually and communicate through an intermediate language. In you're case you'll have to write the assembly back-end and reuse other people's C compiler.

like image 70
orlp Avatar answered Jan 20 '23 20:01

orlp