LARA

Translating Syntax Tree to CFG

Similar to what we had so far, but

  • fresh variable names instead of stack for expressions
  • edges in CFG instead of jump instructions
  • test edges to encode conditional branches

Example of translation

Building a Translator to CFG

Simulating “next” instruction

  • the command to emit next instruction adds a successor edge in the graph
  • makes code generation similar to bytecode generation

Translating Expressions

  • emit instructions, return stored variable name - like stack
  • alternative: passing the destination of assignment

Example:

len = (a + b + c) * 2;
len = (a + len + c) * 2;

Number of introduced variables

  • we will worry about this later

Translating Control-Flow

  • what do we need to pass into translation functions?