Title: Lecture 20 Types Offsets Revisited
1Lecture 20 Types / Offsets Revisited
CSCE 531 Compiler Construction
- Topics
- Procedural Abstraction
- Activation records
- Readings 8.2
March 29, 2006
2Overview
- Last Time
- Review Semantics actions for function invocation
- Review Semantics actions for arglist
- Attribute placeList list of identifiers
- Handling Function Definitions
- Todays Lecture
- Final reductions of statement lists in
programs/functions/procedures - Passing Parameters
- Array.c
- Nested Scope
- Nested.c
- References Section 8.2
- Homework
3Test 2 - TIME CHANGE !!!!!
- Test 2 - TIME CHANGE !!!!!
- Wednesday April 5 700PM
- First Robotics Volunteers Friday March 31,
500-700PM - Graduate Assistants - I need to see after class!
- AARONS,
- AL-ABRI,
- BYRNES,
- GARRETT,
- GREGORY,
- KODUR,
- SAXENA,
- TEMLYAKOV,
- VARGHESE,
- TALATAM
4Some Email Questions
- How do we handle running out of pace in quad
arrays? Again with corrections - When an if-then statement is last statement in
program (or function) how do we backpatch?
5Question on size of code arrays
- What happens when you run out of space?
- Nextquad gt arraySize
void gen(int op) static int opcodeNULL
static int arraySize 0 static int nextquad
0 if (nextquad gt arraySize)
arraySize ARRAY_INCREMENT opcode (int
) realloc(opcode, arraySize)
opcodenextquad op
Need to be a globals Why?
6Final reductions of statement lists
7Precedence of Operators
- Dear Dr. Matthews
- About the operator precedence, if I have
- a b c,
- What will be the order?
- Is that first evaluate bc then a
- (bc) or first a b then (ab) c?
- Best
8C type booleans Not for Project 4!!!
- The grammar for handling the logical operator
not - Is B ? NOT B
- Not B ? '!' E , which would be fine in C
-
- /CODE FOR THE ('not' B)
EXPRESSION/ -
9Parameter Passing
- Call by value
- Call by reference
- Copy-restore
- Call by name
- Logically the procedure is treated as a macro
with the arguments substituted for the formal
parameters - Actually code passed for evaluating the argument
is passed to the functions
10(No Transcript)
11Declarations within Functions/Procedures
- Figure 8.11 differences in approaches
- P ? offset 0 D // place code instead
of marker - D ? D D
- D ? ID T enter(id.place, T.type,
offset) - offset offset T.width
-
12Types within the Declarations
- T ? integer T.type INTEGER T.width 4
- double T.type double T.width 8
- array num of T1
- T.type array(num.val, T1.type)
- T.width num.val T1.width
-
- T1 T.type pointer(T1.type)
- T.width 4
-
13Representing Type Information
- Type tree
- Nodes
- Leaves Base types int, float
- Interior Nodes Type Constructors
- Array (size, dimensions, type)
- or maybe array of array for 2 dimensions
- Pointer ( targetType)
- FuncReturning
- Record ( componentTypeList )
14Type Example
15Type Encoding
- Base types
- boolean 0000
- char 0001
- int 0010
- double 0011
- Type constructor encodings -
- pointer 01
- array 10
- freturns 11
- Why encode at all?
16Handling Records
17Structural and Name Equivalence of Types
- Two identifiers are name equivalent if the types
have the same name. - Two identifiers are structurally equivalent if
the types have the same structure (type tree).