Cross Reference

Overview

The Cross Reference Generator is the compiler module responsible for generating the Cross Reference Listing, appearing in the Listing File. It is called if the user has specified the -xref switch.

The Cross Reference Listing is an alphabetic listing of user defined symbols with their associated attributes, such as data type, relative memory address, etc. In addition, the source line number of each occurrence of the symbol is given with an indicator of the type of use:

d

definition or declaration of the symbol. This includes occurrence of a symbol in a declaration or definition statement.

r

reference of the symbol.

i

initialization of the symbol.

m

modification of the symbol’s value. (NOT IMPLEMENTED) This includes occurrence of a symbol on the left side of an assignment or in a declaration with an initializer.

a

The symbol is an operand of the address (unary &) operator.(NOT IMPLEMENTED)

Data Structures

Symbol Table — contains symbol names and attributes used in the Cross Reference Listing. See section 11.

Reference File — temporary binary file containing a record for each occurrence of a user defined symbol in the input source. This file is written only if the -xref flag is specified. All records are written by the Semantic Analyzer.

Each record consists of 3 words :

  1. symbol table pointer to a user defined symbol (type INT).

  2. source input file line number of occurrence (type ``short``int ). Negated if occurrence was in an include file? (HAVE NOT DETERMINED HOW TO HANDLE INCLUDE FILES.)

  3. type of occurrence (type ``short``int ). One of the characters d, r, i, m, or a, representing the occurrence types defined above.

Processing Overview

The Cross Reference Generator performs the following steps:

  1. Reads the Reference File and constructs a list of references for each symbol. All reference records are read into memory. The symbol pointer field is used to link the records to the appropriate list. The head of the list is pointed to by a field in the symbol table entry for the symbol referenced. Macros exist to access this field.

  2. Sorts referenced symbols alphabetically using a mergesort. Insertion sort is used for small subsequences. To determine whether or not a symbol is referenced, only the Reference File records are used, not the symbol table REF flag or any other symbol table field. The insertion sort is responsible for excluding nonreferenced symbols of the symbol table.

  3. Writes the Cross Reference Listing.