HPlogo HP C++ Programmer's Guide: HP 9000 Series Workstations and Servers > Chapter 3 Compiling and Executing HP C++ Programs

Phases of the Compiling System

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

When you compile an HP C++ program it passes through one or more phases or subprocesses controlled by a component of the compiling system. The CC command invokes the components of the HP C++ compiling system automatically when you use the CC command. You do not have to invoke each component yourself.

Use the -v and -ptv options to see detailed information about each component as it executes. The following sections describe these phases and components.

Figure 3-1 Phases of the HP C++ Compiling System in Compiler Mode

[Phases of the HP C++ Compiling System in Compiler Mode]

What Happens in Compiler Mode

This section describes the compiler phases or subprocesses that execute when you compile a C++ program in compiler mode, the default mode. In compiler mode your C++ source code is compiled directly to object code. Refer to Figure 3-1 “Phases of the HP C++ Compiling System in Compiler Mode”.

In translator mode, your C++ code is translated to C code, then compiled by the C compiler. See Figure 3-2 “Phases of the HP C++ Compiling System in Translator Mode” for more information on translator mode.

Preprocessing

When you compile a C++ source program using either compiler mode or translator mode, HP C++ invokes the preprocessor Cpp.ansi on your programs that have the file name suffix .c or .C. The preprocessor examines all lines beginning with a #, performs the corresponding actions and macro replacements, and produces a preprocessed version of your program with the file name suffix .i. The .i file is created in a directory used to store temporary files.

If the next phase, compiling with cfront, is successful, the .i file in the temporary directory is deleted by default. Use the -P option to save the .i files.

For more information on the preprocessor, see Chapter 2 “The HP C++ Preprocessor”, "The HP C++ Preprocessor."

Compiling C++ Source Code

When you use the default compiler mode, the compilation phase runs cfront in compiler mode. cfront compiles the preprocessed C++ code and generates object code in the .o file.

cfront also creates a map file, a temporary file containing information about the data types in your code.

In compiler mode the C++ code is not translated to C code.

Compile-Time Template Processing

The compile-time template processing phase runs c++ptcomp which merges the map file into the repository.

Link-Time Template Processing

The link-time template processing phase runs c++ptlink and retrieves information about templates from the repository to automatically instantiate templates. c++ptlink may create additional object files in the repository. This phase is entered only if templates need to be instantiated.

Linking

In the link phase, the CC command invokes the linker, /bin/ld, using the cc interface. The linker produces an executable program that includes the start-up routines from /lib/crt0.o (/opt/langtools/lib/*crt0.o for Versions A.10.01 and later) and any needed library routines from the archive libraries /lib/libc.a, /usr/lib/libC.a, and /usr/lib/libC.ansi.a, or references to library routines from the shared libraries /lib/libc.sl, /usr/lib/libC.sl, and /usr/lib/libC.ansi.sl. If you are using exception handling, the libraries in /usr/lib/CC/eh are used.

External references are resolved, libraries are searched to resolve references to library routines, and the object files are combined into an executable program file, a.out by default.

Linking Constructors and Destructors

The patch phase runs c++patch. c++patch links or chains constructors and destructors of nonlocal static objects in the executable file or shared library.

By default, the name of the executable file is a.out.

What Happens in Translator Mode

This section describes the compiler phases or subprocesses that execute when you compile a C++ program in translator mode. In translator mode, your C++ code is translated to C code, then compiled by the C compiler. Refer to Figure 3-2 “Phases of the HP C++ Compiling System in Translator Mode”.

Translator mode is used only when you use the +T option to CC. By default, C++ uses compiler mode. See Figure 3-1 “Phases of the HP C++ Compiling System in Compiler Mode” for more information on compiler mode.

Figure 3-2 Phases of the HP C++ Compiling System in Translator Mode

[Phases of the HP C++ Compiling System in Translator Mode]

Preprocessing

When you compile a C++ source program using translator mode, HP C++ invokes the preprocessor Cpp.ansi on your programs the same as it does in compiler mode and produces a preprocessed version of your program with the file name suffix .i.

For more information on the preprocessor, see Chapter 2 “The HP C++ Preprocessor”, "The HP C++ Preprocessor."

Translating C++ Source Code to C

The translation phase runs cfront in translator mode. cfront takes the output of the preprocessor (the .i files containing C++ source code), performs syntax and type checking, and translates HP C++ source programs to C source programs. The temporary C files created by cfront are exact translations of the C++ code ready for the HP C compiler to compile.

In addition, cfront creates a map file, a temporary file containing information about the data types in your code.

If you specified the -g or -g1 option, cfront also creates a temporary file containing information for the symbolic debugger.

Compile-Time Template Processing

The compile-time template processing phase runs c++ptcomp which merges the map file into the repository.

Compiling the Translated C Source Code

In translator mode the compilation phase runs the C compiler, cc, which compiles the translated C source code and generates object code in the .o file.

Adding Debug Information

When you use translator mode and you compile with either the -g or -g1 option, your files go through the merge phase. This phase runs c++merge and merges the debug information from the temporary file into the object file so you can use the symbolic debugger.

When you use compiler mode and specify either -g or -g1 the HP C++ compiler adds the debug information directly to the object file.

Link-Time Template Processing

The link-time template processing phase runs c++ptlink and retrieves information about templates from the repository to automatically instantiate templates. c++ptlink may create additional object files in the repository. This phase is entered only if templates need to be instantiated.

Linking

In the link phase, the CC command invokes the linker, /bin/ld, using the cc interface. The linker produces an executable program that includes the start-up routines from /lib/crt0.o (/opt/langtools/lib/*crt0.o for Versions A.10.01 and later) and any needed library routines from the archive libraries /lib/libc.a, /usr/lib/libC.a, and /usr/lib/libC.ansi.a, or references to library routines from the shared libraries /lib/libc.sl, /usr/lib/libC.sl, and /usr/lib/libC.ansi.sl. If you are using exception handling, the libraries in /usr/lib/CC/eh are used.

External references are resolved, libraries are searched to resolve references to library routines, and the object files are combined into an executable program file, a.out by default.

Linking Constructors and Destructors

The patch phase runs c++patch. c++patch links or chains constructors and destructors of nonlocal static objects in the executable file or shared library.

By default, the name of the executable file is a.out.