opcodes.scala
来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 646 行 · 第 1/2 页
SCALA
646 行
} override def consumedTypes = { val args = method.tpe.paramTypes map toTypeKind style match { case Dynamic | Static(true) => AnyRefReference :: args case _ => args } } override def produced = if(toTypeKind(method.tpe.resultType) == UNIT) 0 else if(method.isConstructor) 0 else 1 /** object idenity is equality for CALL_METHODs. Needed for * being able to store such instructions into maps, when more * than one CALL_METHOD to the same method might exist. */ override def equals(other: Any) = other match { case o: AnyRef => this eq o case _ => false } } case class BOX(boxType: TypeKind) extends Instruction { override def toString(): String = "BOX " + boxType override def consumed = 1 override def consumedTypes = boxType :: Nil override def produced = 1 } case class UNBOX(boxType: TypeKind) extends Instruction { override def toString(): String = "UNBOX " + boxType override def consumed = 1 override def consumedTypes = AnyRefReference :: Nil override def produced = 1 } /** Create a new instance of a class through the specified constructor * Stack: ...:arg1:arg2:...:argn * ->: ...:ref */ case class NEW(kind: REFERENCE) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String = "NEW "+ kind; override def consumed = 0; override def produced = 1; /** The corresponding constructor call. */ var init: CALL_METHOD = _ } /** This class represents a CREATE_ARRAY instruction * Stack: ...:size_1:size_2:..:size_n * ->: ...:arrayref */ case class CREATE_ARRAY(elem: TypeKind, dims: Int) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="CREATE_ARRAY "+elem.toString() + " x " + dims; override def consumed = dims; override def consumedTypes = List.make(dims, INT) override def produced = 1; } /** This class represents a IS_INSTANCE instruction * Stack: ...:ref * ->: ...:result(boolean) */ case class IS_INSTANCE(typ: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="IS_INSTANCE "+typ.toString() override def consumed = 1 override def consumedTypes = AnyRefReference :: Nil override def produced = 1 } /** This class represents a CHECK_CAST instruction * Stack: ...:ref(oldtype) * ->: ...:ref(typ <=: oldtype) */ case class CHECK_CAST(typ: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="CHECK_CAST "+typ.toString() override def consumed = 1 override def produced = 1 override val consumedTypes = List(AnyRefReference) override def producedTypes = List(typ) } /** This class represents a SWITCH instruction * Stack: ...:index(int) * ->: ...: * * The tags array contains one entry per label, each entry consisting of * an array of ints, any of which will trigger the jump to the corresponding label. * labels should contain an extra label, which is the 'default' jump. */ case class SWITCH(tags: List[List[Int]], labels: List[BasicBlock]) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="SWITCH ..." override def consumed = 1 override def produced = 0 } /** This class represents a JUMP instruction * Stack: ... * ->: ... */ case class JUMP(whereto: BasicBlock) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="JUMP "+whereto.label override def consumed = 0 override def produced = 0 } /** This class represents a CJUMP instruction * It compares the two values on the stack with the 'cond' test operator * Stack: ...:value1:value2 * ->: ... */ case class CJUMP(successBlock: BasicBlock, failureBlock: BasicBlock, cond: TestOp, kind: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String = ( "CJUMP (" + kind + ")" + cond.toString()+" ? "+successBlock.label+" : "+failureBlock.label ); override def consumed = 2 override def produced = 0 } /** This class represents a CZJUMP instruction * It compares the one value on the stack and zero with the 'cond' test operator * Stack: ...:value: * ->: ... */ case class CZJUMP(successBlock: BasicBlock, failureBlock: BasicBlock, cond: TestOp, kind: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String = ( "CZJUMP (" + kind + ")" + cond.toString()+" ? "+successBlock.label+" : "+failureBlock.label ); override def consumed = 1 override def produced = 0 } /** This class represents a RETURN instruction * Stack: ... * ->: ... */ case class RETURN(kind: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="RETURN (" + kind + ")" override def consumed = if (kind == UNIT) 0 else 1 override def produced = 0 } /** This class represents a THROW instruction * Stack: ...:Throwable(Ref) * ->: ...: */ case class THROW() extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="THROW" override def consumed = 1 override def produced = 0 } /** This class represents a DROP instruction * Stack: ...:something * ->: ... */ case class DROP (typ: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="DROP "+typ.toString() override def consumed = 1 override def produced = 0 } /** This class represents a DUP instruction * Stack: ...:something * ->: ...:something:something */ case class DUP (typ: TypeKind) extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="DUP" override def consumed = 1 override def produced = 2 } /** This class represents a MONITOR_ENTER instruction * Stack: ...:object(ref) * ->: ...: */ case class MONITOR_ENTER() extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="MONITOR_ENTER" override def consumed = 1 override def produced = 0 } /** This class represents a MONITOR_EXIT instruction * Stack: ...:object(ref) * ->: ...: */ case class MONITOR_EXIT() extends Instruction { /** Returns a string representation of this instruction */ override def toString(): String ="MONITOR_EXIT"; override def consumed = 1; override def produced = 0; } /** A local variable becomes visible at this point in code. * Used only for generating precise local variable tables as * debugging information. */ case class SCOPE_ENTER(lv: Local) extends Instruction { override def toString(): String = "SCOPE_ENTER " + lv override def consumed = 0 override def produced = 0 } /** A local variable leaves its scope at this point in code. * Used only for generating precise local variable tables as * debugging information. */ case class SCOPE_EXIT(lv: Local) extends Instruction { override def toString(): String = "SCOPE_EXIT " + lv override def consumed = 0 override def produced = 0 } /** Fake instruction. It designates the VM who pushes an exception * on top of the /empty/ stack at the beginning of each exception handler. * Note: Unlike other instructions, it consumes all elements on the stack! * then pushes one exception instance. */ case class LOAD_EXCEPTION() extends Instruction { override def toString(): String = "LOAD_EXCEPTION" override def consumed = error("LOAD_EXCEPTION does clean the whole stack, no idea how many things it consumes!") override def produced = 1 override def producedTypes = AnyRefReference :: Nil } /** This class represents a method invocation style. */ sealed abstract class InvokeStyle { /** Is this a dynamic method call? */ def isDynamic: Boolean = this match { case Dynamic => true case _ => false } /** Is this a static method call? */ def isStatic: Boolean = this match { case Static(_) => true case _ => false } def isSuper: Boolean = this match { case SuperCall(_) => true case _ => false } /** Is this an instance method call? */ def hasInstance: Boolean = this match { case Dynamic => true case Static(onInstance) => onInstance case SuperCall(_) => true case _ => false } /** Returns a string representation of this style. */ override def toString(): String = this match { case Dynamic => "dynamic" case Static(false) => "static-class" case Static(true) => "static-instance" case SuperCall(mix) => "super(" + mix + ")" } } case object Dynamic extends InvokeStyle /** * Special invoke. Static(true) is used for calls to private * members. */ case class Static(onInstance: Boolean) extends InvokeStyle /** Call through super[mix]. */ case class SuperCall(mix: Name) extends InvokeStyle }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?