コード例 #1
0
  @Test
  public void singleBlock() {
    IRBody block = buildBody("y<-x+1;z<-3; 4");
    ControlFlowGraph cfg = new ControlFlowGraph(block);

    System.out.println(cfg);

    List<BasicBlock> basicBlocks = cfg.getBasicBlocks();
    assertThat(basicBlocks.size(), equalTo(3)); // entry + 1 + exit = 3
    assertThat(basicBlocks.get(1).getStatements().size(), equalTo(block.getStatements().size()));
  }
コード例 #2
0
  /**
   * @param closure the closure to inline
   * @param arguments the names of the formals that will be supplied to this inline call
   */
  public InlinedFunction(RuntimeState parentState, Closure closure, Set<Symbol> arguments) {

    runtimeState = new RuntimeState(parentState, closure.getEnclosingEnvironment());

    IRBodyBuilder builder = new IRBodyBuilder(runtimeState);
    IRBody body = builder.buildFunctionBody(closure, arguments);

    cfg = new ControlFlowGraph(body);
    dTree = new DominanceTree(cfg);
    ssaTransformer = new SsaTransformer(cfg, dTree);
    ssaTransformer.transform();
    useDefMap = new UseDefMap(cfg);
    types = new TypeSolver(cfg, useDefMap);
    params = body.getParams();

    for (Statement statement : body.getStatements()) {
      if (statement instanceof ReturnStatement) {
        returnStatements.add((ReturnStatement) statement);
      }
    }
  }