[dev][announce] Optimizing C compiler & c++ compiler/runtime

From: Rob <robpilling_AT_gmail.com>
Date: Fri, 20 Dec 2013 18:06:07 +0000 (GMT)

Paul Onyschuk wrote:
> On Fri, 20 Dec 2013 13:49:43 +0100
> Sylvain BERTRAND <sylware_AT_legeek.net> wrote:
>
>> There is also the question of finding a new C99 optimizing
>> compiler written properly in C of course.
>>
>> Anything else?
>
> On one hand, you can use pretty old GCC and most of C codebase will
> compile just fine (OpenBSD still uses patched GCC v4.2.1, which is more
> than six years old). C is stable - you will more likely see changes in
> standard C library, than compiler/language itself. GCC v4.7.x should
> work just fine for some years to come.
>
> The last problem: C99-capable compiler isn't enough to get usable
> system based on Linux. Clang which was designed as GCC drop-in
> replacement chokes on Linux kernel (some patches are needed), because
> it heavily uses GCC extensions and specific features (some
> undocumented/undefined).
>
> PCC/TCC aren't actively developed, I'm not sure about the status of
> firm/CParser. Still those alternative C compilers are just good
> enough for specific programs and not larger set of packages.

I suppose if you can get a stable version of GCC, like you say, the
platform ABIs aren't going to change, but I can see certain things from
C11 coming into libraries, such as atomics. Of course glibc (should)
support all the way back to C89. Not sure if musl is C99 and above or
not.

pcc is pretty much dead but there's active development on tcc, both
bug-fixes and work on the ARM ABI code. However I find bugs can easily
sneak in due to its very small test suite and somewhat hard to
understand / strongly coupled code. Still, speed-wise it goes like a
stabbed rat.

I've been working on a C compiler in my spare time and recently finished
floating point support (minus long doubles). My aim has been to have a
simple and easy to understand code base and little bloat, while
supporting common extensions, such as emitting the middle term in ?:
expressions, __asm__, __typeof__ and so on.

The code generation beats tcc's and can usually match or beat gcc and
clang's -O0 level in plenty of cases, which I find to be a good balance
for now. There's plenty of room for improvement in the backend.

The main features left before I can proclaim C99 support are passing and
returning structs/unions by value, and VLAs *shudder*.

It targets primarily x86_64 and can target x86 (experimental/32-bit) but
32-bit support for 'long long' and x87 floating point stack support are
lacking (which is the same reason why long double isn't supported on
x86_64 yet). There's also a MIPS backend but this hasn't been tested and
is out of date.

Alongside this, I'm now at a stage where I can work on getting it to
bootstrap. I'm currently held back by a bug in the preprocessor when
handling glibc/Debian's unistd.h and it also looks like I'll need to
support GNU's transparent union extension too.

If anyone's interested. It's hosted here [1] and I'm all ears to
critiques and feedback.

Thanks,
Rob

1: https://github.com/bobrippling/ucc-c-compiler
Received on Fri Dec 20 2013 - 19:06:07 CET

This archive was generated by hypermail 2.3.0 : Fri Dec 20 2013 - 19:12:14 CET