HP 3000 Manuals

Compiling, Linking, and Running Your Program [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation


HP Pascal/iX Programmer's Guide

Compiling, Linking, and Running Your Program 

To make your HP Pascal program a valid HP-UX process, you must compile,
link (and load), and run it.

The HP-UX command pc coordinates the HP Pascal compiler
(/usr/lib/pascomp) and the HP-UX linker loader (/bin/ld).

The name of the file containing your source program must end with .p (for
example, prog.p).  The extension .p causes the pc command to call the HP
Pascal compiler, which compiles your program and stores the resultant
code in an object file.  The name of the object file ends in .o (if the
source file name is prog.p, the object file name is prog.o).  If prog.p
is the only file parameter of a particular pc command, and it compiles
and links successfully, then the object file is not saved.

If the compiler does not find errors in the program, the pc command calls
the linker, ld, which links the object file with required library files
into a program file.  The name of the program file is a.out (unless you
specify another name in the pc command) and it resides in the directory
from which pc was invoked.  The program file is ready to run.

Figure B-1  shows how a file named prog.p becomes a running program on
HP-UX.

[]
Figure B-1. How a File Becomes a Running Program on HP-UX This section explains: * The HP-UX pc command. * How to pass run-time parameters to your program. * How HP-UX handles interrupts. * How HP-UX handles run-time errors. pc Command The HP-UX command pc coordinates the HP Pascal compiler (/usr/lib/pascomp) and the HP-UX linker loader (/bin/ld). Additionally, the compiler looks for a system-wide file called /usr/lib/pasopts. If the file exists and is not empty, the compiler opens and reads the file. The file should contain only directives and comments. If there is anything else in the file, the compiler emits an error message. If the file is empty, which is the default, the compiler does not attempt to open it. For more information on the system-wide file, refer to the section on compiler options in the HP Pascal/HP-UX Reference Manual. Syntax [REV BEG] pc [file ] [...] [option] [REV END] Parameters file At least one file is required. option Any of the following instructions to the compiler: -A Produce warnings when non-ANSI Pascal features are found (same as ANSI ON). +a Cause the compiler to generate archived object (.a) files instead of simple object (.o) files. This option exists for compatibility with the Series 300 pc command. -C Suppress code generation. No object (.o) files will be created and linking will be suppressed. This is effectively a request for syntax/semantics checking only (same as CODE OFF). +C Convert MPE/iX format file names in the compiler options BUILDINT, INCLUDE, LISTINTR, SPLINTR, and SYSINTR to HP-UX-format file names. Fully qualified HP-UX-format file names (those that begin with slash, like /mnt/srf/file) are not converted. This option is the same as the compiler option CONVERT_MPE_NAMES This option assumes an HP-UX directory structure that is modeled after the MPE/iX accounting structure, in which all files reside in group-level directories and groups are subdirectories of accounts. This option converts MPE/iX format file names to lower case letters. For example, assume the HP-UX directory structure account/group, where group is a directory containing the file f. If a Pascal source program contains the statement $INCLUDE 'F.Group.Account'$ then the compiler appends the appropriate path information to f and searches for the resulting name (for example, root/account/group/f, where root is the parent of the account-level directories). -c Suppress linking and only produce object (.o) files from source files. -Dname=bool, Defines name is as if it has been set (with -Dname $SET) to the nth line on the source file. bool can be either TRUE or FALSE; if bool in not specified, name is set to TRUE. name and bool can be uppercase or lowercase. The order in which the compiler encounters $SETs (regardless of relative order on the command line) is: 1. -Dname=bool 2. +Q dfile 3. source file The compiler overrides -Dname=bool with any subsequent duplicate use of $SET, always taking the last one and issuing a warning. +DAmodel Generates object code for a specific version of the PA-RISC architecture. model can be a model number such as 750 or 870, or one of the following architecture specifications: 1.0 Generates object code suitable for all implementations of PA-RISC 1.0 or higher. This is the default for all Series 800 models. 1.1 Generates object code suitable for all implementations of PA-RISC 1.1. This is the default for all Series 700 models. Note that object code generated for PA-RISC 1.1 will not execute on PA-RISC 1.0 implementations. +DAmodel also specifies the appropriate library search path for HP-UX math libraries. If your program calls any of the standard Pascal Arithmetic functions, using +DA1.0 links the PA-RISC 1.0 version of the math library and using +DA1.1 links the PA-RISC 1.1 version of the library. The PA-RISC 1.1 libraries have performance enhancements and new routines that the PA-RISC 1.0 libraries lack. See the HP-UX Floating-Point Guide for more information about using math libraries. +DSmodel Perform instruction scheduling appropriate for a specific implementation of the PA-RISC architecture. model can be a model number such as 750 or 870, or one of the following architecture specifications: 1.0 Perform scheduling tuned to a model representative of PA-RISC 1.0 implementations. 1.1 Perform scheduling tuned to a model representative of PA-RISC 1.1 implementations. The default scheduling is based on the model number returned by uname(2). This option affects only performance of the object code by scheduling the code based on the specific latencies of the target implementation. The resulting code executes correctly on other PA-RISC implementation, subject to the +DA option. +FPflag Specify how the run time environment for floating-point operations should be initialized at program start up. flag is a series of upper or lower case letters from the set [VvZzOoUuIiDd] with no embedded white-space. If the upper-case letter is selected, that behavior is enabled. If the lower-case letter is selected or if the letter is not present in flag, the behavior is disabled. The default is that all behaviors are disabled. The list below describes the behaviors: V Trap on invalid floating-point operations. Z Trap on divide by zero. O Trap on floating-point overflow. U Trap on floating-point underflow. I Trap on floating-point operations that produce inexact results. D Enable sudden underflow (flush to zero) of denormalized values. Enabling underflow is possible only on implementations of PA-RISC 1.1 or higher; it is not possible on PA-RISC 1.0. To dynamically change these settings at run time, refer to fpgetround(3M). -G Prepare object files for profiling with the gprof utility (see "GPROF" in the HP Pascal/HP-UX Reference Manual). -g Generate additional information for the symbolic debugger, and ensure that the program is linked as required for the symbolic debugger. -Idir Add dir to the list of directories that search for $INCLUDE files whose names do not begin with /. The search is performed in the following order: 1. The directory containing the source file. 2. Directories specified with the -I option. 3. The current working directory. 4. The standard directory /usr/include. -L Write a program listing to stdout. -lx Cause the linker to search the libx.sl or libx.a libraries in an attempt to resolve currently unresolved external references. Because a library is searched when its name is encountered, placement of a -l is significant. If a file contains an unresolved external reference, the library containing the definition must be placed after the file on the command line. See ld(1) for more information. -N Cause the output file from the linker to be marked as unshareable (see -n). -n Cause the output file from the linker to be marked as shareable (see -N). -O Turn on optimization. The compiler performs level 2 optimization. See +Oopt. +Oarg Perform optimizations selected by arg. There are two kinds of arguments to the +O optimization option. Those in the first group can have arg defined as: 1 Perform level 1 optimizations. These include branch optimizations, dead code elimination, instruction scheduling, and peephole optimization. 2 Perform level 2 optimizations. These include common subexpression elimination, constant folding, loop invariant code motion, coloring register allocation, and store-copy optimization. Level 2 optimizations are a superset of level 1 optimizations. The -O option is equivalent to the +O2 option. 3 Perform level 3 optimizations. These include, but are not limited to, interprocedural global optimizations. Level 3 optimizations are a superset of level 2 optimizations. Those in the second group can have arg defines as: s Suppress optimizations which tend to increase the generated code size. Currently, these optimizations include software pipelining and loop unrolling. bbnum Specify the maximum number of basic blocks allowed in a procedure that is to be optimized at level 2. If a procedure contains more than num basic blocks, level 1 optimization is performed for that procedure. The default value for num is 500 (same as $OPTIMIZE 'BASIC_BLOCKSnum'$). The arguments in the second group implicitly request level 2 optimizations, but an argument from the first group overrides the implicit level 2 regardless of their relative positions on the command line. -o outfile Name the output file from the linker outfile instead of a.out. -P lines Allow lines lines per page of compiler listing, including header or trailer (same as the LINES compiler option). -p Prepare object files for profiling with the prof utility. -Q Cause the output file from the linker to be marked as not demand loadable (see -q). -q Cause the output file from the linker to be marked as demand loadable (see -Q). +Q dfile Cause dfile to be read before compilation of each source file. The file dfile can only contain compiler options. +R Turns off range checking (same as the compiler option RANGE OFF). -S Output an assembly file. This file is named filename.s, where filename is the base name of the source file. -s Cause the output of the linker to be stripped of symbol table information. See strip(1) in linker documentation. This option is incompatible with symbolic debugging. -t x,name Substitute or insert subprocess x with name where x is one or more of an implementation-defined set of identifiers indicating the subprocesses. This option works in the following modes: * If x is a single identifier, name represents the full path name of the new subprocess. * If x is a set of identifiers, name represents a prefix to which the standard suffixes are concatenated to construct the full pathname of the new subprocesses. The values x can assume are: c Compiler body (standard suffix is pascomp). 0 Same as c. l Linker (standard suffix is ld). -v Enable verbose mode, producing a step-by-step description of the compilation process on stderr. -w Turn off warning messages (same as the compiler option WARN OFF). -Wc,arg1 Cause arg1 through argn to be handed off to [,arg2,... subprocess c. The arg parameters are of the argn] form: -argoption[,argvalue] where argoption is the name of an option recognized by subprocess c and argvalue is a parameter for argoption (if it has one). The parameter c can have these values: Value Meaning c Compiler body (standard suffix is pascomp). 0 Same as c. d Driver program. l Linker (standard suffix is ld). For example, the specification to pass the -r option (preserve rotation information) to the linker is -Wl,-r. -Y Enable 16-bit Native Language Support when parsing string literals and comments (same as the compiler option NLS_SOURCE). Note that 8-bit parsing is always supported. Other options--instructions to the linker--are also allowed. See pc(1) in the HP-UX Reference for details. -y Generate additional information needed by static analysis tools and ensure that the program is linked as required for static analysis. This option is incompatible with optimization. +z, +Z Both of these options cause the compiler to generate position independent code (PIC) for use in building shared libraries. However, you must use +z to generate PIC, unless certain limits are exceeded. Use +Z when limits are exceeded. If both +z and +Z are specified, only the last one encountered will apply. Note that +z is the same as $SHLIB_CODE ON$ and +Z is the same as $SHLIB_CODE 2$. The options -G and -p are ignored if you use either +Z or +z. For more information about PIC , refer to Programming on HP-UX. file The name of a textfile that contains source code for an HP Pascal program, or the name of an object file. The textfile name ends with .p; the object file name ends with .o. For each textfile, the pc command calls the HP Pascal compiler, which tries to compile it. If the compiler compiles the textfile named prog1.p without errors, it produces an object file named prog1.o (which resides in the current directory). If each textfile compiles successfully, the pc command calls the HP-UX Linker Loader, ld, which links all of the object files (pc command parameters and those resulting from compiles) into the final program file. If prog.p is the only file parameter of a particular pc command, and it compiles and links successfully, then its object file, prog.o, is not saved. Example The command: pc main.p ext1.p ext2.p compiles the object files main.o, ext1.o, and ext2.o, into the final program file a.out. It is equivalent to the command sequence: pc -c main.p pc -c ext1.p pc -c ext2.p pc main.o ext1.o ext2.o
NOTE The HP Pascal compiler ignores the following Series 300 pc command options without warning: +X +x +M +b +bfpa +f +ffpa
Run-Time Parameters You can pass run-time parameters to your program as HP-UX command-line arguments when starting your program. No arguments are automatically bound to program parameters. Even the three pre-opened (standard) files, stdin, stdout, and stderr are only bound to the HP Pascal textfiles input, output, and stderr if the program heading declares the textfiles. Other run-time parameters must be obtained from the command line arguments by importing the predefined module arg and using the routines that it exports, which are: Function Return Value argc The total number of program arguments. (This integer is greater than or equal to one, because every HP-UX program has at least one program parameter, the program name.) argn An HP Pascal string that contains the nth program argument, where n is an argument to argn and must be in the range 0..argc - 1. If n is outside this range, the run-time library generates a range error. The call argn(0) returns the program name. argv A pointer to a null-terminated array of pointers, each of which points to a null-terminated PAC that contains an argument (see the export section of the arg module, on the next page). The module arg belongs to the default module library /usr/lib/paslib; therefore, your program can import it without specifying a library with the SEARCH compiler option. The export section for the module arg is: MODULE arg; EXPORT TYPE arg_string1024 = string[1024]; arg_type = PACKED ARRAY[1..32000] OF char; argarray = ARRAY[0..32000] OF ^argtype; argarrayptr = ^argarray; FUNCTION argv : argarrayptr; FUNCTION argc : integer; FUNCTION argn (n : integer) : arg_string1024; IMPLEMENT . . . . END. Example $STANDARD_LEVEL 'HP_MODCAL'$ PROGRAM arg_demo (input, output); VAR f : text; line : string[255]; fname : string[80]; IMPORT arg; BEGIN IF argc > 1 THEN BEGIN {If a program argument was passed ...} fname := argn(1); {assign it to fname ...} reset(f,fname); {reset the file fname ...} WHILE NOT eof(f) DO BEGIN {and list its contents.} readln(f,line); writeln(line); END; END; {IF} END. {arg_demo} Associating Program Header Files with Run-Time Parameters On HP-UX, files defined in the program header are implicitly associated with run-time parameters. For example, if the program header is: PROGRAM myprog (input, output, file1, file2); then when the program myprog is run with command-line arguments, file1 is bound to the first argument, and file2 is bound to the second. The predefined files input, output, and stderr are not subject to this implicit association. Other command-line arguments that are not subject to this implicit association are those that begin with plus (+) and minus (-). For example, if the compiled program produced from the above example is run with the command: a.out -opt1 arg1 +opt2 arg2 arg3 then file1 is bound to arg1 and file2 is bound to arg2. Therefore, if the program executes the statement: reset (file1); it is equivalent to the statement: reset (file1, 'arg1'); If there is no run-time argument for a program header file, then the upshifted formal name of the file is implicitly associated with it. For example, if the program above is run with the command: a.out arg1 then there is no run-time argument for file2, so it is associated with the file named FILE2. Of course, if you provide an explicit association, it overrides this implicit association. Also, if the file is already open before the statement executes, the usual rules apply (that is, the previous association is maintained). Interrupt Handling Your program can trap HP-UX interrupts (SIGINT and SIGQUIT, for example). The recommended way to trap these signals is to make explicit calls to the HP-UX system routine signal.
NOTE The HP9000 series 200 run-time routine catch_signals is supported, but a call to this routine will severely affect the error-handling mechanisms described in Chapter 11 , because those depend on trapping certain HP-UX signals themselves (namely, SIGILL, SIGFPE, SIGBUS, SIGSEGV, and SIGSYS). Use of this routine is strongly discouraged.
Example PROGRAM prog; CONST BADSIG = -1; SIG_DFL = 0; SIG_IGN = 1; SIG_INT = 2; SIG_QUIT = 3; VAR Old_Action : integer; FUNCTION signal (SignalNum : integer; ProcAddress : integer) : integer; EXTERNAL; The function signal accepts a signal number, SignalNum, and a procedure address, ProcAddress. Whenever the signal with the number SignalNum is raised, the function transfers control to the procedure with the address ProcAddress. The function signal returns the old stored value of ProcAddress. PROCEDURE InterruptHandler (SignalNum : integer); EXTERNAL; BEGIN Old_Action := signal (SIGINT, Baddress (InterruptHandler)); IF Old_Action = SIG_IGN THEN Old_Action := signal (SIGINT, SIG_IGN) ELSE IF Old_Action = BADSIG THEN {An invalid SignalNum or ProcAddress was passed}; Old_Action := signal (SIGQUIT, Baddress (InterruptHandler)); IF Old_Action = SIG_IGN THEN Old_Action := signal (SIGQUIT, SIG_IGN) ELSE IF Old_Action = BADSIG THEN {An invalid SignalNum or ProcAddress was passed}; END. When either of the signals SIGINT or SIGQUIT is raised (by entering CONTROL C on the keyboard, for example), the procedure InterruptHandler is called.
NOTE In the preceding example, if InterruptHandler is to return to the main program, its first action must be to rearm the signal mechanism (in the manner described above) for the signal that was trapped. This is necessary because every time a signal is trapped, the HP-UX operating system resets its action information (the stored value of ProcAddress) to SIG_DFL (the default action). The program cannot resume normal execution and trap interrupts again unless it rearms the signal handler.
Run-Time Error Handling If HP-UX detects a run-time error, it aborts the program unless the program defines error recovery code. Error recovery code can catch run-time errors that originate from: * In-line compiled code (for example: range violation errors, nil pointer errors, math overflow errors). * Run-time support routines (for example: string, set, math). * Pascal file system (I/O errors). * HP-UX file system support (system errors). * Hardware (signals), except the kill signal. When compiling a program, the compiler generates code that will call the predefined procedure escape if HP-UX detects a run-time error in the compiled program. The procedure escape transfers control to the program's error recovery code (if the program has no error recovery code, the program aborts). For a complete explanation of error recovery code, see Chapter 11 . Run-time errors in in-line compiled code are unique in that they can be suppressed--that is, you can tell the compiler not to generate code to catch them (see the compiler option RANGE in the HP Pascal/HP-UX Reference Manual). Run-time errors from other sources cannot be suppressed. Most run-time errors that arise from interaction between in-line compiled code and run-time support routines are I/O errors. A few are system errors.


MPE/iX 5.0 Documentation