On 26 May 2015 00:30, "ketmar via Digitalmars-d" <
digitalmars-d@puremagic.com> wrote:
>
> On Mon, 25 May 2015 18:34:24 +0200, Iain Buclaw via Digitalmars-d wrote:
>
> > Yes, they do.  The key difference is that GCC doesn't require you to
> > delve into it's backend, as a language implementer, you only need to
> > think of how the code should be represented in it's tree language (ie:
> > http://icps.u-strasbg.fr/~pop/gcc-ast.html) - Because of this, I never
> > need to look at assembly dumps to understand what is going on, only tree
> > dumps,
> > which are handily outputted in a C-style format with
> > -fdump-tree-original=stdout.
>
> yet there are no well-documented samples for GCC, like "let's create a
> frontend for simple C-like language, step by step" (at least not in the
> distribution).

There used to be treelang, but nobody maintained it, and it quickly became
obsolete.  This is the best small frontend I've come across.

https://github.com/giuseppe/gccbrainfuck

Depending on when you tried your attempt, the response is always going to
be , the entry barrier is getting lower every year.

LLVM and GCC are very similar, but where LLVM built it's AST on class
hierarchy from the start, due to legacy, GCC achieves the same OO style
using unions and accessor macros.  The best documentation for these can be
found in the source code (see tree.def and tree.h for all definitions and
accessors).

I suspect the most common beginner bugs occurs when using right accessor on
the wrong tree causes an ICE at runtime in 'some obscure location'.

Incase you intend to dabble again in the future as more parts move over to
C++, so far, RTL, GIMPLE, callgraphs, and almost all synthetic value types
have been switched over. When trees finally get shunted across, you'll
finally benefit from compile-time verified AST.

> there are none for DMD too, but DMD code can be read and
> understood enough to work with it. and reading GCC code is out of
> question, it's way too huge.
>

No one (sane) starts with studying the whole of gcc.  There are only three
or four key files that you only need to reference to get off the ground.

> sure, that is not your fault, i'm simply trying to explain why there are
> almost no people working on GDC. it's just too hard. or it seems to be
> hard, but without good GCC documentation it's almost the same.

It normally starts with a clean frontend. Currently there are bits and
pieces split across the place for GDC.  But at least for the most part, all
codegen is done via handy routines that call the correct backend builder
for you.  But I'd like to go one better and have these part of the new
visitors we are switching to.  Once all code generation for e.g expressions
is all encapsulated into a single file, then it's just a case of
documentation.

Iain

Reply via email to