Question about organization of gfortran source code

Daniel Kraft d@domob.eu
Tue Sep 9 09:23:00 GMT 2008


L R wrote:
> Hi, I am a high school student working on a project involving fortran.
> Since I am focusing more on the optimization side of a compiler, I do
> not want to spend ages writing a parser that will work for all of
> fortran's weird gotcha's. I am trying to figure out from the sources
> where the parser ends and the rest of it begins, but I am having a
> little trouble understanding everything without reading 80% of the
> code. Could someone please provide some insight into how the sources
> are organized. I realize parse.c obviously deals with a lot of the
> parsing, but I still am having trouble figuring out the execution flow.
> Could someone please tell which sections of the program first deal with
> the tokenization of raw strings all the way to when the program is
> finally in the form of an expression tree. Thanks a lot!

Hi,

to add to what Tobias wrote:  You're right, AFAIK the main parsing is 
done controlled from parse.c, but also a lot is in match.c and other 
files (usually routines [gfc_]match_something with a return-value of 
gfc_match).  This builds up a first internal tree representation of the 
parsed source; next comes a pass over this tree to resolve symbols 
referencing to procedures and the like, check interfaces and 
consistency, and related stuff not possible directly while parsing, this 
is in resolve.c with routines [gfc_]resolve_something.  During this 
phase, also some code-constructs are "handled" by transforming into 
other, equivalent, constructs.

I'd say that after resolution the "parser" work is done and a 
(Fortran-biased) expression tree is there.  The final pass in the 
front-end converts this tree to the language-neutral expression trees 
used in gcc.

-fdump-parse-tree will dump the resolved Fortran tree, while 
-fdump-tree-original will dump the gcc internal one after all front-end 
processing is done.

I hope I got everything correct, feel free to jump in if I messed 
something up...

Yours,
Daniel

-- 
Done:     Arc-Bar-Cav-Sam-Val-Wiz, Dwa-Elf-Gno-Hum-Orc, Law-Neu-Cha, Fem-Mal
To go:    Hea-Kni-Mon-Pri-Ran-Rog-Tou



More information about the Fortran mailing list