Lecture 16
Lecture 16
ENVIRONMENTS
Compiler Front- and Back-end
Source program (character stream) Abstract syntax tree or
other intermediate form
Scanner
(lexical analysis) Machine-Independent
Tokens Code Improvement
Parser
Back end
synthesis
analysis
(syntax analysis)
Parse tree Target Code Generation
:=
id1 +
id2 *
id3 60
:=
•-> AST Id1(val) +
Id2(val) *
id3(val) 60 (const)
Code Generation and Intermediate Code
Forms
Static allocation
Compiler makes the decision regarding storage allocation by looking
only at the program text
Dynamic allocation
Storage allocation decisions are made only while the program is
running
Stack allocation
Names local to a procedure are allocated space on a stack
Heap allocation
Used for data that may live even after a procedure call returns
Ex: dynamic data structures such as symbol tables
Requires memory manager with garbage collection
Static Data Storage Allocation
Compiler allocates space for all
variables (local and global) of all
procedures at compile time
No stack/heap allocation; no
overheads
Ex: Fortran IV and Fortran 77
Variable access is fast since
addresses are known at compile
time
No recursion
Dynamic Data Storage Allocation
Compiler allocates space only for global variables at
compile time
Space for variables of procedures will be allocated at
run-time
Stack/heap allocation
Ex: C, C++, Java, Fortran 8/9
Variable access is slow (compared to static allocation)
since addresses are accessed through the stack/heap
pointer
Recursion can be implemented
Activation Record Structure
An activation record is Temporaries
chunk of computer
Local Data
memory which holds the
arguments and “normal” Machine status
local variables of a
Access Link
function.
An activation record for a Control Link
procedure has fields to Parameters
holds machine status
information, result, local Return Values
variables and so on.
Activation Record Structure….
Temporaries: Expression is evaluated in it. (X=y+Z)
Local variables of the procedure find a place here, then we require
temporaries to evaluate large expression and so on and so forth.
Access link: non local data is accessed.
Control link: Points the activation record of the caller.
Actual parameters which are passed to this particular procedure call are
stored here. The caller will evaluate the parameters and then depending
on the type of parameter passing, either the value or the address is
placed in the actual parameter list.
Activation Record Structure…
Return Value: Value to be return is stored in this.
Machine status holds information about machine status
before procedure call.
The machine status for example, the caller would be
using some registers and before calling this particular
procedure, it would have saved its registers but, this
procedure possibly calls some other procedure and then
it has to store its register contents in some place. So
saved machine status is the place, where it stores the
registers before calling the next procedure.