HP 3000 Manuals

Step Two: Rewrite SPL to Look Like HP C/XL [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation


SPL to HP C/XL Migration Guide

Step Two:  Rewrite SPL to Look Like HP C/XL 

The case sensitivity of HP C/XL is one of the first differences between
these two languages that an SPL programmer is liable to notice.  Because
SPL ignores case, some SPL programs have examples of the same reserved
word or variable name appearing in both upper- and lowercase at various
points in the source.  In HP C/XL, these names will be interpreted as
different entities.  HP C/XL keywords must be expressed in lowercase.
Many HP C/XL programmers tend to specify #define macro identifiers in
uppercase to distinguish them from function names, but there are no
universally accepted standards.

As a first step, convert the SPL source to all uppercase (except for
strings, of course).  When you convert to HP C/XL in the next step,
reserved and keywords will shift to lowercase, and the identifiers of
variables, etc., will remain in uppercase, thereby avoiding any possible
conflict with HP C/XL reserved words and library function names.

There are a number of other changes which may be made to SPL programs,
causing them to conform more closely to HP C/XL forms, and rendering them
easier to translate.

For example, HP C/XL does not allow nested functions, so SPL subroutines
will be awkward to translate.  Careful examination now of any subroutines
used in your SPL program will give you a head start on determining how
best to eliminate the subroutines.

Possibilities are:  moving the subroutine code inline (meaning that the
code will be repeated wherever the subroutine is called, possibly by
means of a DEFINE), or converting the subroutine to an SPL procedure.  In
the latter case, variables in the procedure that are accessed by the
subroutine will have to be supplied as parameters, or declared global to
both the new procedure and its caller.  In many cases, these variables
were declared in the procedure simply for use by the subroutine, which
means they may be declared within the new procedure.

Also, be alert for the possibility that identical subroutines were
declared local to more than one procedure; they could all be replaced by
one global procedure.

Another change that may be easier to debug prior to converting to HP C/XL
is the elimination of any pass-by-reference procedure parameters.  By
changing such parameters to pass-by-value pointers, and then changing the
actual parameters to addresses (generated with the "@" operator), the
process of passing and accessing parameters in the same manner as HP C/XL
may be tested in an SPL environment.  Remember that unsubscripted array,
pointer, and procedure identifiers passed by reference do not require any
modification.

Because the natural data size of HP C/XL is 32 bits, you should convert
as many SPL INTEGER variables to SPL DOUBLE as possible.  This will
result in a more efficient final HP C/XL program.

There are a few HP C/XL reserved words that are also reserved words in
SPL, and there always exists the possibility that an SPL variable name
has a unique meaning as an HP C/XL reserved word.  All keywords in HP
C/XL must be in lowercase, but relying on case differences to
differentiate between reserved words and variable names is bad practice.

The following is a list of words which are reserved in both languages,
but do not always mean the same thing:

CASE        This is a statement in SPL, but, as case, it is used to label
            switch alternatives in HP C/XL.

DO          This statement is very similar, but SPL performs a DO-WHILE
            test, while HP C/XL performs a do-until test.

DOUBLE      This is a 32-bit signed integer in SPL, but a 64-bit IEEE
            floating point number in HP C/XL. Variables declared DOUBLE
            in an SPL program must be converted to type [long] int when
            converting to HP C/XL.

ELSE        This word is very similar in both languages, therefore simply
            make certain that else is in lowercase at the time of
            conversion.  Also, make sure the statement before the else
            ends with either a semicolon, ";", or a right brace, "}".

FOR         This is a similar statement that has different syntax.  See
            "FOR Statement".

GOTO        This is an identical operation, but SPL allows both GO and
            GOTO. Changing both to lowercase goto is valid SPL and
            prepares for the move to HP C/XL.

IF          This statement is identical in both languages, but has
            slightly different syntax.  Change the word to lowercase.

LONG        In SPL, this is a 64-bit floating point number in the MPE V
            format.  In HP C/XL, long is a 32-bit integer.  Be certain to
            convert it to double in HP C/XL. Also remember that the
            64-bit floating-point internal formats are quite different on
            the two systems.

RETURN      This causes a return from a procedure or subroutine in SPL,
            and also causes a return from a function in HP C/XL. Remember
            to remove the SPL parameter and add the HP C/XL return value.
            (See "RETURN Statement").

SWITCH      In SPL, this declares a list of labels to be branched to by
            an indexed GOTO. In HP C/XL, switch is a statement type,
            analogous to the SPL CASE. (See "GO TO Statement").

WHILE       This function is identical in both languages, having only a
            slight difference in syntax.

The following are HP C/XL reserved words.  Examine the SPL source for any
use of these words as variable names.

auto           default        extern         int            sizeof         union
break          do             float          long           static         unsigned
case           double         for            register       struct         void
char           else           goto           return         switch         while
continue       enum           if             short          typedef

You should also avoid the following proposed ANSI C reserved words:

const          signed         volatile

SPL array declarations should be examined for cases that have a nonzero
lower bound.  This is not allowed in HP C/XL, and should be recoded to
work properly with a lower bound of zero.  Remember that indirect (and
many direct) arrays can be coded in HP C/XL with a pointer to cell zero.

BYTE arrays used for storing ASCII strings should be examined for how
they are used and, if possible, a NUL ('\0', numeric value zero) should
be placed in the last byte.  This is done to facilitate later use of the
HP C/XL convention, which expects a NUL to terminate a string.

Be especially careful with cases where word pointers were converted to
byte pointers (and vice versa) by means of shift, multiply, or divide
operations.  All pointers in HP C/XL will refer to byte addresses, so
these operations will rarely translate without careful recoding.

Bit operations in SPL are performed for two reasons.  One is to unpack
data words read by the program from external files, and the other to
conserve data storage for variables used by the program.  In the latter
case, consider declaring whole words for the individual fields and
eliminating the bit operations entirely.

The SPL switch declaration may be left alone at this stage.  It will be
converted into an HP C/XL #define macro directive in step 3.  See "GO TO
Statement" and "CASE Statement".

Certain operations, such as passing labels as parameters, are not
permitted in HP C/XL, so now could be the time to recode the necessary
operation in more translatable constructs.  In general, operations that
use extra data segments and split stack operations, should be removed and
rewritten (if possible), or at least isolated into separate procedures.

As a final consideration to HP C/XL, move all of the SPL program's outer
block executable statements into a new procedure named main, and make the
new outer block consist of a single statement, calling this procedure.
These changes will bring an SPL program as close to HP C/XL conventions
as possible, and should be thoroughly tested in this form before making
the plunge into HP C/XL itself.



MPE/iX 5.0 Documentation