XTRAN Example — Analyze 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:

The following example identifies and reports all of the above problems.  It uses standard rule sets that we deliver with our VAX MACRO analysis version of XTRAN.  The analysis and reporting rules comprise about 600 non-comment lines of XTRAN's rules language, which we call "meta-code".

The procedure is to run the operand analysis on all source files, appending the results to a single text data file.  When all modules have been analyzed, a final XTRAN run is done with a set of reporting rules that reads the text data file and generates the analysis output.

The analysis output shows all occurrences of each instance of each of the problems specified above, in all analyzed source files.  (In the example below, we analyzed only one source file.)

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 identify the problems and fix them than to let XTRAN translate them.  Once they have been identified by an analysis such as this one, and suitable fixes have been determined, XTRAN has facilities to automate the cleanup as part of the translation process.  Click for an actual translation example using this technique.

The input to and output from XTRAN are untouched, except that line numbers have been added to the input for reference.



Process Flowchart

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

process flowchart

Input to XTRAN:  deman4-a.mar

44 A    =       1
45 B    =       2
46      MOVL    A+1(R2),2(R3)   ;expr offset, num offset
47      MOVL    UNKN(R1),R2     ;ambig opnd
48      MOVL    WS+2,R2         ;expr addr
49 C    =       .               ;parsed as "C:"
50      MOVL    A+1(R2),4(R3)   ;expr offset, num offset
51      MOVL    WS+2,R2         ;expr addr
52      MOVL    A+2(R2),2(R3)   ;expr offset, num offset
53      MOVL    WS+2,R2         ;expr addr
54      BRW     .+4             ;PC occurrence
55      MOVL    A+1(R2),2(R3)   ;expr offset, num offset
56      MOVL    WS+4,R2         ;expr addr
57 .    =       1000            ;PC occurrence
58      MOVL    #WS+4,R2        ;expr addr
59      MOVL    UNKN(R1),R2     ;ambig opnd
60 WS:  .BLKW   1


Output from XTRAN:

Total of 2 numbers as offsets:

2 (3):
    deman4-a.mar . . . . . . .  46, 52, 55
4 (1):
    deman4-a.mar . . . . . . .  49

Total of 2 expressions as offsets:

A+1 (3):
    deman4-a.mar . . . . . . .  46, 49, 55
A+2 (1):
    deman4-a.mar . . . . . . .  52

Total of 2 expressions as addresses:

WS+2 (3):
    deman4-a.mar . . . . . . .  48, 51, 53
WS+4 (2):
    deman4-a.mar . . . . . . .  56, 58

Total of 1 ambiguous operand:

UNKN(R1) (2):
    deman4-a.mar . . . . . . .  47, 59

Program Counter references:

. (1):
    deman4-a.mar . . . . . . .  57