Compiler

Here is located the main program, common variables, and everything else that does not belong into other categories.

Main Program

This is the main program of the compiler. It initializes some data, reads configuration file, processes command line parameters, loads library (reports error if it is not found), initializes module data, checks for main file, resets compilation timer, compiles the source file and writes compilation status.
 

Processing Command-Line Parameters

This procedure processes command line parameters and sets compiler flags and data accordingly.
 

Error Handling

Compiler should have the possibility to report error from any function. Turbo Pascal solves this problem by defining procedure SetErrorAddress which saves the stack position and return address.
 

Error Reporting

Turbo Pascal reports errors with module name, source line and error position where the error occured. This is very handy to locate the problem. This information can also be used in some text editors to position the cursor where the compiler reported error.
 

Compilation Progress and Status Display

During compilation Turbo Pascal displays current module and source line number (if command line switch for quiet compilation was not used).
 

Finding Source Position From Code Address

Turbo Pascal has a command line switch /Fseg:ofs which can find module name and source line number compiled at this address. The program is normally compiled but instead of compilation status the source position is displayed.
 

Command Line Syntax Display

When no source file is specified this procedure simply displays Turbo Pascal command line syntax with default switch states.
 

The Compilation Process

This is where the actual compilation starts. Turbo Pascal first clears and prepares some variables and data structures and then compiles the module (unit or program). If program was compiled then compiler checks for indirect references and calls a procedure to link the code and data and to create the executable file.
 

Processing Used Units

Every Turbo Pascal module (program or unit) can use other units. Processing them is one of the trickiest parts of Turbo Pascal compiler.
 

Loading Used Units

Each used unit is checked if it is already loaded. If it is not, it needs to be found and checked if recompilation is needed. When used unit needs recompilation the current processed unit (symbol tables and compilar data) need to be pushed to the heap to make room for a new unit.
 

System Unit

This is the Turbo Pascal System unit. This unit implements Turbo Pascal's runtime library.
 


 
 
© 2017 Turbo Pascal | Privacy Policy