Chapter 2. Compiling, Linking, and Running Pascal Programs
Prev |  | Next

## Chapter 2. Compiling, Linking, and Running Pascal Programs

This chapter lists specific commands for compiling, linking, and running Pascal programs on the IRIS-4D. It also explains the tools used in each command procedure.

You can find general information about compiling, linking, and running programs on the IRIS-4D in the IRIS-4D Series Compiler Guide.

## Compiling and Linking Programs

Compile and link programs using the Pascal driver command `pc` as described in this section.

This is the format of the pc command:

    pc [

    options]

    filename

These are the parts of the command and their tasks:

- `pc` invokes the Pascal driver processes that compile, optimize, assemble, and link edit the program. (To compile programs without linking, see Section 2.1.2, “Pascal Driver Options” below.)

- `option` represents a driver option. The number of options allowed on a command line by the compiler varies according to the task.

- `filename` may include Pascal source code, object code, and libraries:

  - `filename.p` for Pascal source code

  - `filename.o` for object code

  - `-l` `libraryname` for libraries; libraries follow files

The output of the `pc` command is a program executable module.

### The Pascal Driver

The Pascal driver invoked by the `pc` command is an intelligent program that in turn invokes the five major components of the compiler system.

These are the five components, listed below in processing order:

1. Pascal compiler

2. optimizer

3. code generator

4. assembler

5. link editor

Figure 2-1 illustrates the compile process.

In this illustration, the primary driver phases are in the boxes. The principal input is the source file `more.p`. The principal output is the executable file `a.out`. The file name `a.out` is the default name for executables.

See Section 2.1.2 section below to rename the executable file during the compile process.

Figure 2-1. Pascal Compile Process

### Pascal Driver Options

Three driver output options are listed in this section according to the task each one performs. Additional options are discussed briefly by category. The complete set of options is listed in reference format in the pc(1) man page.

#### Produce a Linkable Object File

Use the `--c` driver option to produce a linkable object file instead of an executable. This option stops the driver immediately after the assembler phase.

The linkable object file has the suffix .`o.`

Here is an example of the driver command with this option:

    pc -c more.p

The object file produced is `more.o`.

| Note: When you want to place more than one object file on the command line, specify the file containing the main program first. The link editor requires this information.

#### Rename the Executable

Use the `-o` option to rename the executable during the compile process. If this option is not used, the executable will be named `a.out`.

You can use this option with a source file or an object module.

Here is an example command line that takes the source file `myprog.p`, compiles it, links it, and names the executable `exec.myprog`:

    pc myprog.p -o exec.myprog

Here is an example command that takes the object module `more.o`, links it, and names the executable `exec.myprog`:

    pc more.o -o exec.myprog

#### Graphics Option

If your program contains graphics routines from the Graphics Library, you need to use the graphics option. The graphics option, `-Zg`, automatically links to your program two libraries and a conversion file: `libpgl.a`,`libgl.a`, and `p2cstr.o`.

If you do not use the `-Zg` option, you can explicitly link the necessary routines as follows:

    pc sourcefile.p -lpgl -lgl /usr/lib/p2cstr.o

#### Debugging Options

When you are debugging, use the `-g` option with the output option discussed above. The `-g` option creates an expanded symbol table in the object file and links the file using the debugging flag. An example of compiling for debugging is:

    pc -g sourcefile.p -o executefile

There are other forms of the `-g` option, plus different options for profiling ( `-pn`), optimizing ( `-On`), and other specialized driver functions. These are discussed and listed in the release notes for your version of Pascal.

### Compiling Multi-Language Programs

The compiler system provides drivers for other languages in addition to Pascal, including C (standard), Fortran 77 (optional), and PL/1 (optional).

This section describes general multi-language compiling conventions.

When your application has two or more source programs written in different languages, you should compile each program separately with the appropriate driver, and then separately link them in another step. Use the `-c` option to create objects suitable for link editing.

#### Driver Command Syntax

For each language below, see the man page listed with it for correct driver command syntax:

    C               cc(1)
    Fortran 77      f77(1)
    PL/1            pl1(1)
    Pascal          pc(1)

Here is a command example with a C program and a Pascal program:

    cc -c main.c
    pc -c rest.p

`main.c` contains the main routine and is executed first, as required. Then the Pascal source file `rest.p` is compiled.

The compile processes and output for this example are shown in Figure 2-2.

Figure 2-2. Multi-Language Compile Process

### Linking Separate Language Objects

The driver recognizes the .o suffix as the name of a file containing object code suitable for link editing, and immediately invokes the link editor.

Here is an example command that link edits the object created in the last example above:

    pc -o all main.o rest.o

The command produces the executable program object `all`. You can achieve the same results using the `cc` driver command with the additional option `-l`, as shown below:

    cc -o all main.o rest.o -lp -lm

Both `f77` and `cc` use the C link library by default. However, the `cc` driver command does not know the names of the link libraries required by Pascal objects. Therefore, you must specify them explicitly to the link editor, using the `-l` option with the symbols for the other libraries.

The `-l` option with p links the Pascal library `/usr/lib/libp.a`.

The `-l` option with m links the Math library `/usr/lib/libm.a`.

See the FILES section of the Pascal pc(1) manual pages, for a complete list of files available. See the ld man page for additional information about the `-l` option.

### Making Inter-Language Calls

In addition to compiling separate language source files into one executable, you can make inter-language calls between C, Pascal, and Fortran 77.

An interface between C and Pascal is described in Chapter 4 of this manual. An interface between Pascal and Fortran 77 is described in the Fortran 77 Programmer's Guide.

## Running Programs

Run Pascal programs using the name of the executable object module produced by the `pc` command with the `-o` option.

If you do not rename the program during the compile process, it is named `a.out` by default. Invoke it with this command in the directory where the executable resides:

    a.out

If you do rename the program during the compile process, invoke it with its assigned name in the directory where the executable resides.

The IRIS-4D Series Compiler Guide contains more information about run time considerations.

Prev | Table of Contents | Next
Chapter 1. Pascal Implementation |  | Chapter 3. Storage Mapping