Interface VarGen<V extends JitVar>

Type Parameters:
V - the class of p-code variable node in the use-def graph
All Superinterfaces:
ValGen<V>
All Known Subinterfaces:
DirectMemoryVarGen, InputVarGen, LocalOutVarGen, LocalVarGen<V>, MemoryOutVarGen, MemoryVarGen<V>, SubLocalVarGen<V>, SubMemoryVarGen<V>
All Known Implementing Classes:
MissingVarGen, SubDirectMemoryVarGen, SubInputVarGen, SubLocalOutVarGen, SubMemoryOutVarGen, WholeDirectMemoryVarGen, WholeInputVarGen, WholeLocalOutVarGen, WholeMemoryOutVarGen

public interface VarGen<V extends JitVar> extends ValGen<V>
The bytecode generator for a specific use-def variable (operand) access

For a table of value types, their use-def types, their generator classes, and relevant read/write opcodes, see JitVal. This interface is an extension of the JitVal interface that allows writing. The only non-JitVar JitVal is JitConstVal. As such, most of the variable-access logic is actually contained here.

See Also:
  • Method Details

    • lookup

      static <V extends JitVar> VarGen<V> lookup(V v)
      Lookup the generator for a given p-code variable use-def node
      Type Parameters:
      V - the class of the variable
      Parameters:
      v - the JitVar whose generator to look up
      Returns:
      the generator
    • genVarnodeInit

      static <N extends Emitter.Next> Emitter<N> genVarnodeInit(Emitter<N> em, JitCodeGenerator<?> gen, Varnode vn)
      Emit bytecode necessary to support access to the given varnode

      This applies to all varnode types: memory, unique, and register, but not const. For memory varnodes, we need to pre-fetch the byte arrays backing their pages, so we can access them at the translation site. For unique and register varnodes, we also need to pre-fetch the byte arrays backing their pages, so we can birth and retire them at transitions. Technically, the methods for generating the read and write code will already call JitCodeGenerator.requestFieldForArrDirect(Address); however, we'd like to ensure the fields appear in the classfile in a comprehensible order, so we have the generator iterate the variables in address order and invoke this method, where we make the request first.

      Type Parameters:
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      gen - the code generator
      vn - the varnode
      Returns:
      the emitter with ...
    • genReadValDirectToStack

      static <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N extends Emitter.Next> Emitter<Emitter.Ent<N,T>> genReadValDirectToStack(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JT type, Varnode vn)
      Emit bytecode that loads the given varnode with the given p-code type from the state onto the stack.

      This is used for direct memory accesses and for register/unique scope transitions. The JVM type of the operand is determined by the type argument.

      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      type - the p-code type of the variable
      vn - the varnode to read from the state
      Returns:
      the emitter with ..., result
    • genWriteValDirectFromStack

      static <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, T>> Emitter<N1> genWriteValDirectFromStack(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JT type, Varnode vn)
      Emit bytecode that writes the given varnode with the given p-code type in the state from a stack operand.

      This is used for direct memory accesses and for register/unique scope transitions. The expected JVM type of the stack variable is described by the type argument.

      Type Parameters:
      THIS - the type of the generated class
      N1 - the tail of the stack (...)
      N0 - ..., value
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      type - the type of the operand on the stack
      vn - the varnode to write in the state
      Returns:
      the emitter with ...
    • genWriteValDirectFromStack

      static <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, T>> Emitter<N1> genWriteValDirectFromStack(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JT type, JitVarnodeVar v)
      Emit bytecode that writes the given use-def variable in the state from a stack operand.

      The expected type is given by the type argument. Since the variable is being written directly into the state, which is just raw bytes/bits, we ignore the "assigned" type and convert using the given type instead.

      Type Parameters:
      THIS - the type of the generated class
      N1 - the tail of the stack (...)
      N0 - ..., value
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      type - the type of the operand on the stack
      v - the use-def variable node
      Returns:
      the emitter with ...
    • genBirth

      static <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<N> genBirth(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, Set<Varnode> toBirth)
      For block transitions: emit bytecode that births (loads) variables from the state into their allocated JVM locals.
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      toBirth - the set of varnodes to load
      Returns:
      the emitter with ...
    • genRetire

      static <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<N> genRetire(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, Set<Varnode> toRetire)
      For block transitions: emit bytecode the retires (writes) variables into the state from their allocated JVM locals.
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      toRetire - the set of varnodes to write
      Returns:
      the emitter with ...
    • computeBlockTransition

      static <THIS extends JitCompiledPassage> VarGen.BlockTransition<THIS> computeBlockTransition(Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, JitControlFlowModel.JitBlock from, JitControlFlowModel.JitBlock to)
      Compute the retired and birthed varnodes for a transition between the given blocks.

      Either block may be null to indicate entering or leaving the passage. Additionally, the to block should be null when generating transitions around a hazard.

      Type Parameters:
      THIS - the type of the generated class
      Parameters:
      localThis - a handle to this
      gen - the code generator
      from - the block control flow is leaving (whether by branch or fall through)
      to - the block control flow is entering
      Returns:
      the means of generating bytecode at the transition
    • genWriteFromStack

      <THIS extends JitCompiledPassage, T extends Types.BPrim<?>, JT extends JitType.SimpleJitType<T, JT>, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, T>> Emitter<N1> genWriteFromStack(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, V v, JT type, Opnd.Ext ext, Scope scope)
      Write a value from a stack operand into the given variable
      Type Parameters:
      THIS - the type of the generated class
      T - the JVM type of the stack operand
      JT - the p-code type of the stack operand
      N1 - the tail of the stack (...)
      N0 - ..., value
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      type - the p-code type of the stack operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...
    • genWriteFromOpnd

      <THIS extends JitCompiledPassage, N extends Emitter.Next> Emitter<N> genWriteFromOpnd(Emitter<N> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, V v, Opnd<JitType.MpIntJitType> opnd, Opnd.Ext ext, Scope scope)
      Write a value from a local operand into the given variable
      Type Parameters:
      THIS - the type of the generated class
      N - the tail of the stack (...)
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      opnd - the source operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...
    • genWriteFromArray

      <THIS extends JitCompiledPassage, N1 extends Emitter.Next, N0 extends Emitter.Ent<N1, Types.TRef<int[]>>> Emitter<N1> genWriteFromArray(Emitter<N0> em, Local<Types.TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, V v, JitType.MpIntJitType type, Opnd.Ext ext, Scope scope)
      Write a value from an array operand into the given variable
      Type Parameters:
      THIS - the type of the generated class
      N1 - the tail of the stack (...)
      N0 - ..., arrayref
      Parameters:
      em - the emitter
      localThis - a handle to this
      gen - the code generator
      v - the variable to write
      type - the p-code type of the array operand
      ext - the kind of extension to apply when adjusting from varnode size to JVM size
      scope - a scope for temporaries
      Returns:
      the emitter with ...