Compiler Construction
Spring 2000
Assignment V

Due : April 12
Intermediate code generation.
The assignment consists in generating quadruples for programs written in
a small subset of Ada (a subset of Pascal, for that matter) involving
integers, one-dimensional arrays of integers, and the usual control structures.
Output of the program should be a readable sequence of quadruples; internally
you generate a sequence (an array will be fine) of records with four components:
a target, an operator, and two operands. The target and the operands are
entities or literals (integers). Some of the operands may be missing, for
unary operations, or for conditional jumps, or for labels which are instructions
on their own.
The assignment requires that you traverse the statement part of the program,
generate labels and go-tos for control structures, and temporaries for complex
expressions. You should be able to generate quadruples for the following:
function Test_Fib (N : Integer) return Boolean is
type Fib_array is array (1..100) of integer;
Fib : Fib_Array;
K : Integer;
begin
Fib (1) := 1;
Fib (2) := 1;
for J in 3 .. N loop
Fib (J) = Fib (J-1) + Fib (J-2);
end loop;
K = N;
while K > 2 loop
if Fib (K) - Fib (K-1) /= Fib (K-2) then
return False;
else
K := K -1;
end if;
end loop;
return True;
end Test_Fib;
The output can be printed using assignment syntax or using operation names
that corresponding to the assembly language you will eventually generate.
Entity names remain symbolic (N, K, Fib, etc). In the last part of the project
you will convert these into machine references (offsets from base pointers).
No need to deal with non-local variables, so no need for static chains.