Is TCC good learning material?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is TCC good learning material?

Stefanos Baziotis
Hello everyone,

I'm new to TCC and I'm fascinated in what it can accomplish for its size.

I'm passionate about compilers and I'd like to dive in TCC.
Do you think it's good learning material? I'm not a complete beginner.
i.e. I can program a minijava compiler in hours, I'm contributing in 2 D
compilers and I can navigate through Clang easily.
OTOH, I can't understand a thing in GCC and TCC :/. The documentation did
not help much either.

Is this normal? How much time it takes roughly? And should I stick with it
or just leave it for when I'm more experienced?

Kind regards,
- Stefanos


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is TCC good learning material?

Michael Matz-4
Hi,

On Mon, 2 Sep 2019, Stefanos Baziotis wrote:

> I'm new to TCC and I'm fascinated in what it can accomplish for its size.
>
> I'm passionate about compilers and I'd like to dive in TCC.
> Do you think it's good learning material? I'm not a complete beginner.
> i.e. I can program a minijava compiler in hours, I'm contributing in 2 D
> compilers and I can navigate through Clang easily.
> OTOH, I can't understand a thing in GCC and TCC :/. The documentation did
> not help much either.
>
> Is this normal? How much time it takes roughly? And should I stick with it
> or just leave it for when I'm more experienced?

Stick with it, it's really not that hard.  Open tccgen.c and start reading
from bottom to top.  You want to be equipped with an editor/GUI that
provides quick jumping to definitions of functions you happen to come
across while reading.

You have to keep in mind that TCC is a single pass compiler that generates
code during parsing, which influences various ways of doing things, but in
a way it also simplifies TCCs data structures: there's not much internal
state except the symbol table (split between the ELF symbol table and the
TCC one), the expression stack, the symbol unwind stack (for scopes) and
the implicit function call stack for parsing the various recursive C
constructs.

Also, to understand the inner workings of stuff it helps to see the thing
in action under control of a debugger, so choose a short C file and see
what TCC does with it while compiling.

Of course, TCC also contains the preprocessor (tccpp.c) and ELF linker
(tccelf.c), but they're all controlled from and called by routines in
tccgen.c.  (As is the various architecture backends in e.g. x86_64-gen.c).


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is TCC good learning material?

Stefanos Baziotis
>
> Stick with it, it's really not that hard.  Open tccgen.c and start reading
> from bottom to top.  You want to be equipped with an editor/GUI that
> provides quick jumping to definitions of functions you happen to come
> across while reading.
>
> You have to keep in mind that TCC is a single pass compiler that generates
> code during parsing, which influences various ways of doing things, but in
> a way it also simplifies TCCs data structures: there's not much internal
> state except the symbol table (split between the ELF symbol table and the
> TCC one), the expression stack, the symbol unwind stack (for scopes) and
> the implicit function call stack for parsing the various recursive C
> constructs.
>
> Also, to understand the inner workings of stuff it helps to see the thing
> in action under control of a debugger, so choose a short C file and see
> what TCC does with it while compiling.
>
> Of course, TCC also contains the preprocessor (tccpp.c) and ELF linker
> (tccelf.c), but they're all controlled from and called by routines in
> tccgen.c.  (As is the various architecture backends in e.g. x86_64-gen.c).
>

Great, thanks! I'll try to update the doc as I learn. In my opinion,
it's fairly minimal.

Kind regards,
Stefanos


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel