1 / 10

Overview of Compilation The Compiler BACK End

Overview of Compilation The Compiler BACK End. COP4620 – Programming Language Translators Dr. Manuel E. Bermudez. Analyze static semantics : V ariables declared before they are used ? Assignment compatibility? e.g ., a :=3 Operator type compatibility ? e.g., a+3

arnita
Télécharger la présentation

Overview of Compilation The Compiler BACK End

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. Overview of CompilationThe Compiler BACK End COP4620 – Programming Language Translators Dr. Manuel E. Bermudez Translators

  2. Analyze static semantics: Variables declared before they are used ? Assignment compatibility? e.g., a:=3 Operator type compatibility ? e.g., a+3 Do actual and formal parameter types match? e.g. intf(int n, char c) {…} ... f('x', 3); Enforcement of scope rules. PHASE 3: Contextual Constraint Analysis Translators

  3. Traverse the tree recursively Deduce type information at the bottom, Pass type information up the tree. Each node verifies the types below. Make use of a DECLARATION TABLE, to keep track of names and their meaning. Contextual Constraint Analysis Translators

  4. Enter x into the DCLN table, with its type. Check type compatibility for x=5. x2 not declared! Verify type of ’>’ is boolean. Check type compatibility for ‘+’. Check type compatibility between x and int, for assignment. Contextual Constraint Analysis Translators

  5. Goal: Convert syntax tree to target code. Target code could be: Machine language. Assembly language. Quadruples for a fictional machine: Label, opcode, operands (1 or 2) PHASE 4: code generation   Translators

  6. Tradeoffs: “gcc” generates assembly code. “javac” generates bytecodes, to be interpreted by the JVM. “gcc”: slow compilation, fast running code. “javac”: fast compilation, slow running code. Speed depends on implementation strategy, not the language ! Code Generation: Traverse the tree again. Code Generation Translators

  7. Code generation (stack machine) • Text Level 1 • Text Level 2 • Text Level 3 LOAD 5 STORE X LOAD X LOAD 10 BGT COND L1 L2 L1 LOAD X LOAD 1 BADD STORE X GOTO L3 L2 ... L3 Translators

  8. Reduce the size of the target program. Decrease the running time of the target. “Optimization” a misnomer. “Code improvement” ? Two types of optimization: Peephole optimization (local). Global optimization (improve loops, etc.). Code Optimization Translators

  9. LOAD 5 STORE X LOAD X is replaced with LOAD 5 STND X STND: Store non-destructive Code Optimization LOAD 5 STORE X LOAD X LOAD 10 BGT COND L1 L2 L1 LOAD X LOAD 1 BADD STORE X GOTO L3 L2 ... L3 Translators

  10. Summary Source Scanner Tokens Screener Tokens Error Routines Table Routines Parser Tree Constrainer Tree Code Generator Code Interpreter Input Output Translators

More Related