1 // Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file 2 // for details. All rights reserved. Use of this source code is governed by a 3 // BSD-style license that can be found in the LICENSE file. 4 5 package com.android.tools.r8.ir.conversion; 6 7 import com.android.tools.r8.graph.DebugLocalInfo; 8 import com.android.tools.r8.ir.code.CatchHandlers; 9 10 /** 11 * Abstraction of the input/source code for the IRBuilder. 12 * 13 * Implementations of the abstraction need to compute/provide the block-structure of the source and 14 * delegate building of the actual instruction stream. 15 */ 16 public interface SourceCode { 17 18 // Accessors. instructionCount()19 int instructionCount(); instructionIndex(int instructionOffset)20 int instructionIndex(int instructionOffset); instructionOffset(int instructionIndex)21 int instructionOffset(int instructionIndex); 22 23 // True if the method needs a special entry block (prelude) that is not a targetable block. 24 // This is the case for methods with arguments or that need additional synchronization support. needsPrelude()25 boolean needsPrelude(); 26 getCurrentLocal(int register)27 DebugLocalInfo getCurrentLocal(int register); 28 29 /** 30 * Trace block structure of the source-program. 31 * 32 * <p>The instruction at {@code index} is traced and its target blocks are marked by using 33 * {@code IRBuilder.ensureSuccessorBlock} (and {@code ensureBlockWithoutEnqueuing}). 34 * 35 * @return If the instruction closes the block, the last index of the block, 36 * otherwise -1. 37 */ traceInstruction(int instructionIndex, IRBuilder builder)38 int traceInstruction(int instructionIndex, IRBuilder builder); 39 closedCurrentBlockWithFallthrough(int fallthroughInstructionIndex)40 void closedCurrentBlockWithFallthrough(int fallthroughInstructionIndex); closedCurrentBlock()41 void closedCurrentBlock(); 42 43 // Setup and release resources used temporarily during trace/build. setUp()44 void setUp(); clear()45 void clear(); 46 47 // Delegates for IR building. buildPrelude(IRBuilder builder)48 void buildPrelude(IRBuilder builder); buildInstruction(IRBuilder builder, int instructionIndex)49 void buildInstruction(IRBuilder builder, int instructionIndex); buildPostlude(IRBuilder builder)50 void buildPostlude(IRBuilder builder); 51 52 // Helper to resolve switch payloads and build switch instructions (dex code only). resolveAndBuildSwitch(int value, int fallthroughOffset, int payloadOffset, IRBuilder builder)53 void resolveAndBuildSwitch(int value, int fallthroughOffset, int payloadOffset, 54 IRBuilder builder); 55 56 // Helper to resolve fill-array data and build new-array instructions (dex code only). resolveAndBuildNewArrayFilledData(int arrayRef, int payloadOffset, IRBuilder builder)57 void resolveAndBuildNewArrayFilledData(int arrayRef, int payloadOffset, IRBuilder builder); 58 getCurrentCatchHandlers()59 CatchHandlers<Integer> getCurrentCatchHandlers(); 60 61 // For debugging/verification purpose. verifyRegister(int register)62 boolean verifyRegister(int register); verifyCurrentInstructionCanThrow()63 boolean verifyCurrentInstructionCanThrow(); verifyLocalInScope(DebugLocalInfo local)64 boolean verifyLocalInScope(DebugLocalInfo local); 65 } 66