1 / 16

Road Map

This guide covers Regular Expressions, Context-Free Grammars, LR Parsing Algorithm, Building LR Parse Tables, and Code Generation with Three-Address Code. Includes examples and implementation details.

hardeman
Download Presentation

Road Map

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Road Map • Regular Exprs, Context-Free Grammars • LR parsing algorithm • Building LR parse tables • Compiling Expressions • Build control flow intermediates • Generate target code • Optimize intermediate

  2. Implementation “Done” to date • Symbol Table • Generic List routines • Expressions using lex, yacc input

  3. Three-Address Codesection 6.2.1 (new), pp 467 (old) • Assembler for generic computer • Types of statements 3-address (Dragon) • Assignment statement x = y op z • Unconditional jump br label • Conditional jump if( cond ) goto label • Parameter x • Call statement call f

  4. Example “Source” a = ((c-1) * b) + (-c * b)

  5. Example 3-Address t1 = c - 1 t2 = b * t1 t3 = -c t4 = t3 * b t5 = t2 + t4 a = t5

  6. Three-Address Implementation(Quadruples, sec 6.2.2; pp 470-2)

  7. Three-Address Implementation(Triples, section 6.2.3)

  8. Three-Address Implementation • N-tuples (my choice – and yours ??) • Lhs = oper(op1, op2, …, opn) • Lhs = call(func, arg1, arg2, … argn) • If condOper(op1, op2, Label) • br Label

  9. Three-Address Code • 3-address operands • Variable • Constant • Array • Pointer

  10. Control Flow Graphsec 8.4 (new); sec 9.4 (old) • Nodes are Basic Blocks • Single entry, single exit • No branch exempt (possibly) at bottom • Edges represent one possible flow of execution between two basic blocks • Whole CFG represents a function

  11. Bubble Sort begin; int A[10]; main(){ int i,j; Do 10 i = 0, 9, 1 10 A[i] = random(); Do 20 i = 1, 9, 1 Do 20 j = 1, 9, 1 20 if( A[j] > A[j+1]) swap(j); }

  12. Bubble Sort (cont.) int swap(int i) { int temp; temp = A[i]; A[i] = A[i+1]; A[i+1] = temp; } end;

  13. Example Generate 3-addr code for BubbleSort

  14. Building CFGalg 8.5 (pp 526-7); alg 9.1(p 529) • Starting with 3-addr code • Each leader starts a basic block which ends immediately before the next leader • ID “leaders” (heads of basic blocks) • First statement is a leader • Any statement that is the target of a conditional of unconditional goto is a leader • Any statement immediately following a goto or conditional goto is a leader • Each leader starts a basic block which ends immediately before the next leader

  15. Example Build control flow graphs for BubbleSort

  16. Code Generation • Pick three registers to be used throughout • Assuming stmt of form dest = s1 op s2 • Generate code by: • Load source 1 into r5 • Load source 2 into r6 • R7 = r5 op r6 • Store r7 into destination

More Related