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:
LocalVarGen<V>
,MemoryVarGen<V>
- All Known Implementing Classes:
DirectMemoryVarGen
,InputVarGen
,LocalOutVarGen
,MemoryOutVarGen
,MissingVarGen
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:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
A means to emit bytecode on transitions betweenblocks
-
Method Summary
Modifier and TypeMethodDescriptionstatic VarGen.BlockTransition
computeBlockTransition
(JitCodeGenerator gen, JitControlFlowModel.JitBlock from, JitControlFlowModel.JitBlock to) Compute the retired and birthed varnodes for a transition between the given blocks.static void
generateBirthCode
(JitCodeGenerator gen, Set<Varnode> toBirth, org.objectweb.asm.MethodVisitor rv) For block transitions: emit bytecode that births (loads) variables from thestate
into their allocated JVM locals.static void
generateRetireCode
(JitCodeGenerator gen, Set<Varnode> toRetire, org.objectweb.asm.MethodVisitor rv) For block transitions: emit bytecode the retires (writes) variables into thestate
from their allocated JVM locals.static void
generateValInitCode
(JitCodeGenerator gen, Varnode vn) Emit bytecode necessary to support access to the given varnodestatic void
generateValReadCodeDirect
(JitCodeGenerator gen, JitType type, Varnode vn, org.objectweb.asm.MethodVisitor rv) Emit bytecode that loads the given varnode with the given p-code type from thestate
onto the JVM stack.static JitType
generateValReadCodeDirect
(JitCodeGenerator gen, JitVarnodeVar v, JitTypeBehavior typeReq, org.objectweb.asm.MethodVisitor rv) Emit bytecode that loads the given use-def variable from thestate
onto the JVM stack.static void
generateValWriteCodeDirect
(JitCodeGenerator gen, JitType type, Varnode vn, org.objectweb.asm.MethodVisitor rv) Emit bytecode that writes the given varnode with the given p-code type in thestate
from the JVM stack.static void
generateValWriteCodeDirect
(JitCodeGenerator gen, JitVarnodeVar v, JitType type, org.objectweb.asm.MethodVisitor rv) Emit bytecode that writes the given use-def variable in thestate
from the JVM stack.void
generateVarWriteCode
(JitCodeGenerator gen, V v, JitType type, org.objectweb.asm.MethodVisitor rv) Write a value from the stack into the given variablelookup
(V v) Lookup the generator for a given p-code variable use-def nodeMethods inherited from interface ghidra.pcode.emu.jit.gen.var.ValGen
generateValInitCode, generateValReadCode
-
Method Details
-
lookup
Lookup the generator for a given p-code variable use-def node- Type Parameters:
V
- the class of the variable- Parameters:
v
- theJitVar
whose generator to look up- Returns:
- the generator
-
generateValInitCode
Emit bytecode necessary to support access to the given varnodeThis applies to all varnode types:
memory
,unique
, andregister
, but notconst
. 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 attransitions
. Technically, the methods for generating the read and write code will already callJitCodeGenerator.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.- Parameters:
gen
- the code generatorvn
- the varnode
-
generateValReadCodeDirect
static void generateValReadCodeDirect(JitCodeGenerator gen, JitType type, Varnode vn, org.objectweb.asm.MethodVisitor rv) Emit bytecode that loads the given varnode with the given p-code type from thestate
onto the JVM stack.This is used for direct memory accesses and for register/unique scope transitions. The JVM type of the stack variable is determined by the
type
argument.- Parameters:
gen
- the code generatortype
- the p-code type of the variablevn
- the varnode to read from the staterv
- the visitor for therun
method
-
generateValReadCodeDirect
static JitType generateValReadCodeDirect(JitCodeGenerator gen, JitVarnodeVar v, JitTypeBehavior typeReq, org.objectweb.asm.MethodVisitor rv) Emit bytecode that loads the given use-def variable from thestate
onto the JVM stack.The actual type is determined by resolving the
typeReq
argument against the given variable. Since the variable is being loaded directly from the state, which is just raw bytes/bits, we ignore the "assigned" type and convert directly the type required by the operand.- Parameters:
gen
- the code generatorv
- the use-def variable nodetypeReq
- the type (behavior) required by the operand.rv
- the visitor for therun
method- Returns:
- the resulting p-code type (which also describes the JVM type) of the value on the JVM stack
-
generateValWriteCodeDirect
static void generateValWriteCodeDirect(JitCodeGenerator gen, JitType type, Varnode vn, org.objectweb.asm.MethodVisitor rv) Emit bytecode that writes the given varnode with the given p-code type in thestate
from the JVM stack.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.- Parameters:
gen
- the code generatortype
- the p-code type of the variablevn
- the varnode to write in the staterv
- the visitor for therun
method
-
generateValWriteCodeDirect
static void generateValWriteCodeDirect(JitCodeGenerator gen, JitVarnodeVar v, JitType type, org.objectweb.asm.MethodVisitor rv) Emit bytecode that writes the given use-def variable in thestate
from the JVM stack.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.- Parameters:
gen
- the code generatorv
- the use-def variable nodetype
- the p-code type of the value on the stack, as required by the operandrv
- the visitor for therun
method
-
generateBirthCode
static void generateBirthCode(JitCodeGenerator gen, Set<Varnode> toBirth, org.objectweb.asm.MethodVisitor rv) For block transitions: emit bytecode that births (loads) variables from thestate
into their allocated JVM locals.- Parameters:
gen
- the code generatortoBirth
- the set of varnodes to loadrv
- the visitor for therun
method
-
generateRetireCode
static void generateRetireCode(JitCodeGenerator gen, Set<Varnode> toRetire, org.objectweb.asm.MethodVisitor rv) For block transitions: emit bytecode the retires (writes) variables into thestate
from their allocated JVM locals.- Parameters:
gen
- the code generatortoRetire
- the set of varnodes to writerv
- the visitor for therun
method
-
computeBlockTransition
static VarGen.BlockTransition computeBlockTransition(JitCodeGenerator 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, theto
block should benull
when generating transitions around a hazard.- Parameters:
gen
- the code generatorfrom
- 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
-
generateVarWriteCode
void generateVarWriteCode(JitCodeGenerator gen, V v, JitType type, org.objectweb.asm.MethodVisitor rv) Write a value from the stack into the given variable- Parameters:
gen
- the code generatorv
- the variable to writetype
- the p-code type (which also determines the expected JVM type) of the value on the stackrv
- the visitor for therun
method
-