XTRAN Example — Translate HP (Digital, Compaq) VAX MACRO Problem Operands

In translating VAX MACRO to C, a number of types of assembler operands can cause problems.  These include:

XTRAN has the ability to handle numeric and expression offsets and expression addresses automatically, by generating appropriate address arithmetic in C.  However, the tradeoff is C code that is less readable and not as easily maintained.  So it is usually better to use XTRAN to identify the problems and fix them than to let XTRAN translate them "as is".

You can use XTRAN's VAX MACRO analysis version to find and report all occurrences of these types of operands in a body of VAX MACRO code, using standard rule sets.  The analysis output shows all occurrences of each instance of each of the problem operands, in all analyzed source files.  Click for such an analysis example.

Once you have used XTRAN to identify the problem operands using such an analysis, and have determined suitable fixes for them, XTRAN has facilities to automate the cleanup as part of the translation process.

The input to and output from XTRAN are untouched, except that rules are elided and described.



Process Flowchart

Here is a flowchart for this process, in which the elements are color coded:

process flowchart

Input to XTRAN:

<Rule to declare the following to XTRAN in C:>

        typedef struct str
            {
            long memb;
            long memb2;
            long memb3;
            }
            Str;

        Str str1;

<Rules to replace all MEMB+4 with MEMB2 and all MEMB+8 with MEMB3 in VAX
MACRO before translation>

        MOVL    MEMB+4(R2),R1           ;MOVL MEMB+4(R2),R1
        MOVL    4+MEMB(R2),R1           ;MOVL 4+MEMB(R2),R1
        MOVL    MEMB+4+STR1,R1          ;MOVL MEMB+4+STR1,R1
        MOVL    4+MEMB+STR1,R1          ;MOVL 4+MEMB+STR1,R1
        MOVL    STR1+<MEMB+4>,R1        ;MOVL STR1+<MEMB+4>,R1
        MOVL    STR1+<4+MEMB>,R1        ;MOVL STR1+<4+MEMB>,R1

        MOVL    MEMB+8(R2),R1           ;MOVL MEMB+8(R2),R1
        MOVL    8+MEMB(R2),R1           ;MOVL 8+MEMB(R2),R1
        MOVL    MEMB+8+STR1,R1          ;MOVL MEMB+8+STR1,R1
        MOVL    8+MEMB+STR1,R1          ;MOVL 8+MEMB+STR1,R1
        MOVL    STR1+<MEMB+8>,R1        ;MOVL STR1+<MEMB+8>,R1
        MOVL    STR1+<8+MEMB>,R1        ;MOVL STR1+<8+MEMB>,R1

Output from XTRAN:

        extern long r1;
        extern Str *r2;

        Str str1;

        r1 = r2->memb2;                         /*movl memb+4(r2),r1*/
        r1 = r2->memb2;                         /*movl 4+memb(r2),r1*/
        r1 = str1.memb2;                        /*movl memb+4+str1,r1*/
        r1 = str1.memb2;                        /*movl 4+memb+str1,r1*/
        r1 = str1.memb2;                        /*movl str1+<memb+4>,r1*/
        r1 = str1.memb2;                        /*movl str1+<4+memb>,r1*/
        r1 = r2->memb3;                         /*movl memb+8(r2),r1*/
        r1 = r2->memb3;                         /*movl 8+memb(r2),r1*/
        r1 = str1.memb3;                        /*movl memb+8+str1,r1*/
        r1 = str1.memb3;                        /*movl 8+memb+str1,r1*/
        r1 = str1.memb3;                        /*movl str1+<memb+8>,r1*/
        r1 = str1.memb3;                        /*movl str1+<8+memb>,r1*/