[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP Pascal for OpenVMS
|
Previous | Contents | Index |
%ARCH_NAME returns a string containing "IA64", "Alpha", or "VAX" depending on the architecture of the system on which the compilation is taking place.
%SYSTEM_NAME returns a string containing "OpenVMS."
%SYSTEM_VERSION returns a string containing the value of SYI$_VERSION from the $GETSYI system-service.
For example:
program example(output); begin writeln('Program running on ',%system_name, ' ',%arch_name, ' ',%system_version); end. |
This example uses the %IF directive to selectively provide declarations or code based on the architecture:
%if %arch_name = "Alpha" %then var handle : integer := 0; %elif %arch_name = "IA64" %then var handle : integer64 := 0; %endif |
%DATE returns a string containing the date at the beginning point of the compilation.
%TIME returns a string containing the time at the beginning point of the compilation.
%COMPILER_VERSION returns a string containing the version string of the HP Pascal compiler performing the compilation.
%LINE returns an integer that denotes the current line number in the source file.
%FILE returns a string containing the file name that is currently being compiled. The string contains a full OpenVMS file specification including the disk, directory, file name, file type, and version fields.
%ROUTINE returns a string with the name of the routine that is currently being compiled. If used in the executable portion of a program, the program's name is returned. If used in the declaration section of a MODULE/PROGRAM, the name of the MODULE/PROGRAM is returned.
%MODULE returns a string containing the name of the module/program that is currently being compiled.
%IDENT returns a string that contains the ident string of the compilation that is set with the [IDENT()] attribute.
This chapter describes how the HP Pascal compiler allocates and represents program components. It discusses the following topics:
This chapter describes how to establish program sections and program section properties. The HP Pascal compiler uses contiguous areas of memory, called program sections, to store information about a program.
The compiler writes these program sections to the object file. When constructing an executable image, the OpenVMS Linker divides the image into sections. Each image section contains program sections that have the same properties. The linker controls memory allocation by arranging image sections according to program section properties. You can use special linker options to change program section properties and to influence the memory allocation in the image. You include these options in a linker options file, which is input to the linker.
The OpenVMS Linker refers to the various characteristics of program sections as attributes. This chapter uses the term properties to avoid confusion with the HP Pascal attribute classes.
Table A-1 lists the possible program section properties on OpenVMS systems.
Property | Description |
---|---|
PIC/NOPIC | Position independent or position dependent |
CON/OVR | Concatenated or overlaid |
REL/ABS | Relocatable or absolute |
GBL/LCL | Global or local scope |
EXE/NOEXE | Executable or nonexecutable |
RD/NORD | Readable or nonreadable |
WRT/NOWRT | Writable or nonwritable |
SHR/NOSHR | Shareable or nonshareable |
Table A-2, Table A-3, and Table A-4 list the program sections that HP Pascal can establish, if necessary, on OpenVMS I64, OpenVMS Alpha, and OpenVMS VAX systems, respectively.
Program Section | Data |
---|---|
$ABS$ | No data is allocated in this program section. It is used for defining global literals (variables declared with the GLOBAL and VALUE attributes). |
$BSS$ | Zeroed static storage. |
$CODE$ 1 | Machine instructions. |
$DATA$ | Nonexternal static types; writable variables declared with the STATIC attribute; writable variables that use default allocation and are declared at program or module level of a nonoverlaid compilation unit. All such variables must be larger than 64 bits in size. |
LIB$INITIALIZE | Addresses of routines declared with the INITIALIZE attribute and compiler-generated routines to perform module initialization. |
$LINK$ | Small literals. |
$LITERAL$ 1 | Constants needing storage; nonvolatile, readonly, static variables. |
$SDATA$ | Nonexternal static types; writable variables declared with the STATIC attribute; writable variables that use default allocation and are declared at program or module level of a nonoverlaid compilation unit. All such variables must be 64 bits or smaller in size. |
Program Section | Data |
---|---|
$ABS$ | No data is allocated in this program section. It is used for defining global literals (variables declared with the GLOBAL and VALUE attributes). |
$BSS$ | Zeroed static storage. |
$CODE$ 1 | Machine instructions. |
$DATA$ | Nonexternal static types; writable variables declared with the STATIC attribute; writable variables that use default allocation and are declared at program or module level of a nonoverlaid compilation unit. |
LIB$INITIALIZE | Addresses of routines declared with the INITIALIZE attribute and compiler-generated routines to perform module initialization. |
$LINK$ | Procedure descriptors and small literals. |
$LITERAL$ 1 | Constants needing storage; nonvolatile, readonly, static variables. |
Program Section | Data |
---|---|
. ABS . | No data is allocated in this program section. It is used for defining global literals (variables declared with the GLOBAL and VALUE attributes). |
$CODE 1 | Machine instructions; constants needing storage; nonvolatile, readonly, static variables. |
LIB$INITIALIZE | Addresses of routines declared with the INITIALIZE attribute and compiler-generated routines to perform module initialization. |
$LOCAL | Nonexternal static types; writable variables declared with the STATIC attribute; writable variables that use default allocation and are declared at program or module level of a nonoverlaid compilation unit. |
PAS$GLOBAL | Writable variables that use default allocation and are declared at program or module level of an overlaid compilation unit. |
You can also establish user-defined program sections with the HP Pascal PSECT and COMMON attributes. The PSECT attribute directs the compiler to establish a separate program section for static variables or executable blocks. In this way, you can ensure particular program section properties for these objects. You can also choose to group them with related static variables and blocks to reduce the amount of paging overhead.
The COMMON attribute directs the compiler to establish a particular program section called a common block. A common block is an overlaid program section that contains one variable. By storing variables in common blocks, aHP Pascal program can share variables with programs written in other Hewlett-Packard languages.
The following example uses a common block to pass information between HP Pascal and HP Fortran:
PROGRAM Common_Example (OUTPUT); VAR Myrec : [COMMON(Example)] RECORD Intfld : INTEGER; Strfld : PACKED ARRAY [1..10] OF CHAR; END; [EXTERNAL] PROCEDURE Call_Fort; EXTERNAL; BEGIN Myrec := ZERO; Call_Fort; WRITELN('Intfld = ',Myrec.Intfld); WRITELN('Strfld = ',Myrec.Strfld); END. |
SUBROUTINE CALL_FORT C STRUCTURE /TEST/ INTEGER*4 ITEM CHARACTER * 10 ITEM_NAME END STRUCTURE C RECORD /TEST/ VAR COMMON /EXAMPLE/ VAR C VAR.ITEM = 10 VAR.ITEM_NAME = '0123456789' END |
The HP Pascal program initializes the common record, Myrec, to zero, then calls the HP Fortran routine, Call_Fort, to assign the desired values to the elements within the common record. The HP Pascal program then writes the assigned values to your terminal.
Only one variable can be allocated in a particular HP Pascal common block. To share more than one data item in the same common block, the record variable containing all shareable items is declared and used.
Whether the compiler establishes a program section, or you create one, the program section is assigned one property from each class listed in Table A-1. These properties are assigned to satisfy the requirements of the types, variables, and executable blocks that have been allocated in the same program section. Table A-5 lists the minimal properties required by various objects.
Object | Properties | |||
---|---|---|---|---|
EXE | RD | WRT | NOSHR | |
Read-only variable | X | |||
Write-only variable | X | X | X 1 | |
Read/write variable | X | X | X 1 | |
Executable block 2 (OpenVMS I64 and OpenVMS Alpha systems only) | X | |||
Executable block 2 (OpenVMS VAX systems only) | X | X |
The . ABS . and $ABS$ program section properties are ABS, NOEXE, NORD, NOWRT, and NOSHR. All other program sections except LIB$INITIALIZE are position independent and relocatable; all except those established by the COMMON attribute are concatenated and local. Program sections established by COMMON are overlaid and global. The remaining properties are assigned as follows:
If you want to guarantee that read-only variables can never be
modified, you can allocate storage exclusively for them in a separate
program section that will always remain nonwritable.
A.2 Storage Allocation
The following sections discuss storage allocation of variables, symbolic constants, and executable blocks. Static types require no allocation. Nonstatic data types require allocation to store possible run-time values. Section A.2.3 gives an example.
When allocating storage for a variable, the compiler first determines an allocation attribute for the variable. If the allocation attribute is STATIC or COMMON, the compiler then chooses a program section in which to allocate storage. The compiler applies the following rules sequentially to determine the allocation attribute:
The compiler applies the following rules sequentially to choose the program section in which to allocate storage for nonexternal common and static variables:
When allocating storage for symbolic constants and executable blocks, the compiler determines the appropriate program section by applying the same rules of scope to program section names that it applies to identifiers. The compiler always allocates storage in the program section whose name appeared in the most recent heading of a routine or compilation unit.
Table A-3 and Table A-4 describe the program sections established for each kind of data in a program unless a PSECT attribute appears in the heading of routine or compilation unit and directs that storage to be allocated in a different program section.
Example A-1 shows how the compiler establishes program sections to allocate storage for symbolic constants, variables, and executable blocks. The comments in the programs indicate the names of the program sections used.
Example A-1 Using Program Sections to Allocate Storage |
---|
PROGRAM Allocate_Variables (INPUT,OUTPUT); CONST Message_String = 'Random String Literal'; { $LITERAL on OpenVMS I64 } { $LITERAL on OpenVMS Alpha } { $CODE on OpenVMS VAX } VAR Magic_Number : [READONLY,PSECT(Magic)] INTEGER VALUE 42; { Magic } Local_Variable : INTEGER; { $SDATA$ on OpenVMS I64 } { $DATA$ on OpenVMS Alpha } { $LOCAL on OpenVMS VAX } [PSECT(Error_Routines)] PROCEDURE User_Error; CONST User_Error_Message = 'Internal Error'; { Error_Routines } VAR Error_Count : [STATIC] INTEGER VALUE 0; { $SDATA$ on OpenVMS I64 } { $DATA$ on OpenVMS Alpha } { $LOCAL on OpenVMS VAX } Message_Buffer : VARYING [132] OF CHAR; { Automatic Storage } BEGIN { Error_Routines } Error_Count := Error_Count + 1; Local_Variable := Error_Count; END; BEGIN { $CODE or $CODE$ } . . . END. |
Storage for all variables with static allocation is allocated in $SDATA$, $DATA$, or $LOCAL. Storage for the executable block of the main program is allocated in $CODE or $CODE$. Storage for the symbolic constant Message_String is allocated in $LITERAL on OpenVMS I64 and OpenVMS Alpha systems and in $CODE on OpenVMS VAX systems. Storage is allocated in the user-created program section, Error_Routines, for the symbolic constant User_Error_Message and the executable block of User_Error. Storage for Local_Variable is in $SDATA$ on OpenVMS I64 systems, $DATA$ on OpenVMS Alpha systems, and $LOCAL on OpenVMS VAX systems because it was referred to in a nested block. Storage for Magic_Number is in the user-created program section, Magic. Since Magic_Number was declared with the READONLY attribute, the program section has the NOEXE, NOWRT, RD, and SHR properties.
Previous | Next | Contents | Index |