Re: How do I make my own custom C compiler?
- From: jacob navia <jacob@xxxxxxxxxxxxxxxx>
- Date: Thu, 08 Jun 2006 19:51:58 +0200
Giannis Papadopoulos a écrit :
Keith Thompson wrote:
"smnoff" <rhinohat@xxxxxxxxxxx> writes:
Ok, I am think I am a little more knowledgeable about C and pointers, ughh.
And likewise, I want to fix C.....and not so much to make a C++ or Java or C# or even D like language.
So, if I wanted to make my "custom" C compiler that's different that the current C99 or ANSI C, where would I start?
I'd start with an existing open-source compiler, such as gcc or lcc.
Isn't a bit risky to start with such a behemoth?
gcc is impossible to understand unles you spend at least
2-3 YEARS working in it full time.
There are at most 20 people on the world that can understand
that compiler, and by understanding I mean that they are
able to modify something in it, something basic like
the parser for instance.
I tried something much simpler: to fix a bug.
Under windows, when a function was _stdcall, it would screw
the floating point stack.
I spent two weeks trying to fix it, learning how it works,
etc.
The first problem is to know RTL. You have to completely understand
RTL to understand the flow of things.
Second, the sheer size of the code base. There are 13-15 MB
of C source code to understand. And the code is mostly very sparsely
commented. Macros everywhere hide from you what is going on.
Accessing data structures is always done with macros, to easy
things when structure layout changes, but this makes it very
hard for newcomers to understand what the hell those macros
are DOING...
Third, you have to find your way in a mess of #ifdefs that defies
the imagination. gcc runs in many machines, and "portability"
has been taken to ridiculous extremes (the assembler, for instance).
This means that the same macro can have several interpretations
depending on which combination of machine/os you are running.
Fourth, like in any beast like this, you are bound to encounter
the horrible hacks that will kill you.
For instance I am trying to understand the way gcc generates the
DWARF tables for C++ exception handling, and I spent several
days trying to understand why the assembler instructions:
.byte 0x4
.long 1
would produce a single byte "0x41" instead of a byte 0x4 and
a 32 bit integer 1.
First, most gcc developers told me I was wrong and that was impossible.
I learned then, that most people in the mailing lists do not know what
they are talking about.
You have to find the guy that knows what he/she is talking about. It
took me a week to find him, and then he told me that the assembler,
when assembling the debug_frame section does not follow what is written
in the assembly directives but "optimizes" it, to save space.
Ahhhhhh.
I would have never found it, it just never crossed my mind...
Lesson learned: Be prepared to find all possible hacks.
ATTENTION IMPORTANT STUFF
-------------------------
Gcc is a very good compiler. It is a compiler that generates code for
MANY machines, and is therefore very complex. Nowhere I want to
imply with this message that its "crap" or "a bad compiler". I just
want to tell people here that is surely not something you
want to *start* with.
jacob
.
- Follow-Ups:
- Re: How do I make my own custom C compiler?
- From: Allan Adler
- Re: How do I make my own custom C compiler?
- References:
- How do I make my own custom C compiler?
- From: smnoff
- Re: How do I make my own custom C compiler?
- From: Keith Thompson
- Re: How do I make my own custom C compiler?
- From: Giannis Papadopoulos
- How do I make my own custom C compiler?
- Prev by Date: Re: Is this valid C?
- Next by Date: Re: How do I make my own custom C compiler?
- Previous by thread: Re: How do I make my own custom C compiler?
- Next by thread: Re: How do I make my own custom C compiler?
- Index(es):
Relevant Pages
|