Package ghidra.pcode.emu.jit.gen.var

# Enum Class MissingVarGen

java.lang.Object
java.lang.Enum<MissingVarGen>
ghidra.pcode.emu.jit.gen.var.MissingVarGen

All Implemented Interfaces:
  `ValGen<JitMissingVar>`, `VarGen<JitMissingVar>`, `Serializable`, `Comparable<MissingVarGen>`, `Constable`

public enum MissingVarGen extends Enum<MissingVarGen> implements VarGen<JitMissingVar>
The generator for a missing (local) variable.

In principle, a `JitMissingVar` should never show up in the use-def graph, since they should all be replaced by `phi` outputs. We can be certain these should never show up as an output, so we prohibit any attempt to generate code that writes to a missing variable. However, we wait until run time to make that assertion about reads. In theory, it's possible the generator will generate unreachable code that reads from a variable; however, that code is unreachable. First how does this happen? Second, what if it does?

To answer the first question, we note that the passage decoder should never decode any statically unreachable instructions. However, the p-code emitted by those instructions may technically contain unreachable ops.

To answer the second, we note that the ASM library has a built-in control-flow analyzer, and it ought to detect the unreachable code. In my observation, it replaces that code with `nop` and/or `athrow`. Still, in case it doesn't, or in case something changes in a later version (or if/when we port this to the JDK's upcoming classfile API), we emit our own bytecode to throw an `AssertionError`.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class java.lang.Enum

  `Enum.EnumDesc<E extends Enum<E>>`

  ## Nested classes/interfaces inherited from interface ghidra.pcode.emu.jit.gen.var.VarGen

  `VarGen.BlockTransition`

- ## Enum Constant Summary

  Enum Constants
  Enum Constant
  Description
  `GEN`
  Singleton

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `generateValInitCode(JitCodeGenerator gen, JitMissingVar v, org.objectweb.asm.MethodVisitor iv)`
  Prepare any class-level items required to use this variable
  `JitType`
  `generateValReadCode(JitCodeGenerator gen, JitMissingVar v, JitTypeBehavior typeReq, TypeConversions.Ext ext, org.objectweb.asm.MethodVisitor rv)`
  Read the value onto the stack
  `void`
  `generateVarWriteCode(JitCodeGenerator gen, JitMissingVar v, JitType type, TypeConversions.Ext ext, org.objectweb.asm.MethodVisitor rv)`
  Write a value from the stack into the given variable
  `static MissingVarGen`
  `valueOf(String name)`
  Returns the enum constant of this class with the specified name.
  `static MissingVarGen[]`
  `values()`
  Returns an array containing the constants of this enum class, in the order they are declared.

  ### Methods inherited from class java.lang.Enum

  `clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf`

  ### Methods inherited from class java.lang.Object

  `getClass, notify, notifyAll, wait, wait, wait`

- ## Enum Constant Details

  - ### GEN

    public static final MissingVarGen GEN
    Singleton

- ## Method Details

  - ### values

    public static MissingVarGen[] values()
    Returns an array containing the constants of this enum class, in the order they are declared.
    Returns:
      an array containing the constants of this enum class, in the order they are declared

  - ### valueOf

    public static MissingVarGen valueOf(String name)
    Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
    Parameters:
      `name` - the name of the enum constant to be returned.
    Returns:
      the enum constant with the specified name
    Throws:
      `IllegalArgumentException` - if this enum class has no constant with the specified name
      `NullPointerException` - if the argument is null

  - ### generateValInitCode

    public void generateValInitCode(JitCodeGenerator gen, JitMissingVar v, org.objectweb.asm.MethodVisitor iv)
    Description copied from interface: `ValGen`
    Prepare any class-level items required to use this variable

    For example, if this represents a direct memory variable, then this can prepare a reference to the portion of the state involved, allowing it to access it readily.

    Specified by:
      `generateValInitCode` in interface `ValGen<JitMissingVar>`
    Parameters:
      `gen` - the code generator
      `v` - the value
      `iv` - the constructor visitor

  - ### generateValReadCode

    public JitType generateValReadCode(JitCodeGenerator gen, JitMissingVar v, JitTypeBehavior typeReq, TypeConversions.Ext ext, org.objectweb.asm.MethodVisitor rv)
    Description copied from interface: `ValGen`
    Read the value onto the stack
    Specified by:
      `generateValReadCode` in interface `ValGen<JitMissingVar>`
    Parameters:
      `gen` - the code generator
      `v` - the value to read
      `typeReq` - the required type of the value
      `ext` - the kind of extension to apply when adjusting from JVM size to varnode size
      `rv` - the visitor for the `run` method
    Returns:
      the actual p-code type (which determines the JVM type) of the value on the stack

  - ### generateVarWriteCode

    public void generateVarWriteCode(JitCodeGenerator gen, JitMissingVar v, JitType type, TypeConversions.Ext ext, org.objectweb.asm.MethodVisitor rv)
    Description copied from interface: `VarGen`
    Write a value from the stack into the given variable
    Specified by:
      `generateVarWriteCode` in interface `VarGen<JitMissingVar>`
    Parameters:
      `gen` - the code generator
      `v` - the variable to write
      `type` - the p-code type (which also determines the expected JVM type) of the value on the stack
      `ext` - the kind of extension to apply when adjusting from varnode size to JVM size
      `rv` - the visitor for the `run` method