Pristine Ack-5.5
[Ack-5.5.git] / doc / ego / ca / ca1
1 .bp
2 .NH 1
3 Compact assembly generation
4 .NH 2
5 Introduction
6 .PP
7 The "Compact Assembly generation phase" (CA) transforms the
8 intermediate code of the optimizer into EM code in
9 Compact Assembly Language (CAL) format.
10 In the intermediate code, all program entities
11 (such as procedures, labels, global variables)
12 are denoted by a unique identifying number (see 3.5).
13 In the CAL output of the optimizer these numbers have to
14 be replaced by normal identifiers (strings).
15 The original identifiers of the input program are used whenever possible.
16 Recall that the IC phase generates two files that can be
17 used to map unique identifying numbers to procedure names and
18 global variable names.
19 For instruction labels CA always generates new names.
20 The reasons for doing so are:
21 .IP -
22 instruction labels are only visible inside one procedure, so they can
23 not be referenced in other modules
24 .IP -
25 the names are not very suggestive anyway, as they must be integer numbers
26 .IP -
27 the optimizer considerably changes the control structure of the program,
28 so there is really no one to one mapping of instruction labels in
29 the input and the output program.
30 .LP
31 As the optimizer combines all input modules into one module,
32 visibility problems may occur.
33 Two modules M1 and M2 can both define an identifier X (provided that
34 X is not externally visible in any of these modules).
35 If M1 and M2 are combined into one module M, two distinct
36 entities with the same name would exist in M, which
37 is not allowed.
38 .[~[
39 tanenbaum machine architecture
40 .], section 11.1.4.3]
41 In these cases, CA invents a new unique name for one of the entities.
42 .NH 2
43 Implementation
44 .PP
45 CA first reads the files containing the procedure and global variable names
46 and stores the names in two tables.
47 It scans these tables to make sure that all names are different.
48 Subsequently it reads the EM text, one procedure at a time,
49 and outputs it in CAL format.
50 The major part of the code that does the latter transformation
51 is adapted from the EM Peephole Optimizer.
52 .PP
53 The main problem of the implementation of CA is to
54 assure that the visibility rules are obeyed.
55 If an identifier must be externally visible (i.e.
56 it was externally visible in the input program)
57 and the identifier is defined (in the output program) before
58 being referenced,
59 an EXA or EXP pseudo must be generated for it.
60 (Note that the optimizer may change the order of definitions and
61 references, so some pseudos may be needed that were not
62 present in the input program).
63 On the other hand, an identifier may be only internally visible.
64 If such an identifier is referenced before being defined,
65 an INA or INP pseudo must be emitted prior to its first reference.