Tutorials - Resolving symbols

Tutorials - Resolving symbols

Pass - defining labels

Defining labels can be performed during the first pass (see lectures) or we can make it as a separate independent pass (after reading and parsing the source code).

If you follow the (simplified) visitor design pattern you may write a method

  • Node.activate(Code)

which appropriately defines the symbol (given by the label if it exists).

Pass - resolving (right) symbols

Resolving symbols is performed during the second pass (see lectures) or it can be separate independent pass.

a) Expand the class Node with the method:

  • resolve(Code code)

which resolves any symbols used in the operands of the instructions. Of course, you will need to override this method in some subclasses of  Node. When doing this be careful at:

  • directives - some directives need not only to resolve symbol but also must change other attributes such as the code start address, base register value etc.
  • instructions of format 3 - check also the resolved operand if it is in the required interval
  • instructions of format 4 - should not support (as specified in the standard) PC-relative and base-relative addressing.

When resolving symbols follow the instructions in the slides, e.g., addressing priority: PC-relative, base, direct.

b) Expand the class Code with the method

  • resolve()

which initiates resolving of symbols for all the instructions by using the visitor design pattern.

Последнее изменение: Sunday, 9 December 2018, 02:42