rui314 / 8cc

A Small C Compiler
MIT License
6.13k stars 740 forks source link

Portability #17

Closed andrewchambers closed 9 years ago

andrewchambers commented 9 years ago

Are you interested in any ports of 8cc? i386 would test that 8cc code generators can handle 32 bit code.

If you feel like working on it for fun I'd be willing to help in my spare time. I think that 8cc is probably the best option for hobbyists who need a toy c compiler for invented processors, but 8cc is pretty x86_64 specific at the moment.

In terms of design I would go for a design the same way the plan9 c compilers are done, without conditional compilation but separate binaries.

rui314 commented 9 years ago

I'm interested in porting this stuff to other architectures. It would be fun. 8cc is currently not portable at all; the code generator generates x86-64 assembly, and the parser assumes LP64 (long and pointer are 64 bit).

I agree that the plan 9 design looks better than the others.

However I don't think now is the right time. I'm doing a major rewrite of the parser, which will radically change the intermediate data format used between the parser and the code generator. If we had two backends, I would have to update the two.

andrewchambers commented 9 years ago

Sounds good. maybe there needs to be an 8as ;).

Off topic: But what are your goals in your rewrite? improved diagnostics? error recovery? or something else altogether.

edit: looks like you are making the front end do more work so the back end doesn't need to. I approve this as it will make porting easier anyway..

rui314 commented 9 years ago

My current goal is to fix miscomiples due to the code generator. The codegen's code is messy, and the reason of that is because the data it needs to handle is not structured well. So this is a part of the parser issue, and a part of the codegen issue.

I'm trying to flatten the AST by expanding all compound literals and nested structures. In other words I'm making changes to the parser so that it will create a list of quadruples. For example,

int x; if (x) { x = foo() + bar(); } else { x = bar(); }

will be read as

var x type int var $a type int var $b type int var $c type int $a = x if x: L1 goto L2 L1: $b = funcall(bar) $c = funcall(foo) x = $b + $c goto L3 L2: x = funcall(bar) L3:

Eventually I'd like to do SSA conversion on this, but it's a future plan.