The Pascal Compiler |
3 |
![]() |
The syntax of this command is:
pc [options] filenameThis chapter contains the following sections:
pc Version Number
To identify the version number of pc when you compile your program, call the compiler with the -V option. This option instructs the compiler to produce output that identifies the versions of all the programs used in compiling, the compiler itself, the code generator, and so on.
hostname% mcs -p a.out | grep Pascal SC4.2 18 Sept 1996 Pascal 4.2 |
Compile and Link Sequence
You can compile the file any.p with the following command-line:hostname% pc any.p
This command actually invokes the compiler driver, which calls several programs or passes of the program, each of which processes the program. The output of each pass is the input to the next one.
Figure 3-1 shows the sequence of events when you invoke pc.
Figure 3-1 Organization of Pascal Compilation
Language Preprocessor
The cpp(1) program is the C language preprocessor. The compiler driver pc normally calls cpp(1) during the first pass of a Pascal compilation. If you use the -xl switch, pc calls the alternate preprocessor cppas. Then cpp(1) and cppas operate on files that contain the extension .p or .pas.
program showinclude; #include "file.i" begin ... end. |
See the man page for cpp(1) for information on its directives and other features. Appendix A, "Pascal Preprocessor," describes cppas.
File Name Extensions Accepted By pc
Pascal source files generally use the extension .p. The compiler recognizes other file name extensions. Table 3-1 lists the most important extensions.
The table notes that pc can produce assembler source files as well as unlinked object files. In each case, you can pass these partially compiled files to pc, which then finishes the compilation, linking, and loading.
Option-Passing on the Command-Line
To pass an option on the command-line, use a dash (-) followed by the option name. In some cases, you must supply additional information, such as a file name. For example, this command activates the listing option -l, which is off by default:hostname% pc -l rmc.p
The following command causes the generated object file to be named rmc instead of the default, a.out.hostname% pc -o rmc rmc.p
Option-Passing in the Program Text
Some options can be passed to the compiler in program text as well as on the command-line. With this facility, you can use different option values for different parts of a program.{$P+}
{$H*}
(*$I-*)
{$l+,L-,n+}
Table 3-2 shows the options that can be passed in program text.
You set options within comments, which can be delimited by either { and } or (* and *). The first character in the comment must be the $ (dollar sign). $ must be immediately followed by an option letter. Next must be either +, -, or *.
When you begin compiling a program, each stack is empty and each option has an initial current value, which may be the option default value or may have been set on the command line.
If no values have been pushed onto the stack, the effect of * is undefined.
Figure 3-2 Options in Program Text
Options
This section describes all the pc command options in alphabetical order. As described elsewhere in the documentation, Pascal 4.2 runs only in SPARC Solaris 2.x environments, which is where these options are designed for. -a
The -a option is the old style of basic block profiling for tcov. See
-xprofile=tcov for information on the new style of profiling and the tcov(1) man page for more details. Also see the manual, Profiling Tools. -Bbinding
The -B option specifies whether libraries for linking are static (not shared, indicated with -Bstatic), or dynamic (shared, indicated with -Bdynamic). -b
It is inefficient for Pascal to send each character to a terminal as it generates its output. It is even less efficient if the output is the input of another program, such as the line printer daemon, lpr(1).
{$b0} |
No buffering |
{$b1} |
Line buffering |
{$b2} |
Block buffering. The block size is 1,024. |
Any number greater than 2 (for example, {$b5}) is treated as {$b2}. You can only use this option in the main program. The block buffering value in effect at the end of the main program is used for the entire program.
-C
The -C option enables runtime checks that verifies that:
The -V0 and -V1 options implicitly turn on -C.
You can use calign within a program as well as on the command-line. However, calign only has an effect in the type and var sections of the program. Any types you define when calign is on use C-style alignment whenever you define variables of that type.
The -cond option instructs pc to compile the lines in your program that begin with the %debug compiler directive. If you compile your program without
-xl runs your program through the preprocessor cppas, which handles the Apollo DOMAIN®-style Pascal compiler directives, such as %debug.
See Appendix A, "Pascal Preprocessor," for a complete description of conditional variables, cppas, and compiler directives.
-config
You can only use this option when you also use the -xl option.
-Dname[=def]
The -D option defines a symbol name to the C preprocessor, cpp. It is equivalent to using the #define statement in your program. If you do not include a definition, name is defined as 1. See cpp(1) for more information. -dalign
The -dalign option instructs the compiler to generate double load and store instructions wherever possible for faster execution. All double-typed data become double-aligned, so do not use this option when correct alignment is not ensured. -dn
The -dn option specifies static linking in the link editor. -dryrun
The -dryrun option instructs the compiler to show, but not execute, the commands constructed by the compilation driver. You can then see the order of execution of compiler passes without actually executing them. -dy
The -dy option specifies dynamic linking in the link editor. -fast
The -fast option includes -fns -ftrap=%none; that is, it turns off all trapping. In previous releases, the -fast macro option included
-fnonstd; now it does not.
Note - The criteria for the -fast option vary with the compilers from SunSoft: C, C++, FORTRAN 77, Fortran 90, and Pascal. See the appropriate documentation for the specifics.
-flags
The -help or -flags option lists and summarizes all available options. -fnonstd
The -fnonstd option causes nonstandard initialization of floating-point arithmetic hardware. By default, IEEE 754 floating-point arithmetic is nonstop, and underflows are gradual. (See the Numerical Computation Guide for details.) The -fnonstd option causes hardware traps to be enabled for floating-point overflow, division by zero, and invalid operation exceptions. These hardware traps are converted into SIGFPE signals, and if the program has no SIGFPE handler, it terminates with a memory dump. -fns
The -fns
option turns on the SPARC non-standard floating-point mode. -fround=r
The -fround=
r option sets the IEEE 754 rounding mode that is established during program initialization. -ftrap=t
The -ftrap=
t option sets the IEEE 754 trapping mode in effect at startup.
You can compile using both the -g and -O options. However, there are some side effects:
Note - Special case: -04 -g. The combination -04 -g turns off inlining that you usually get with -04.
-h
name option names a shared dynamic library and provides a way to have versions of a shared dynamic library.This is a loader option, passed to ld. In general, the name after -h should be exactly the same as the one after -o. A space between the -h and name is optional.
The compile-time loader assigns the specified name to the shared dynamic library you are creating. It records the name in the library file as the intrinsic name of the library. If there is no -hname option, then no intrinsic name is recorded in the library file.
Every executable file has a list of needed shared library files. When the runtime linker links the library into an executable file, the linker copies the intrinsic name from the library into that list of needed shared library files. If there is no intrinsic name of a shared library, then the linker copies the path of the shared library file instead.
hostname% pc -I/home/incfiles -I/usr/incfiles program.pThe preprocessor searches for #include and %include files in this order:
hostname% pc -i scanner.i program.pSee cpp(1), or or Chapter 5, "Separate Compilation," for information on include files.
-keeptmp
The -keeptmp option keeps temporary files that are created during compilation, so they are retained instead of being deleted automatically. -L
The -L option maps all keywords and identifiers to lowercase. In Pascal, uppercase and lowercase are not interchangeable in identifiers and keywords. In standard Pascal, the case is insignificant outside of character strings and character constants. The -L option is most useful for transporting programs from other systems. See also the -s option. -l
The -l option produces a listing of the program. For example:
The first line identifies the version of the compiler you are using. The next line gives the modification time of the file being compiled. The remainder of the listing is the source program.
-Ldirectory
The -Ldirectory option adds directory to the ld library search path for ld. -libmieee
Forces IEEE 754 style return values for math routines in exceptional cases. In such cases, no exception message is printed, and errno is not set. -libmil
The -libmil option instructs the compiler to select the best inline templates for the floating-point option and operating system release available on this system. -llib
The -llib option links ld(1) with the object library, lib. -misalign
The -misalign option allows for misaligned data in memory. Use this option only if you receive a warning message that your data is misaligned. -mt
The -mt option uses multithread-safe libraries, eliminates conflicts between threads, so that Pascal library routines can be safely used in a multiprocessing environment. -native
The -native option causes pc to generate code for the best floating-point hardware available on the machine you are compiling on. -nolib
The -nolib option instructs the compiler not to link any libraries by default--that is, no -l options are passed to ld. Normally, the pc driver passes -lc to ld.hostname% pc -nolib -Bstatic -lm -Bdynamic -lc test.p
-nolibmil
The -nolibmil option instructs the compiler to reset -fast so that it does not include inline templates. Use this option after the -fast option, as in:hostname% pc -fast -nolibmil myprog.p
-non_init[=yes|no]
This option turns on early warnings of the use of uninitialized local variables. That is, if the pc compiler is given the -non_init (or -non_init=yes) option, it issues a warning at the time it finds an uninitialized local variable. This warning is issued even if the variable is initialized later in the routine.
The default late warnings are actually useful only for local variables that are never assigned. Commonly, however, a local variable is inappropriately first used and later initialized, as shown in the following example:
program iw1.p; procedure q; var x: integer; begin writeln(x); x:= 1; end; begin q; end. |
In this iw1.p program, the local variable x is used at line 5 before initialization at line 6. If iw1.p is compiled without the -non_init option, the compiler does not issue a warning because the local variable is finally initialized.
hostname% pc -non_init iw1.p w 18280 line 5 - variable x is used but never set hostname% |
Given the -non_init option, the compiler tracks the program control flow, and issues a warning each time it encounters an uninitialized local variable.
program iw2; procedure q; label 1; var x: integer; begin goto 1; writeln(x); 1: x:= 1; end; begin q; end. |
hostname% pc -non_init iw2.p w 18630 line 7 - Unreachable statement hostname% |
The following example program, iw3.p, uses indirect variable p^ (p as a local pointer variable). However, the order of statements is wrong. That is, p^ is undefined until line 7, after the execution statements at lines 5 and 6.
program iw3; procedure q; var p: ^integer; begin writeln(p^); new(p); p^:= 1; end; begin q; end. |
hostname% pc -non_init iw4.p w 18280 line 6 - variable p is used but never set hostname% |
Use With -Rw
The -non_init option can be used together with the -Rw option, which provides warnings for record fields. Compiling with a combination of the -non_init and -Rw options can capture most usages of uninitialized whole and component variables.
program iw_rw; procedure q; type t = record a,b: integer end; var p: ^integer; r: t; i: integer; begin writeln(p^); writeln(r.a); writeln(i); new(p); r.a:= 1; i:= 0; end; begin q; end. |
Compiling iw_rw with a combination of the -non_init and -Rw options captures the usages of uninitialized whole and component variables:
Lack of Effect of -non_init
The -non_init option has no effect in the following two cases:
There are four levels of optimization. You indicate the level by specifying a digit from 1 to 4 after the -O option. If you leave out the digit, the optimization level defaults to -O2.
The level numbers are interpreted as follows:
-O5
, -xO5
-xprofile
and -xO5
.
If the optimizer runs out of memory, it tries to recover by retrying the current procedure at a lower level of optimization, then resumes subsequent procedures at the original level specified in the -O command-line option.
Note - Levels -O3 and -O4 may result in an increase in the size of the executables. When optimizing for size, use level -O2. For most programs,
-O4 is faster than -O3, which is faster than -O2, which is faster than -O1. However, in a few cases -O2 may be faster than the others, and -O3 may be faster than -O4. You can try compiling with each level to see if you have one of these rare cases.
If you optimize at -O3 or -O4 with very large procedures (thousands of lines of code in a single procedure), the optimizer may require an unreasonable amount of memory. Such cases may result in degraded machine performance.
You can prevent this from happening in the C shell by limiting the amount of virtual memory available to a single process. To do this, use the limit command (see csh(1)).
For example, to limit virtual memory to 16 megabytes:
hostname% limit datasize 16MThis command causes the optimizer to try to recover if it reaches 16 megabytes of data space.
This limit cannot be greater than the machine's total available swap space, and in practice, should be small enough to permit normal use of the machine while a large compilation is in progress. For example, on a machine with 32 megabytes of swap space, the command limit datasize 16M ensures that a single compilation never consumes more than half of the machine's swap space.
The best setting of data size depends on the degree of optimization requested and the amount of real memory and virtual memory available. To find the actual swap space:
hostname% /usr/sbin/swap -sTo find the actual real memory:
hostname% /usr/sbin/prtconf | grep Memory
hostname% pc -o myprog myprog.pIf you use this option with the -c option, the name you give is used as the name for the object file. The default file name for object files is the source file name with a .o extension. You cannot give the object file the same name as the source file.
The size of the global offset table is limited to 8Kbytes with -pic. The -PIC option expands the global offset table to handle 32-bit addresses for those rare cases where there are too many data objects for -pic.
For more information on PIC, see the section on shared libraries in the Solaris documentation.
hostname% pc -Qoption cpp -R myprog.p
hostname% pc -Qpath /home/pascal/sparc testp.p
.o |
Object file from as(1) |
.pi |
Preprocessed Pascal source from cpp(1) |
.s |
Assembler source. This option is the same as the -S option. |
For example, the following command produces the file, hello.s:
hostname% pc -Qproduce .s hello.p
-qp
The -qp option is the same as -p option.
-R path[:dir]
The -Rpath[:dir] option passes a colon-separated list of directories that specify the library search path used by the runtime linker. If present and not null, it is recorded in the output object file and passed to the runtime linker. -Rw
The -Rw option checks and issues warnings on record fields which are used, but not set.
When this option is on, the compiler performs a full analysis (as far as possible at compile time) of how record fields are assigned and used. Warnings contain full access constructs for fields which are used, but not set, for example, V.F1.F2^.F3.
Use the -Rw option to check the use of "unsafe" variant records, such as the assignment of a variant to a field, or the use of another field from a "parallel" variant. These practices may result in runtime errors which are hard to find.
Examples:
Note - The -Rw option requires extra compile-time, and is, therefore, recommended for use in debugging only.
The Pascal main program, rr.p (two records)
|
program p; type r = record a,b: integer end; procedure qq; var r1, r2: r; var i: integer; begin i:=r1.a; i:=r2.a; i:=r1.b; i:=r2.b; end; begin qq; end. |
-S
The -S option compiles the program and outputs the assembly language in the file, sourcefile.s. For example, the following command places the assembly language translation of rmc.p in the file rmc.s. No executable file is created. -s[level]
The -s option instructs the compiler to accept standard Pascal only. Pascal has two levels of compliance with standard Pascal: Level 0 and Level 1. The only difference between the two is that Level 1 also allows conformant arrays.
This option is most useful when a program is to be ported to other machines.
This option can be used for two purposes:
program p(output); var time: integer; begin writeln(wallclock); end. |
hostname% pc -temp=. hello.pIf you do not specify a temporary directory, pc places the temporary files in the /tmp directory.
-V0 |
Equivalent to -C, -H, -L, and -s0 |
-V1 |
Equivalent to -C, -H, -L, and -s1 |
-v
The -v (verbose) option prints the command line used to call each compilation pass. -w
By default, the compiler prints warnings about inconsistencies it finds in the input program. The -w option turns off the warnings.hostname% {$w-}
-xa
Same as -a. -xarch=a
The -xarch=
a option limits the set of instructions the compiler may use.
-xcache=c
The -xcache=
c option defines the cache properties for use by the optimizer.
si |
The size of the data cache at level i, in kilobytes |
li |
The line size of the data cache at level i, in bytes |
ai |
The associativity of the data cache at level i |
Although this option can be used alone, it is part of the expansion of the -target option. Its primary use is to override a value supplied by the -target option.
Example: -xcache=16/32/4:1024/32/1 specifies the following:
Level 1 cache has: 16K bytes 32 bytes line size 4-way associativity |
Level 2 cache has: 1024K bytes 32 bytes line size Direct mapping associativity |
-xchip=c
The -xchip=
c option specifies the target processor for use by the optimizer.
In the map file, if you include the flag O in the string of segment flags, then the static linker ld attempts to place sections in the order they appear in the map file. See the Solaris documentation for details about this option, the segment flags, and the map file.
When you use -xl, the compiler invokes the cppas preprocessor in place of cpp(1). See Appendix A, "Pascal Preprocessor," for information on cppas.
Modules compiled with -xl are not compatible with modules compiled without -xl. You should not link these two types of modules together.
-xlibmieee
Same as -libmieee. -xlibmil
Same as -libmil. -xlibmopt
Uses a math routine library optimized for performance. The results may be slightly different than those produced by the normal math library. This option is implied by the -fast option. -xlicinfo
The -xlicinfo option returns information about the licensing system. In particular, it returns the name of the license server and the IDs of users who have licenses checked out. When you give this option, the compiler is not invoked and a license is not checked out. -xMerge
The -xMerge option instructs pc to merge the data segment of the resulting program with the text segment. -xnolib
Same as -nolib. -xnolibmopt
Resets -fast, and does not use the math routine library.
pc -fast -xnolibmopt ... -xO5
Optimizes the object code. See also -O[level].
If the optimizer runs out of memory, it tries to recover by retrying the current procedure at a lower level of optimization and resumes subsequent procedures at the original level specified in the command-line option.
-xprofile=
p option collects data for a profile or use a profile to optimize.p must be collect, use[:name], or tcov.
This option causes execution frequency data to be collected and saved during execution, then the data can be used in subsequent runs to improve performance.
-xregs=r
The -xregs=
r option specifies the usage of registers for the generated code.
The default is -xregs=appl,float.
-xs
The -xs option disables Auto-Read for dbx in case you cannot keep the .o files around. This option passes the -s option to the code generator and linker.
-xsafe=mem
option allows the compiler to assume no memory-based traps occur.This option grants permission to use the speculative load instruction on V9 machines.
-xspace
option does no optimizations that increase the code size.Example: Do not unroll loops.
-xtarget=
t option specifies the target system for the instruction set and optimization.t must be one of: native, generic, system-name.
The -xtarget option permits a quick and easy specification of the -xarch, -xchip, and -xcache combinations that occur on real systems. The only meaning of -xtarget is in its expansion.
The performance of some programs may benefit by providing the compiler with an accurate description of the target computer hardware. When program performance is critical, the proper specification of the target hardware could be very important. This is especially true when running on the newer SPARC processors. However, for most programs and older SPARC processors, the performance gain is negligible and a generic specification is sufficient.
-xtarget Expansions
Table 3-9