Subsections


6. Generated code

The Free Pascal compiler relies on the assembler to make object files. It generates just the assembly language file. In the following two sections, we discuss what is generated when you compile a unit or a program.


6.1 Units

When you compile a unit, the Free Pascal compiler generates 2 files :
  1. A unit description file (with extension .ppu, or .ppw on WINDOWS NT ).
  2. An assembly language file (with extension .s).
The assembly language file contains the actual source code for the statements in your unit, and the necessary memory allocations for any variables you use in your unit. This file is converted by the assembler to an object file (with extension .o) which can then be linked to other units and your program, to form an executable.

By default (compiler version 0.9.4 and up), the assembly file is removed after it has been compiled. Only in the case of the -s command-line option, the assembly file must be left on disk, so the assembler can be called later. You can disable the erasing of the assembler file with the -a switch.

The unit file contains all the information the compiler needs to use the unit:

  1. Other used units, both in interface and implementation.
  2. Types and variables from the interface section of the unit.
  3. Function declarations from the interface section of the unit.
  4. Some debugging information, when compiled with debugging.
  5. A date and time stamp.
Macros, symbols and compiler directives are not saved to the unit description file. Aliases for functions are also not written to this file, which is logical, since they cannot appear in the interface section of a unit.

The detailed contents and structure of this file are described in the first appendix. You can examine a unit description file using the ppudump program, which shows the contents of the file.

If you want to distribute a unit without source code, you must provide both the unit description file and the object file.

You can also provide a C header file to go with the object file. In that case, your unit can be used by someone who wishes to write his programs in C. However, you must make this header file yourself since the Free Pascal compiler doesn't make one for you.


6.2 Programs

When you compile a program, the compiler produces again 2 files :

  1. An assembly language file containing the statements of your program, and memory allocations for all used variables.
  2. A linker response file. This file contains a list of object files the linker must link together.
The link response file is, by default, removed from the disk. Only when you specify the -s command-line option or when linking fails, then the file is left on the disk. It is named link.res.

The assembly language file is converted to an object file by the assembler, and then linked together with the rest of the units and a program header, to form your final program.

The program header file is a small assembly program which provides the entry point for the program. This is where the execution of your program starts, so it depends on the operating system, because operating systems pass parameters to executables in wildly different ways.

It's name is prt0.o, and the source file resides in prt0.s or some variant of this name. It usually resided where the system unit source for your system resides. It's main function is to save the environment and command-line arguments and set up the stack. Then it calls the main program.



root
2000-12-20