tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Is TCC good learning material?


From: Michael Matz
Subject: Re: [Tinycc-devel] Is TCC good learning material?
Date: Mon, 2 Sep 2019 20:15:26 +0000 (UTC)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]