Interface VarHandler

All Known Subinterfaces:
SimpleVarHandler<T,JT>, SubInLongHandler<ST,SJT>, SubVarHandler<ST,SJT,WT,WJT>
All Known Implementing Classes:
AlignedMpIntHandler, DoubleVarAlloc, FloatVarAlloc, IntInIntHandler, IntInLongHandler, IntVarAlloc, LongInLongHandler, LongVarAlloc, NoHandler, ShiftedMpIntHandler

public interface VarHandler
A handler that knows how to load and store variables' values from local storage.

Some variables are hosted in a single JVM local of compatible type. Others, notably multi-precision integers, are allocated among two or more JVM local integers. Each such integer is called a "leg" of the multi-precision integer. Other literature may call these "digits" (whose value is in [0, 0xffffffff]). Depending on the operator implementation, value may need to be loaded with alternative types or in different forms. e.g., any float operator will need to convert its inputs into the appropriate float type, even if the operands were allocated as an int type. Similarly, some operators are implement their multi-precision computations by invoking static methods whose parameters are int[], and so they will load and store the array forms instead of accessing the legs' locals. This interface provides generators for the various circumstances. Each subclass provides the implementations for various allocations.

  • Method Details

    • nameVn

      static String nameVn(Varnode vn)
      Generate a name for the variable representing the given varnode

      These are for debugging purposes. When dumping generating bytecode, the declared local variables and their scopes are often also dumped. This provides a human with the local variable index for various varnodes.

      Parameters:
      vn - the varnode
      Returns:
      the name
    • vn

      Varnode vn()
      Get the complete varnode accessible to this handler
      Returns:
      the varnode
    • name

      default String name()
      Get the name for this handler's local variable, named after the varnode is represents.
      Returns:
      the name of the local variable
    • type

      JitType type()
      Get the p-code type of the local variable this handler uses.
      Returns:
      the type
    • genLoadToStack

      <TT extends Types.BPrim<?>, TJT extends JitType.SimpleJitType<TT, TJT>, N extends Emitter.Next> Emitter<Emitter.Ent<N,TT>> genLoadToStack(Emitter<N> em, JitCodeGenerator<?> gen, TJT type, Opnd.Ext ext)
      Emit bytecode to load the varnode's value onto the JVM stack.
      Type Parameters:
      TT - the JVM type of the value to load onto the stack
      TJT - the p-code type of the value to load onto the stack
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the value expected on the JVM stack by the proceeding bytecode
      ext - the kind of extension to apply when adjusting from JVM size to varnode size
      Returns:
      the emitter typed with the resulting stack
    • genLoadToOpnd

      <N extends Emitter.Next> Opnd.OpndEm<JitType.MpIntJitType,N> genLoadToOpnd(Emitter<N> em, JitCodeGenerator<?> gen, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope)
      Emit bytecode to load the varnode's value into several locals.
      Type Parameters:
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the value expected on the JVM stack by the proceeding bytecode
      ext - the kind of extension to apply
      scope - a scope for generating temporary local storage
      Returns:
      the operand containing the locals, and the emitter typed with the incoming stack
    • genLoadLegToStack

      <N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TInt>> genLoadLegToStack(Emitter<N> em, JitCodeGenerator<?> gen, JitType.MpIntJitType type, int leg, Opnd.Ext ext)
      Emit bytecode to load one leg of a multi-precision value from the varnode onto the JVM stack.
      Type Parameters:
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the complete multi-precision value
      leg - the index of the leg to load, 0 being least significant
      ext - the kind of extension to apply
      Returns:
      the emitter typed with the resulting stack, i.e., having the int leg pushed onto it
    • genLoadToArray

      <N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TRef<int[]>>> genLoadToArray(Emitter<N> em, JitCodeGenerator<?> gen, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope, int slack)
      Emit bytecode to load the varnode's value into an integer array in little-endian order, pushing its ref onto the JVM stack.
      Type Parameters:
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the complete multi-precision value
      ext - the kind of extension to apply
      scope - a scope for generating temporary local storage
      slack - the number of additional, more significant, elements to allocate in the array
      Returns:
      the emitter typed with the resulting stack, i.e., having the ref pushed onto it
    • genLoadToBool

      <N extends Emitter.Next> Emitter<Emitter.Ent<N,Types.TInt>> genLoadToBool(Emitter<N> em, JitCodeGenerator<?> gen)
      Emit bytecode to load the varnode's value, interpreted as a boolean, as an integer onto the JVM stack.
      Type Parameters:
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      Returns:
      the emitter typed with the resulting stack, i.e., having the int boolean pushed onto it
    • genStoreFromStack

      <FT extends Types.BPrim<?>, FJT extends JitType.SimpleJitType<FT, FJT>, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, FT>> Emitter<N1> genStoreFromStack(Emitter<N0> em, JitCodeGenerator<?> gen, FJT type, Opnd.Ext ext, Scope scope)
      Emit bytecode to store a value into a variable from the JVM stack.
      Type Parameters:
      FT - the JVM type of the value on the stack
      FJT - the p-code type of the value on the stack
      N1 - the tail of the incoming stack
      N0 - the incoming stack having the value to store on top
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the value on the stack
      ext - the kind of extension to apply
      scope - a scope for generating temporary local storage
      Returns:
      the emitter typed with the resulting stack, i.e., having popped the value
    • genStoreFromOpnd

      <N extends Emitter.Next> Emitter<N> genStoreFromOpnd(Emitter<N> em, JitCodeGenerator<?> gen, Opnd<JitType.MpIntJitType> opnd, Opnd.Ext ext, Scope scope)
      Emit bytecode to store a varnode's value from several locals.
      Type Parameters:
      N - the incoming stack
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      opnd - the operand whose locals contain the value to be stored
      ext - the kind of extension to apply
      scope - a scope for generating temporary local storage
      Returns:
      the emitter typed with the incoming stack
    • genStoreFromArray

      <N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, Types.TRef<int[]>>> Emitter<N1> genStoreFromArray(Emitter<N0> em, JitCodeGenerator<?> gen, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope)
      Emit bytecode to store a varnode's value from an array of integer legs, in little endian order
      Type Parameters:
      N1 - the tail of the incoming stack
      N0 - the incoming stack having the array ref on top
      Parameters:
      em - the emitter typed with the incoming stack
      gen - the code generator
      type - the p-code type of the value on the stack
      ext - the kind of extension to apply
      scope - a scope for generating temporary local storage
      Returns:
      the emitter typed with the resulting stack, i.e., having popped the array
    • subpiece

      VarHandler subpiece(Endian endian, int byteOffset, int maxByteSize)
      Create a handler for a PcodeOp.SUBPIECE of a value.

      To implement subpiece, we could load the entire varnode and then extract the designated portion. Or, we could load only the designated portion, averting any code and execution cost of loading the un-designated portions. We accomplish this by re-writing the subpiece op and a load of the sub-varnode.

      Parameters:
      endian - the endianness of the emulation target
      byteOffset - the number of least-significant bytes to remove
      maxByteSize - the maximum size of the resulting variable. In general, a subpiece should never exceed the size of the parent varnode, but if it does, this will truncate that excess.
      Returns:
      the resulting subpiece handler