c10 - CS421 COMPILERS AND INTERPRETERS CS421 Back-End Code...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Copyright 1994 - 2010 Zhong Shao, Yale University Machine Code Generation: Page 1 of 18 Back-End Code Generation • Given a list of itree fragments , how to generate the corresponding assembly code ? datatype frag = PROC of { name : Tree.label, function name body : Tree.stm , function body itree frame : Frame.frame} static frame layout | DATA of string Main challenges : certain aspects of itree statements and expressions do not correspond exactly with machine languages: # of temp. registers on real machines are limited real machine’s conditional-JUMP statement takes only one label high-level constructs ESEQ and CALL ---- side-effects CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Machine Code Generation: Page 2 of 18 Itree Stmts and Exprs • itree statements stm and itree expressions exp datatype stm = SEQ of stm * stm | LABEL of label | JUMP of exp | CJUMP of test * label * label | MOVE of exp * exp | EXP of exp and exp = BINOP of binop * exp * exp | CVTOP of cvtop * exp * size * size | MEM of exp * size | TEMP of temp | NAME of label | CONST of int | CONSTF of real | ESEQ of stm * exp | CALL of exp * exp list CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Machine Code Generation: Page 3 of 18 Side-Effects Side-effects means updating the contents of a memory cell or a temporary register. What are itree expressions that might cause side effects ? ESEQ and CALL nodes ESEQ(s,e) where s is a list of statements that may contain MOVE statement The natural way to generate assembly code for BINOP ( op ,t 1 ,t 2 ) instructions to compute t 1 into r i ; instructions to compute t 2 into r j ; r k <- r i op r j But it won’t work for this: BINOP (PLUS,TEMP a, ESEQ ( MOVE (TEMP a,u),v)) CALL(e,el) by default puts the result in the return-result register . BINOP (PLUS, CALL (...), CALL (...)) CS421 COMPILERS AND INTERPRETERS Copyright 1994 - 2010 Zhong Shao, Yale University Machine Code Generation: Page 4 of 18 Summary: IR -> Machine Code Step #1 : Transform the itree code into a list of canonical trees a. eliminate SEQ and ESEQ nodes b. the arguments of a CALL node should never be other CALL nodes ---- the parent of each CALL node should either be EXP(. ..) or MOVE(TEMP t, . ..) Step #2 : Perform various code optimizations on canonical trees Step #3 : Rearrange the canonical trees (into traces ) so that every CJUMP( cond , l t , l f ) is immediately followed by LABEL( l f ). Step #4 : Instruction Selection ---- generate the pseudo-assembly code from the canonical trees in the step #3. Step #5
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

c10 - CS421 COMPILERS AND INTERPRETERS CS421 Back-End Code...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online