cse443 compilers
play

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis - PowerPoint PPT Presentation

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei WW @ 4/5 handling of type checking in: 'assignable


  1. CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http:/ /www.cse.buffalo.edu/faculty/alphonce/SP17 /CSE443/index.php https:/ /piazza.com/class/iybn4ndqa1s3ei

  2. WW @ 4/5 handling of type checking in: 'assignable ablock' 'assignable recOp identifier' handling of records/arrays recap project 3 intermediate code expectations for pr04

  3. Assignment status PR04 - due M 4/17 @5 HW4 - out W 4/5 @5, due T 4/11 @5

  4. Phases of a compiler Intermediate Representation (IR): specification and generation Figure 1.6, page 5 of text

  5. Three address code instructions (see 6.2.1, pages 364-5) 1. x = y op z 2. x = op y (treat i2r and r2i as unary ops) 3. x = y 4. goto L 5. if x goto L / ifFalse x goto L 6. if x relop y goto L 7. function calls: - param x - call p, n - y = call p - return y 8. x = y[i] and x[i] = y x = & y, x = *y, *x = y 9.

  6. Our language primitive types: integer, real, Boolean, character built-in type: string (array of character) user-defined types: record types have names type rec : (real x := -4.79, y := 1.3) array types have names type arr : (5,10) -> string : ( "" ) function types have names type bar : ( real : x ) -> rec function f : bar { … }

  7. Our language Record field Record field primitive types: integer, real, Boolean, initialization now done initialization now done character with declaration with declaration built-in type: string (array of character) user-defined types: record types have names type rec : (real x := -4.79, y := 1.3) array types have names type arr : (5,10) -> string : ( "" ) function types have names type bar : ( real : x ) -> rec function f : bar { … }

  8. Our language primitive types: integer, real, Boolean, character We now have built-in type: string (array of character) allow multi- user-defined types: dimensional record types have names arrays type rec : (real x := -4.79, y := 1.3) array types have names type arr : (5,10) -> string : ( "" ) function types have names type bar : ( real : x ) -> rec function f : bar { … }

  9. Our language primitive types: integer, real, Boolean, character built-in type: string (array of character) user-defined types: record types have names Function types Function types type rec : (real x := -4.79, y := 1.3) must now be must now be named before named before array types have names use use type arr : (5,10) -> string : ( "" ) function types have names type bar : ( real : x ) -> rec function f : bar { … }

  10. Recusive records Recursive functions A record type must allow a component to be of the same type as the type itself: type Node: ( integer datum:=0 ; Node rest:=null )

  11. type information type indicates size type indicates storage location primitives: in current environment records: on heap arrays: on heap functions: code in static, locals on stack need to determine how to lay out records, arrays, invocation records in memory

  12. Sizes of types int: 32 bits (2's complement) real: 64 bits (IEEE 754) Boolean: 8 bits (TBD) character: 8 bit (ASCII)

  13. Sizes of types type string: ? -> character 5 bytes + length of string * size of character (= 1 byte) # size of dimension 1 (0) (1) (2) (3) (5) dims (integer) 1 0 0 0 5 V A X E S https:/ / en.wikipedia.org/wiki/VAX

  14. Sizes of types 2 # dims 0 size of 0 first 0 What is the size of a multi- dimension 2 dimensional array of type T? 0 size of 0 # of dimensions (X): 1 byte second 0 dimension 3 sizes of dimensions (S i ): X*4 bytes a(0,0) first row a(0,1) data: ( ∏ i ∈ X S i ) * sizeOf(T) a(0,2) a(1,0) second row a(1,1) a(1,2)

  15. Figure 6.16, p 375 array(2,array(3,int)) T w = 24 array(2,array(3,int)) B C w = 24 w = 4 array(3,int) int C w = 12 [2] int C w = 4 [3] 𝜁

  16. Figure 6.16, p 375 9+array(2,arr(3,character)) w = 9 + 6 * 1 = 15 T C w = 2 * 3 B w = 6 character C w = 3 w = 1 2 C 3 𝜁

  17. dblocks (6.3.5 and 6.3.6) records (in separate symbol table), sequence of declarations at start of sblock definition —> type identifier ':' dblock { st.put(identifier.lexeme, TYPE, dblock.type, dblock.width } dblock —> '(' { Env.push(st); st = new Env(); Stack.push(offset); offset = 0; } declaration-list ')' { dblock.type=record(st); dblock.width=offset; st=Env.pop(); offset=Stack.pop(); } declaration-list —> declaration ';' declaration-list declaration-list —> declaration declaration —> identifier ':' { id-list.type = identifier; } <— however you store types identifier-list (maybe pointer into st?) identifier-list —> identifier ( sBinOp constant ) ',' { st.put(identifier.lexeme, VAR, identifier-list.type, offset); Just Just offset = offset + identifier-list.type.width; } suggestions, suggestions, identifier-list not to be taken not to be taken identifier-list —> identifier ( sBinOp constant ) literally literally { st.put(identifier.lexeme, VAR, identifier-list.type, offset); offset = offset + identifier-list.type.width; }

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend