8. Variable names

As well as choosing a type, Relogix also needs to choose a name for each variable and parameter in the translated code. In the case of global data, it can usually choose a name based on the assembler label. But for data which in the assembler code was held in registers, on the stack, or in a condition code, there is no meaningful assembler name.

One possible solution would be simply to use register names, for example a0_1 and a0_2 for the two uses of register A0 in our example. However, this would make for code which is both unreadable and hard to maintain. Relogix instead tries to choose as meaningful a name as possible for each variable. To do this, it uses a variety of techniques. These include looking in the assembler comments for clues as to what the variable represents, as well as seeing how the variable is used and what its type is.

In our example, it has chosen i for the variable corresponding to the D0 register (ECX in the x86 version), because it is used as a loop counter. It has chosen tok_ptr for the function parameter corresponding to A0 (ESI), because it is a pointer to a structure for which it has been able to deduce a name from the assembler definitions. It has little information for A1 and A0 (EDI and ESI) inside the loop, so it has chosen general names suitable for pointers.

For the variable corresponding to D1 (EAX in the x86 version), it has found an assembler comment which looks helpful:

    MOVE.L    (A0)+,D1       ; Get token

It has therefore chosen the name token for the variable.