Node:Internals, Next:Copying, Previous:To Do, Up:Top

## The GPC Source Reference

> "The Source will be with you. Always."

This chapter describes internals of GPC. It is meant for GPC developers and those who want to become developers, or just want to know more about how the compiler works. It does not contain information needed when using GPC to compile programs.

This chapter tells you how to look up additional information about the GNU Pascal compiler from its source code.

Note: If you intend to modify GPC's source, please check the top of each file you're going to modify. A number of files are generated automatically by various tools. The top of these files will tell you by which tool and from what file they were generated. Modifying a generated file is pointless, since it will be overwritten the next time the tool is run. Instead, modify the original source (which will usually be easier in fact, e.g. a bison input file vs. the generated C code). This also holds for various documentation files.

Proprietary compilers often come with a lot of technical information about the internals of the compiler. This is necessary because their vendors want to avoid to distribute the source of the compiler - which is always the most definitive source of this technical information.

With GNU compilers, on the other hand, you are free to get the source code, look how your compiler works internally, customize it for your own needs, and to re-distribute it in modified or unmodified form. You may even take money for this redistribution. (For details, see the GNU General Public License, Copying.)

The following subsections are your guide to the GNU Pascal source code. If you have further questions, be welcome to ask them at the GNU Pascal mailing list (see Support).

All file paths mentioned in this chapter are relative to the GNU Pascal source directory, usually a subdirectory `p` of the GCC source.

The following sections roughly coincide with the order of the steps a Pascal source passes through during compilation (omitting the code generation which is the job of the GCC backend, and the assembler and linker steps at the end which are done by the programs `as` and `ld` of binutils and possibly other utilities like `collect2`). Also missing here is the compiler driver `gpc` which behaves very similarly to `gcc` and whose main job is to invoke the other parts in the right order, with the right arguments etc.

@@ Under construction. Many more things are missing because nobody has yet had the time to write something about them.

- Preprocessor: `gpcpp.c` -- The Pascal preprocessor
- Lexical analyzer: `gpc-lex.c` -- How GPC reads your source.
- Lexer/parser: Interrelations between the lexer and parser
- Language definition: `parse.y` -- ``Syntax diagrams'' as ``Bison'' source.
- Parsing keywords: So many keywords, so many problems ...
- Parsing subranges: Expressions as lower bounds of subranges
- Tree nodes: `../tree.*` -- How GPC stores your program internally.
- Parameter passing: `typecheck.c` -- How GPC passes parameters.
- GPI files: `module.c` -- How GPC's precompiled module/unit interfaces work.
- Automake: `module.c` -- How GPC automatically ``makes'' a large project.
- File Layout: Files that make up GPC; Integrating GNU Pascal in GCC

For more information, see chapters "Portability" through "Fragments" in the GCC documentation.