Runtime - Variables Storage and Access of Variables Three types of - - PowerPoint PPT Presentation

runtime variables storage and access of variables
SMART_READER_LITE
LIVE PREVIEW

Runtime - Variables Storage and Access of Variables Three types of - - PowerPoint PPT Presentation

Todays Topic Runtime - Variables Storage and Access of Variables Three types of data memory (variables) Globals , locals , and dynamic/heap (new) Focus on first two for now How does compiler manage allocation of, reading of, and


slide-1
SLIDE 1

Today’s Topic

Runtime - Variables

slide-2
SLIDE 2

Storage and Access of Variables

Three types of data memory (variables)

  • Globals, locals, and dynamic/heap (new)
  • Focus on first two for now
  • How does compiler manage allocation of, reading
  • f, and storing into variables?

Continue with base + offset base + offset strategy

  • Scope vars allocated in-order on Sparc
  • Oberon scope Sparc base pointer (register)
  • Oberon var decl offset from base pointer
  • Offset is sum of sizes of preceding variables

Modelling of Oberon, compiler, Sparc memory

slide-3
SLIDE 3

Global Variables

VAR z : INTEGER; VAR w : REAL; PROC… split ... w + z… END; (* code *) VAR A : ARRAY 5 OF INTEGER;

  • Compiler symbol table & scopes?
  • Sparc Memory?
  • What is address of:

z z w w A A

Static (global) Instructions (code) Dynamic (Heap) LIFO (Stack) gp gp

  • pc

pc

  • ??

??

  • sp

sp

  • 0x00000000

0x07FFFFFF

slide-4
SLIDE 4

Global Variables

Rewrite as C code and compile “cc –S”

.seg "data" .common _z _z, 0x4,"data" .common _w _w, 0x4,"data" ... set _w _w,%o0 ; set address ld [%o0],%o0 ; load from address set _z _z,%o1 ld [%o1],%o1

More consistent with handling of locals:

set _z _z, %g7 ; base is zero offset from first global … ld [%g7+4],%o0 ; true base + offset style ld [%g7+0],%o1

VAR z : INTEGER; VAR w : REAL; PROC… split ... w + z… END; VAR A : ARRAY 5 OF INTEGER; VAR z : INTEGER; VAR w : REAL; PROC… split ... w + z… END; VAR A : ARRAY 5 OF INTEGER;

slide-5
SLIDE 5

Local Vars – hard due to recursion

PROCEDURE quicksort( VAR A A : ARRAY OF INTEGER; low low, high high : INTEGER) VAR mid mid : INTEGER; BEGIN IF low < high THEN mid := split(A, low, high); quicksort(A, low, mid); quicksort(A, mid+1, high); END; END quicksort;

What is the address of A A low low high high mid mid

sp sp

  • fp

fp

  • Locals & temps

State w/sv’d fp/sp/pc Params & return Locals & temps State w/sv’d fp/sp/pc Params & return Locals & temps State w/sv’d fp/sp/pc Params & return

0x07FFFFFF (bottom)

Call stack with 3 frames

mid (locals & temps)

  • ther registers

(state)

  • ld sp
  • ld fp

return pc high low A

return value

Call frame sp sp

  • fp

fp

slide-6
SLIDE 6

Design Considerations

“Code to specification” to get good interface

  • Approach top-down from use, incremental (start with INTEGER)
  • Implies “base” and “offset” methods for STO
slide-7
SLIDE 7

Design Considerations

“Code to specification” to get good interface

  • Approach top-down from use, incremental (start with INTEGER)
  • Implies “base” and “offset” methods for STO

Machine details deserve their own class

  • Machine architecture could change, use differently
  • A façade class on range of machine details

– Register classes, allocation; machine instructions…

slide-8
SLIDE 8

Design Considerations

“Code to specification” to get good interface

  • Approach top-down from use, incremental (start with INTEGER)
  • Implies “base” and “offset” methods for STO

Machine details deserve their own class

  • Machine architecture could change, use differently
  • A façade class on range of machine details

– Register classes, allocation; machine instructions… String base() { // ExprSTO if (this.isLocal()) { // “Local” property inherited from scope return Machine.localBase(); } else if … } // Now what about offset()?

slide-9
SLIDE 9

Design Considerations

“Code to specification” to get good interface

  • Approach top-down from use, incremental (start with INTEGER)
  • Implies “base” and “offset” methods for STO

Machine details deserve their own class

  • Machine architecture could change, use differently
  • A façade class on range of machine details

– Register classes, allocation; machine instructions… String base() { // ExprSTO if (this.isLocal()) { // “Local” property inherited from scope return Machine.localBase(); } else if … } // Now what about offset()? int size() { // ExprSTO return this.type().size(); }

slide-10
SLIDE 10

Design Considerations

“Code to specification” to get good interface

  • Approach top-down from use, incremental (start with INTEGER)
  • Implies “base” and “offset” methods for STO

Machine details deserve their own class

  • Machine architecture could change, use differently
  • A façade class on range of machine details

– Register classes, allocation; machine instructions… String base() { // ExprSTO if (this.isLocal()) { // “Local” property inherited from scope return Machine.localBase(); } else if … } // Now what about offset()? int size() { // ExprSTO return this.type().size(); } int size() // IntegerType { return Machine.intSize(); } // rep bool as int, BTW