Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6491: Replace org.ow2.asm with Java Class-File API

GhidraHamster82f572ea97cb
diff --git a/Ghidra/Extensions/BSimElasticPlugin/build.gradle b/Ghidra/Extensions/BSimElasticPlugin/build.gradle
index fdf2c379b1..f5e15b63db 100755
--- a/Ghidra/Extensions/BSimElasticPlugin/build.gradle
+++ b/Ghidra/Extensions/BSimElasticPlugin/build.gradle
@@ -93,7 +93,7 @@ task elasticPluginZip(type: Zip) {
}
// Currently targeting elasticsearch-8.19.7 which by default runs with java 25
-compileElasticPluginJava.options.release = 21
+compileElasticPluginJava.options.release = 25
compileElasticPluginJava.dependsOn copyGenericTask
compileElasticPluginJava.dependsOn copyUtilityTask
diff --git a/Ghidra/Extensions/BSimElasticPlugin/contribZipExclude/plugin-descriptor.properties b/Ghidra/Extensions/BSimElasticPlugin/contribZipExclude/plugin-descriptor.properties
index 4445fdfd65..f99c42250a 100755
--- a/Ghidra/Extensions/BSimElasticPlugin/contribZipExclude/plugin-descriptor.properties
+++ b/Ghidra/Extensions/BSimElasticPlugin/contribZipExclude/plugin-descriptor.properties
@@ -2,5 +2,5 @@ description=Feature Vector Plugin
version=1.0
name=lsh
classname=org.elasticsearch.plugin.analysis.lsh.AnalysisLSHPlugin
-java.version=1.21
+java.version=1.25
elasticsearch.version=8.19.7
diff --git a/Ghidra/Features/FileFormats/build.gradle b/Ghidra/Features/FileFormats/build.gradle
index 91c10c5c5d..3ea87870da 100644
--- a/Ghidra/Features/FileFormats/build.gradle
+++ b/Ghidra/Features/FileFormats/build.gradle
@@ -31,12 +31,18 @@ dependencies {
api project(':PDB')
// Used by "Android DEX to JAR" file system
- // dex2jar depends on asm-9.7.1, which is declared in Framework/Emulation
api 'de.femtopedia.dex2jar:dex-ir:2.4.24'
api 'de.femtopedia.dex2jar:dex-reader:2.4.24'
api 'de.femtopedia.dex2jar:dex-reader-api:2.4.24'
api 'de.femtopedia.dex2jar:dex-translator:2.4.24'
+ // Transitive dependencies of dex2jar
+ api 'org.ow2.asm:asm:9.7.1'
+ api 'org.ow2.asm:asm-analysis:9.7.1'
+ api 'org.ow2.asm:asm-commons:9.7.1'
+ api 'org.ow2.asm:asm-tree:9.7.1'
+ api 'org.ow2.asm:asm-util:9.7.1'
+
// Used by "Android DEX to SMALI" file system
api 'org.smali:baksmali:2.5.2' // requires guava-27.1-android or later
api 'org.smali:dexlib2:2.5.2' // requires guava-27.1-android or later
diff --git a/Ghidra/Framework/Emulation/build.gradle b/Ghidra/Framework/Emulation/build.gradle
index e023ffa8e1..7048564170 100644
--- a/Ghidra/Framework/Emulation/build.gradle
+++ b/Ghidra/Framework/Emulation/build.gradle
@@ -26,10 +26,4 @@ dependencies {
api project(':SoftwareModeling')
api project(':Generic')
api project(':Utility')
-
- api 'org.ow2.asm:asm:9.7.1'
- api 'org.ow2.asm:asm-analysis:9.7.1'
- api 'org.ow2.asm:asm-commons:9.7.1'
- api 'org.ow2.asm:asm-tree:9.7.1'
- api 'org.ow2.asm:asm-util:9.7.1'
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitCompiler.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitCompiler.java
index cf7f19010a..eb47fcf290 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitCompiler.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitCompiler.java
@@ -19,8 +19,6 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.util.EnumSet;
-import org.objectweb.asm.ClassWriter;
-
import ghidra.pcode.emu.jit.analysis.*;
import ghidra.pcode.emu.jit.decode.JitPassageDecoder;
import ghidra.pcode.emu.jit.folding.FoldRevalidator;
@@ -195,7 +193,7 @@ public class JitCompiler {
PRINT_SYNTH,
/** Print each eliminated op */
PRINT_OUM,
- /** Enable ASM's trace for each generated classfile */
+ /** Disassemble (via javap) each generated classfile to stderr */
TRACE_CLASS,
/** Enable per-op outline of bytecode generation */
DEEP_TRACE,
@@ -214,25 +212,18 @@ public class JitCompiler {
//EnumSet.of(Diag.PRINT_PASSAGE, Diag.DEEP_TRACE);
/**
- * Exclude a given address offset from ASM's {@link ClassWriter#COMPUTE_MAXS} and
- * {@link ClassWriter#COMPUTE_FRAMES}.
+ * Exclude a given address offset from automatic stack map computation.
* <p>
- * Unfortunately, when automatic computation of frames and maxes fails, the ASM library offers
- * little in terms of diagnostics. It usually crashes with an NPE or an AIOOBE. Worse, when this
- * happens, it fails to output any of the classfile trace. To help with this, a developer may
- * identify the address of the passage seed that causes such a failure and set this variable to
- * its offset. This will prevent ASM from attempting this computation so that it at least prints
- * the trace and dumps out the classfile to disk (if those {@link Diag}nostics are enabled).
+ * When automatic computation of frames fails, a developer may identify the address of the
+ * passage seed that causes such a failure and set this variable to its offset. This will cause
+ * the Class-File API to drop stack maps
+ * ({@link java.lang.classfile.ClassFile.StackMapsOption#DROP_STACK_MAPS}) so that the classfile
+ * can at least be dumped to disk for examination (if those {@linkplain Diag diagnostics} are
+ * enabled). The resulting class will not be loadable by the JVM, but offline tools like
+ * {@code javap} can still inspect it.
* <p>
- * Once the trace/classfile is obtained, set this back to -1 and then apply debug prints in the
- * crashing method. Since it's probably in the ASM library, you'll need to use your IDE /
- * debugger to inject those prints. The way to do this in Eclipse is to set a "conditional
- * breakpoint" then have the condition print the value and return false, so that execution
- * continues. Sadly, this will still slow execution down considerably, so you'll want to set
- * some other conditional breakpoint to catch when the troublesome passage is being translated.
- * Probably the most helpful thing to print is the bytecode offset of each basic block ASM is
- * processing as it computes the frames. Once it crashes, look at the last couple of bytecode
- * offsets in the dumped classfile.
+ * Once the classfile is obtained, set this back to -1 and investigate the issue using debug
+ * prints or a debugger.
*/
public static final long EXCLUDE_MAXS = -1L;
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitJvmTypeUtils.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitJvmTypeUtils.java
index 4e7912a655..3125d65b66 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitJvmTypeUtils.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitJvmTypeUtils.java
@@ -15,34 +15,34 @@
*/
package ghidra.pcode.emu.jit;
+import java.lang.classfile.ClassBuilder;
+import java.lang.constant.ClassDesc;
import java.lang.reflect.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.reflect.TypeLiteral;
-import org.objectweb.asm.ClassVisitor;
/**
* Some utilities for generating type signatures, suitable for use with
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}.
- *
+ * {@link ClassBuilder#withField(String, ClassDesc, int)}.
* <p>
- * <b>WARNING:</b> It seems to me, the internal representation of signatures as accepted by the ASM
- * API is not fixed from version to version. In the future, these utilities may need to be updated
- * to work with multiple versions, if the representation changes in a newer classfile format.
- * Hopefully, the upcoming classfile API will obviate the need for any of this.
+ * <b>WARNING:</b> The internal representation of type signatures is defined by the JVM
+ * specification. While the standard Class-File API handles most descriptor generation, these
+ * utilities produce <em>generic</em> signatures (as in the {@code Signature} attribute), which
+ * still require manual construction.
*/
public enum JitJvmTypeUtils {
;
/**
- * Get the internal name of a class as in {@link org.objectweb.asm.Type#getInternalName(Class)}.
- *
+ * Get the internal name of a class (e.g., {@code java.lang.String}).
+ *
* @param cls the class
* @return the internal name
*/
public static String classToInternalName(Class<?> cls) {
- return org.objectweb.asm.Type.getInternalName(cls);
+ return cls.getName().replace('.', '/');
}
/**
@@ -57,7 +57,6 @@ public enum JitJvmTypeUtils {
/**
* Get the signature of the given wildcard type
- *
* <ul>
* <li>{@code sig(?) = *}</li>
* <li>{@code sig(? super MyType) = -sig(MyType)}</li>
@@ -84,14 +83,11 @@ public enum JitJvmTypeUtils {
/**
* Get the signature of the given type
- *
* <p>
* For the use case this supports, probably the best way to obtain a {@link Type} is via
* {@link TypeLiteral}.
- *
* <p>
* As of the JVM 21, internal type signatures are derived as:
- *
* <ul>
* <li>{@code sig(my.MyType) = Lmy/MyType.class;}</li>
* <li>{@code sig(my.MyType[]) = [sig(my.MyType)}</li>
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitPcodeEmulator.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitPcodeEmulator.java
index 78f83fa10a..59316ef2d6 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitPcodeEmulator.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/JitPcodeEmulator.java
@@ -16,6 +16,7 @@
package ghidra.pcode.emu.jit;
import java.lang.invoke.MethodHandles.Lookup;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -23,7 +24,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.apache.commons.lang3.exception.ExceptionUtils;
-import org.objectweb.asm.MethodTooLargeException;
import ghidra.pcode.emu.*;
import ghidra.pcode.emu.jit.JitPassage.AddrCtx;
@@ -296,7 +296,10 @@ public class JitPcodeEmulator extends PcodeEmulator {
try {
return compiler.compilePassage(lookup, decoded);
}
- catch (MethodTooLargeException e) {
+ catch (IllegalArgumentException e) {
+ if (!isMethodTooLargeException(e)) {
+ throw e;
+ }
Msg.warn(this, "Method too large for " + pcCtx + " with maxOps=" + maxOps +
". Retrying with half.");
maxOps >>= 1;
@@ -416,4 +419,22 @@ public class JitPcodeEmulator extends PcodeEmulator {
public void addAccessBreakpoint(AddressRange range, AccessKind kind) {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Check if the given exception is a "method too large" error from the ClassFile API.
+ *
+ * @param e the exception to check
+ * @return true if the exception indicates a method-too-large condition
+ */
+ private static boolean isMethodTooLargeException(IllegalArgumentException e) {
+ String msg = e.getMessage();
+ if (msg == null) {
+ return false;
+ }
+ // FRAGILE: ClassFile API throws IAE with "too large" for oversized methods.
+ // No typed exception exists (as of JDK 25). Also check stack origin.
+ return msg.toLowerCase().contains("too large")
+ && Arrays.stream(e.getStackTrace())
+ .anyMatch(f -> f.getClassName().startsWith("java.lang.classfile"));
+ }
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitAllocationModel.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitAllocationModel.java
index ed170a7a72..fe70384259 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitAllocationModel.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitAllocationModel.java
@@ -17,11 +17,10 @@ package ghidra.pcode.emu.jit.analysis;
import static ghidra.pcode.emu.jit.analysis.JitVarScopeModel.maxAddr;
+import java.lang.classfile.CodeBuilder;
import java.math.BigInteger;
import java.util.*;
-import org.objectweb.asm.Opcodes;
-
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
import ghidra.pcode.emu.jit.JitBytesPcodeExecutorState;
import ghidra.pcode.emu.jit.JitCompiler;
@@ -144,8 +143,8 @@ import ghidra.program.model.pcode.Varnode;
* This actually extends a little beyond allocation, but this is a suitable place for it: All SSA
* values are assigned a handler, including constants and memory variables. Variables which access
* the same varnode get the same handler. For varnodes that are allocated in a JVM local, we create
- * a handler that generates loads and stores to that local, e.g., {@link Opcodes#ILOAD iload}. For
- * constant varnodes, we create a handler that generates {@link Opcodes#LDC ldc} instructions. For
+ * a handler that generates loads and stores to that local, e.g., {@link CodeBuilder#iload}. For
+ * constant varnodes, we create a handler that generates {@link CodeBuilder#ldc} instructions. For
* memory varnodes, we create a handler that generates a sequence of method invocations on the
* {@link JitBytesPcodeExecutorState state}. The code generator will delegate to these handlers in
* order to generate reads and writes of the corresponding variables, as well as to prepare any
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitType.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitType.java
index 08be520340..8c7b83dbe3 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitType.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitType.java
@@ -15,10 +15,9 @@
*/
package ghidra.pcode.emu.jit.analysis;
+import java.lang.classfile.CodeBuilder;
import java.util.*;
-import org.objectweb.asm.Opcodes;
-
import ghidra.lifecycle.Unfinished;
import ghidra.pcode.emu.jit.gen.opnd.Opnd;
import ghidra.pcode.emu.jit.gen.opnd.SimpleOpnd;
@@ -27,7 +26,6 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
/**
* The p-code type of an operand.
- *
* <p>
* A type is an integer of floating-point value of a specific size in bytes. All values and
* variables in p-code are just bit vectors. The operators interpret those vectors according to a
@@ -96,7 +94,6 @@ public interface JitType {
/**
* Identify the p-code type that is exactly represented by the given JVM type.
- *
* <p>
* This is used during Direct userop invocation to convert the arguments and return value.
*
@@ -146,7 +143,6 @@ public interface JitType {
/**
* Identify the p-code type that is exactly represented by the given JVM type.
- *
* <p>
* This is used during Direct userop invocation to convert the arguments and return value.
*
@@ -190,7 +186,6 @@ public interface JitType {
/**
* Re-apply the {@link JitTypeBehavior#INTEGER integer} behavior to this type
- *
* <p>
* This may be slightly faster than {@code JitTypeBehavior.INTEGER.resolve(this)}, because
* each type can pick its int type directly, and integer types can just return {@code this}.
@@ -466,7 +461,6 @@ public interface JitType {
/**
* The p-code types for integers of size 9 and greater.
- *
* <p>
* We take the strategy of inlined manipulation of int locals, composed to form the full
* variable. When stored on the stack, the least-significant portion is always toward the top,
@@ -630,11 +624,10 @@ public interface JitType {
/**
* Extend this p-code type to the p-code type that fills its entire host JVM type.
- *
* <p>
* This is useful, e.g., when multiplying two {@link IntJitType#I3 int3} values using
- * {@link Opcodes#IMUL imul} that the result might be an {@link IntJitType#I4 int4} and so may
- * need additional conversion.
+ * {@link CodeBuilder#imul imul} that the result might be an {@link IntJitType#I4 int4} and so
+ * may need additional conversion.
*
* @return the extended type
*/
@@ -642,7 +635,6 @@ public interface JitType {
/**
* Get the p-code type that describes the part of the variable in each leg
- *
* <p>
* Each whole leg will have the type {@link IntJitType#I4}, and the partial leg, if applicable,
* will have its appropriate smaller integer type.
@@ -653,7 +645,6 @@ public interface JitType {
/**
* Get the p-code type that describes the part of the variable in each leg
- *
* <p>
* Each whole leg will have the type {@link IntJitType#I4}, and the partial leg, if applicable,
* will have its appropriate smaller integer type.
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitTypeModel.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitTypeModel.java
index c3d11cf332..c1d0cf64d7 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitTypeModel.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/analysis/JitTypeModel.java
@@ -15,11 +15,10 @@
*/
package ghidra.pcode.emu.jit.analysis;
+import java.lang.classfile.CodeBuilder;
import java.util.*;
import java.util.Map.Entry;
-import org.objectweb.asm.Opcodes;
-
import ghidra.pcode.emu.jit.JitCompiler;
import ghidra.pcode.emu.jit.analysis.JitType.FloatJitType;
import ghidra.pcode.emu.jit.analysis.JitType.IntJitType;
@@ -100,14 +99,14 @@ import ghidra.program.model.pcode.PcodeOp;
* The native translation to bytecode:
*
* <pre>
- * FLOAD 1 # r0
- * FLOAD 2 # r1
- * FADD
- * FSTORE 3 # $U00:4
- * LDC 0
- * ILOAD 3 # $U00:4
- * ISUB
- * ISTORE 4 # r2
+ * fload 1 # r0
+ * fload 2 # r1
+ * fadd
+ * fstore 3 # $U00:4
+ * ldc 0
+ * iload 3 # $U00:4
+ * isub
+ * istore 4 # r2
* </pre>
* <p>
* Will cause an error when loading the class. This is because the local variable 3 must be one of
@@ -116,8 +115,8 @@ import ghidra.program.model.pcode.PcodeOp;
* type {@code float} to local variable 3, and change the erroneous {@code ILOAD 3} to:
*
* <pre>
- * FLOAD 3
- * INVOKESTATIC {@link Float#floatToRawIntBits(float)}
+ * fload 3
+ * invokestatic {@link Float#floatToRawIntBits(float)}
* </pre>
* <p>
* At this point, the bit-vector contents of {@code $U00:4} are on the stack, but for all the JVM
@@ -140,7 +139,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <p>
* Consider {@code r2 = INT_MULT r0, r1} where the registers are all 5 bytes. Thus, the registers
* are allocated as JVM locals of type {@code long}. We load {@code r0} and {@code r1} onto the
- * stack, and then we emit an {@link Opcodes#LMUL}. Technically, the result is another JVM
+ * stack, and then we emit an {@link CodeBuilder#lmul}. Technically, the result is another JVM
* {@code long}, which maps to an 8-byte p-code integer. Thus, we must apply a mask to "convert" the
* result to a 5-byte p-code integer before storing the result in {@code r2}'s JVM local.
*
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/ExceptionHandler.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/ExceptionHandler.java
index de0a80f39e..c8fdbc2ff5 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/ExceptionHandler.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/ExceptionHandler.java
@@ -15,7 +15,6 @@
*/
package ghidra.pcode.emu.jit.gen;
-import ghidra.pcode.emu.jit.JitPassage.DecodedPcodeOp;
import ghidra.pcode.emu.jit.analysis.JitControlFlowModel.JitBlock;
import ghidra.pcode.emu.jit.gen.JitCodeGenerator.PcGen;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
@@ -29,14 +28,14 @@ import ghidra.program.model.pcode.PcodeOp;
* A requested exception handler
* <p>
* When an exception occurs, we must retire all of the variables before we pop the
- * {@link JitCompiledPassage#run(int) run} method's frame. We also write out the program counter and
+ * {@link JitCompiledPassage#run run} method's frame. We also write out the program counter and
* disassembly context so that the emulator can resume appropriately. After that, we re-throw the
* exception.
* <p>
* When the code generator knows the code it's emitting can cause a user exception, e.g., the Direct
* invocation of a userop, and there are live variables in scope, then it should request a handler
- * (via {@link JitCodeGenerator#requestExceptionHandler(DecodedPcodeOp, JitBlock)}) and surround the
- * code in a {@code try-catch} on {@link Throwable} directing it to this handler.
+ * (via {@link JitCodeGenerator#requestExceptionHandler}) and surround the code in a
+ * {@code try-catch} on {@link Throwable} directing it to this handler.
*
* @param op the op which may cause an exception
* @param block the block containing the op
@@ -45,12 +44,13 @@ import ghidra.program.model.pcode.PcodeOp;
public record ExceptionHandler(PcodeOp op, JitBlock block, Lbl<Ent<Bot, TRef<Throwable>>> lbl) {
/**
* Construct a handler, generating a new label
- *
+ *
* @param op the op which may cause an exception
* @param block the block containing the op
+ * @param em the emitter for the run method containing the handler
*/
- public ExceptionHandler(PcodeOp op, JitBlock block) {
- this(op, block, Lbl.create());
+ public ExceptionHandler(PcodeOp op, JitBlock block, Emitter<?> em) {
+ this(op, block, Lbl.create(em));
}
/**
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForArrDirect.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForArrDirect.java
index 503ab4445b..c38db4bb1f 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForArrDirect.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForArrDirect.java
@@ -15,10 +15,10 @@
*/
package ghidra.pcode.emu.jit.gen;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
-import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static java.lang.classfile.ClassFile.ACC_FINAL;
+import static java.lang.classfile.ClassFile.ACC_PRIVATE;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.JitBytesPcodeExecutorStatePiece.JitBytesPcodeExecutorStateSpace;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
@@ -65,8 +65,8 @@ public record FieldForArrDirect(Address address) implements InstanceFieldReq<TRe
*/
@Override
public <THIS extends JitCompiledPassage, N extends Next> Emitter<N> genInit(Emitter<N> em,
- Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassVisitor cv) {
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, Types.T_BYTE_ARR, name());
+ Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassBuilder clb) {
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, Types.T_BYTE_ARR, name());
return em
.emit(Op::aload, localThis)
.emit(gen::genLoadJitStateSpace, localThis, address.getAddressSpace())
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForContext.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForContext.java
index 57a54f1e6d..b5d1e3254d 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForContext.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForContext.java
@@ -16,9 +16,9 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.*;
+import static java.lang.classfile.ClassFile.*;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
import ghidra.pcode.emu.jit.gen.util.*;
@@ -50,11 +50,11 @@ record FieldForContext(RegisterValue ctx) implements StaticFieldReq<TRef<Registe
*/
@Override
public <N extends Next> Emitter<N> genClInitCode(Emitter<N> em, JitCodeGenerator<?> gen,
- ClassVisitor cv) {
+ ClassBuilder clb) {
if (ctx == null) {
return em;
}
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_REGISTER_VALUE, name());
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_REGISTER_VALUE, name());
return em
.emit(Op::getstatic, gen.typeThis, "LANGUAGE", T_LANGUAGE)
.emit(Op::ldc__a, ctx.getUnsignedValue().toString(16))
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForExitSlot.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForExitSlot.java
index 0fc95b36c1..72e6cf7df7 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForExitSlot.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForExitSlot.java
@@ -16,10 +16,10 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
-import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static java.lang.classfile.ClassFile.ACC_FINAL;
+import static java.lang.classfile.ClassFile.ACC_PRIVATE;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.JitPassage.AddrCtx;
import ghidra.pcode.emu.jit.JitPassage.ExtBranch;
@@ -76,9 +76,9 @@ public record FieldForExitSlot(AddrCtx target) implements InstanceFieldReq<TRef<
*/
@Override
public <THIS extends JitCompiledPassage, N extends Next> Emitter<N> genInit(Emitter<N> em,
- Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassVisitor cv) {
+ Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassBuilder clb) {
FieldForContext ctxField = gen.requestStaticFieldForContext(target.rvCtx);
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, T_EXIT_SLOT, name());
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, T_EXIT_SLOT, name());
return em
.emit(Op::aload, localThis)
.emit(Op::dup)
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForPcodeOp.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForPcodeOp.java
index ee354abba9..accdb5b266 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForPcodeOp.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForPcodeOp.java
@@ -16,14 +16,13 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.*;
+import static java.lang.classfile.ClassFile.*;
+import java.lang.classfile.ClassBuilder;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.objectweb.asm.ClassVisitor;
-
import ghidra.pcode.emu.jit.gen.util.*;
import ghidra.pcode.emu.jit.gen.util.Emitter.Ent;
import ghidra.pcode.emu.jit.gen.util.Emitter.Next;
@@ -66,8 +65,8 @@ public class FieldForPcodeOp implements StaticFieldReq<TRef<PcodeOp>> {
@Override
public <N extends Next> Emitter<N> genClInitCode(Emitter<N> em, JitCodeGenerator<?> gen,
- ClassVisitor cv) {
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, GenConsts.T_PCODE_OP, name());
+ ClassBuilder clb) {
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, GenConsts.T_PCODE_OP, name());
var emIns = em
.emit(gen::genAddress, op.getSeqnum().getTarget())
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForSpaceIndirect.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForSpaceIndirect.java
index 3ce88005a3..f53bb157e5 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForSpaceIndirect.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForSpaceIndirect.java
@@ -16,10 +16,10 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.T_JIT_BYTES_PCODE_EXECUTOR_STATE_SPACE;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
-import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static java.lang.classfile.ClassFile.ACC_FINAL;
+import static java.lang.classfile.ClassFile.ACC_PRIVATE;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.JitBytesPcodeExecutorStatePiece.JitBytesPcodeExecutorStateSpace;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
@@ -62,8 +62,8 @@ public record FieldForSpaceIndirect(AddressSpace space)
*/
@Override
public <THIS extends JitCompiledPassage, N extends Next> Emitter<N> genInit(Emitter<N> em,
- Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassVisitor cv) {
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, T_JIT_BYTES_PCODE_EXECUTOR_STATE_SPACE, name());
+ Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassBuilder clb) {
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, T_JIT_BYTES_PCODE_EXECUTOR_STATE_SPACE, name());
return em
.emit(Op::aload, localThis)
.emit(gen::genLoadJitStateSpace, localThis, space)
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForUserop.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForUserop.java
index 235ab9736c..23d336dd66 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForUserop.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForUserop.java
@@ -16,10 +16,10 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
-import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
+import static java.lang.classfile.ClassFile.ACC_FINAL;
+import static java.lang.classfile.ClassFile.ACC_PRIVATE;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.analysis.JitDataFlowUseropLibrary;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
@@ -62,8 +62,8 @@ public record FieldForUserop(PcodeUseropDefinition<?> userop)
*/
@Override
public <THIS extends JitCompiledPassage, N extends Next> Emitter<N> genInit(Emitter<N> em,
- Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassVisitor cv) {
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, T_PCODE_USEROP_DEFINITION, name());
+ Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassBuilder clb) {
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, T_PCODE_USEROP_DEFINITION, name());
return em
.emit(Op::aload, localThis)
.emit(Op::dup)
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForVarnode.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForVarnode.java
index a58577495f..968f15746a 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForVarnode.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/FieldForVarnode.java
@@ -16,9 +16,9 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.*;
+import static java.lang.classfile.ClassFile.*;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.analysis.JitDataFlowUseropLibrary;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
@@ -61,8 +61,8 @@ public record FieldForVarnode(Varnode vn) implements StaticFieldReq<TRef<Varnode
*/
@Override
public <N extends Next> Emitter<N> genClInitCode(Emitter<N> em, JitCodeGenerator<?> gen,
- ClassVisitor cv) {
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_VARNODE, name());
+ ClassBuilder clb) {
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_VARNODE, name());
return em
.emit(Op::getstatic, gen.typeThis, "ADDRESS_FACTORY", T_ADDRESS_FACTORY)
.emit(Op::ldc__a, vn.getAddress().getAddressSpace().getName())
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/GenConsts.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/GenConsts.java
index 708981acd8..3a9ba2dfac 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/GenConsts.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/GenConsts.java
@@ -19,8 +19,6 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
-import org.objectweb.asm.Type;
-
import ghidra.generic.util.datastruct.SemisparseByteArray;
import ghidra.pcode.emu.jit.*;
import ghidra.pcode.emu.jit.JitBytesPcodeExecutorStatePiece.JitBytesPcodeExecutorStateSpace;
@@ -156,8 +154,9 @@ public interface GenConsts {
MthDesc.returns(Types.T_LONG).param(Types.T_INT).build();
public static final MthDesc<TRef<Integer>, Ent<Bot, TInt>> MDESC_INTEGER__VALUE_OF =
MthDesc.returns(TR_INTEGER).param(Types.T_INT).build();
- public static final String MDESC_JIT_BYTES_PCODE_EXECUTOR_STATE__GET_LANGUAGE =
- Type.getMethodDescriptor(Type.getType(Language.class));
+ public static final MthDesc<TRef<Language>,
+ Bot> MDESC_JIT_BYTES_PCODE_EXECUTOR_STATE__GET_LANGUAGE =
+ MthDesc.returns(T_LANGUAGE).build();
public static final MthDesc<TRef<JitBytesPcodeExecutorStateSpace>,
Ent<Bot, TRef<AddressSpace>>> MDESC_JIT_BYTES_PCODE_EXECUTOR_STATE__GET_SPACE_FOR =
MthDesc.returns(T_JIT_BYTES_PCODE_EXECUTOR_STATE_SPACE).param(T_ADDRESS_SPACE).build();
@@ -338,8 +337,8 @@ public interface GenConsts {
MthDesc.returns(T_JIT_THREAD_BYTES_PCODE_EXECUTOR_STATE).build();
public static final MthDesc<TRef<AddressFactory>, Bot> MDESC_LANGUAGE__GET_ADDRESS_FACTORY =
MthDesc.returns(T_ADDRESS_FACTORY).build();
- public static final String MDESC_LANGUAGE__GET_DEFAULT_SPACE =
- Type.getMethodDescriptor(Type.getType(AddressSpace.class));
+ public static final MthDesc<TRef<AddressSpace>, Bot> MDESC_LANGUAGE__GET_DEFAULT_SPACE =
+ MthDesc.returns(T_ADDRESS_SPACE).build();
public static final MthDesc<TInt, Ent<Bot, TRef<Object>>> MDESC_LIST__ADD =
MthDesc.returns(Types.T_BOOL).param(T_OBJECT).build();
public static final MthDesc<TInt, Ent<Bot, TLong>> MDESC_LONG__BIT_COUNT =
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/InstanceFieldReq.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/InstanceFieldReq.java
index 9df88a8cfe..93fd62f02b 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/InstanceFieldReq.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/InstanceFieldReq.java
@@ -15,7 +15,7 @@
*/
package ghidra.pcode.emu.jit.gen;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
import ghidra.pcode.emu.jit.gen.util.Emitter;
@@ -33,7 +33,6 @@ import ghidra.pcode.emu.jit.gen.util.Types.TRef;
public interface InstanceFieldReq<T extends BNonVoid> extends FieldReq<T> {
/**
* Emit the field declaration and its initialization bytecode
- *
* <p>
* The declaration is emitted into the class definition, and the initialization code is emitted
* into the class constructor.
@@ -43,11 +42,11 @@ public interface InstanceFieldReq<T extends BNonVoid> extends FieldReq<T> {
* @param em the emitter typed with the incoming stack
* @param localThis a handle to the local holding the {@code this} reference
* @param gen the code generator
- * @param cv the visitor for the class definition
+ * @param clb the builder for the class definition
* @return the emitter typed with the incoming stack
*/
<THIS extends JitCompiledPassage, N extends Next> Emitter<N> genInit(Emitter<N> em,
- Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassVisitor cv);
+ Local<TRef<THIS>> localThis, JitCodeGenerator<THIS> gen, ClassBuilder clb);
/**
* Emit code to load the field onto the JVM stack
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/JitCodeGenerator.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/JitCodeGenerator.java
index 43b2a9160f..747f3f2f45 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/JitCodeGenerator.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/JitCodeGenerator.java
@@ -16,16 +16,16 @@
package ghidra.pcode.emu.jit.gen;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
-import static org.objectweb.asm.Opcodes.*;
+import static java.lang.classfile.ClassFile.*;
import java.io.*;
+import java.lang.classfile.*;
+import java.lang.constant.ClassDesc;
import java.lang.invoke.MethodHandles.Lookup;
import java.util.*;
import java.util.stream.Stream;
import org.apache.commons.lang3.reflect.TypeLiteral;
-import org.objectweb.asm.*;
-import org.objectweb.asm.util.TraceClassVisitor;
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
import ghidra.pcode.emu.jit.*;
@@ -147,8 +147,8 @@ import ghidra.util.Msg;
* passage. It consists of these sub-parts:
*
* <ol>
- * <li>Switch table - a {@link Opcodes#TABLESWITCH tableswitch} to jump to the code for the scope
- * transition into the entry block given by {@code blockId}</li>
+ * <li>Switch table - a {@link CodeBuilder#tableswitch} to jump to the code for the scope transition
+ * into the entry block given by {@code blockId}</li>
* <li>Scope transitions - for each block, birth its live varnodes then jump to the block's
* translation</li>
* <li>Default case - throws an {@link IllegalArgumentException} for an invalid {@code blockId}</li>
@@ -183,9 +183,8 @@ import ghidra.util.Msg;
* @implNote Throughout most of the code that emits bytecode, there are (human-generated) comments
* to track the contents of the JVM stack. Items pushed onto the stack appear at the
* right. If type is important, then those are denoted using :TYPE after the relevant
- * variable. TODO: It'd be nice to have a bytecode API that enforces stack structure using
- * the compiler (somehow), but that's probably overkill. Also, I have yet to see what the
- * official classfile API will bring.
+ * variable. The type-safe {@link Emitter} now enforces stack structure at compile time
+ * via Java generics.
* @param <THIS> the type of the generated passage
*/
public class JitCodeGenerator<THIS extends JitCompiledPassage> {
@@ -247,18 +246,15 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
final String nameThis;
final TRef<THIS> typeThis;
- private final ClassWriter cw;
- private final ClassVisitor cv;
-
/**
* Construct a code generator for the given passage's target classfile
* <p>
* This constructor chooses the name for the target classfile based on the passage's entry seed.
* It has the form: <code> Passage$at_<em>address</em>_<em>context</em></code>. The address is
* as rendered by {@link Address#toString()} but with characters replaced to make it a valid JVM
- * classfile name. The decode context is rendered in hexadecimal. This constructor also declares
- * the fields and methods, and emits the definition for {@link JitCompiledPassage#thread()}.
- *
+ * classfile name. The decode context is rendered in hexadecimal. Actual class construction
+ * (fields, methods, bytecode) is deferred to {@link #generate()}.
+ *
* @param lookup a means of accessing user-defined components, namely userops
* @param context the analysis context for the passage
* @param cfm the control flow model
@@ -282,7 +278,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
this.am = am;
this.oum = oum;
- // TODO: Should I incorporate more of the address set into the name?
AddrCtx entry = context.getPassage().getEntry();
String pkgThis = lookup.lookupClass().getPackageName().replace(".", "/");
if (!pkgThis.isEmpty()) {
@@ -293,41 +288,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
.replace(":", "_")
.replace(" ", "_");
this.typeThis = Types.refExtends(JitCompiledPassage.class, "L" + nameThis + ";");
-
- int flags = entry.address.getOffset() == JitCompiler.EXCLUDE_MAXS ? 0
- : ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS;
- cw = new ClassWriter(flags);
- if (JitCompiler.ENABLE_DIAGNOSTICS.contains(Diag.TRACE_CLASS)) {
- cv = new TraceClassVisitor(cw, new PrintWriter(System.err));
- }
- else {
- this.cv = cw;
- }
-
- cv.visit(V17, ACC_PUBLIC, nameThis, null, Type.getInternalName(Object.class), new String[] {
- Type.getInternalName(JitCompiledPassage.class),
- });
-
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_STRING, "LANGUAGE_ID",
- context.getLanguage().getLanguageID().toString());
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_LANGUAGE, "LANGUAGE");
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_ADDRESS_FACTORY, "ADDRESS_FACTORY");
- Fld.decl(cv, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, new TypeLiteral<List<AddrCtx>>() {},
- "ENTRIES");
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, T_JIT_PCODE_THREAD, "thread");
- Fld.decl(cv, ACC_PRIVATE | ACC_FINAL, T_JIT_BYTES_PCODE_EXECUTOR_STATE, "state");
-
- var paramsThread = new Object() {
- Local<TRef<THIS>> this_;
- };
- var retThread = Emitter.start(typeThis, cv, ACC_PUBLIC, "thread",
- MthDesc.returns(T_JIT_PCODE_THREAD).build())
- .param(Def::done, typeThis, l -> paramsThread.this_ = l);
- retThread.em()
- .emit(Op::aload, paramsThread.this_)
- .emit(Op::getfield, typeThis, "thread", T_JIT_PCODE_THREAD)
- .emit(Op::areturn, retThread.ret())
- .emit(Misc::finish);
}
/**
@@ -367,7 +327,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Emit the first bytecodes for the static initializer
- *
* <p>
* This generates code equivalent to:
*
@@ -377,7 +336,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* ADDRESS_FACTORY = LANGUAGE.getAddressFactory();
* }
* </pre>
- *
* <p>
* Note that {@code LANGUAGE_ID} is initialized to a constant {@link String} in its declaration.
* Additional {@link StaticFieldReq static fields} may be requested as the p-code translation is
@@ -401,7 +359,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Emit the first bytecodes for the class constructor
- *
* <p>
* This generates code equivalent to:
*
@@ -412,7 +369,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* this.state = thread.GetState();
* }
* </pre>
- *
* <p>
* Additional {@link InstanceFieldReq instance fields} may be requested as the p-code
* translation is emitted.
@@ -573,10 +529,11 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* Get the label at the start of a block's translation
*
* @param block the block
+ * @param em an emitter for the method containing the block / label
* @return the label
*/
- public Lbl<Bot> labelForBlock(JitBlock block) {
- return blockLabels.computeIfAbsent(block, _ -> Lbl.create());
+ public Lbl<Bot> labelForBlock(JitBlock block, Emitter<?> em) {
+ return blockLabels.computeIfAbsent(block, _ -> Lbl.create(em));
}
/**
@@ -584,10 +541,12 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
*
* @param op the op that might throw an exception
* @param block the block containing the op
+ * @param em an emitter for the method containing the handler
* @return the exception handler request
*/
- public ExceptionHandler requestExceptionHandler(DecodedPcodeOp op, JitBlock block) {
- return excHandlers.computeIfAbsent(op, o -> new ExceptionHandler(o, block));
+ public ExceptionHandler requestExceptionHandler(DecodedPcodeOp op, JitBlock block,
+ Emitter<?> em) {
+ return excHandlers.computeIfAbsent(op, o -> new ExceptionHandler(o, block, em));
}
/**
@@ -602,7 +561,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Emit bytecode to read the given value onto the JVM stack.
- *
* <p>
* Although the value may be assigned a type by the {@link JitTypeModel}, the type needed by a
* given op might be different.
@@ -716,7 +674,6 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Emit bytecode to write the value on the JVM stack into the given variable.
- *
* <p>
* Although the destination variable may be assigned a type by the {@link JitTypeModel}, the
* type of the value on the stack may not match. This method needs to know that type so that, if
@@ -786,17 +743,16 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* and then emits the actual translation.
* <p>
* Line number information in the JVM is a map of strictly-positive line numbers to bytecode
- * offsets. The ASM library allows this to be populated by placing labels and then emitting a
- * line-number-to-label entry (via {@link MethodVisitor#visitLineNumber(int, Label)}. It seems
- * the JVM presumes the entire class is defined in a single source file, so we are unable to
- * (ab)use a filename field to encode debug information. We can encode the op index into the
+ * offsets. The Class-File API provides {@link CodeBuilder#lineNumber(int)} to record this. It
+ * seems the JVM presumes the entire class is defined in a single source file, so we are unable
+ * to (ab)use a filename field to encode debug information. We can encode the op index into the
* (integer) line number, although we have to add 1 to make it strictly positive.
*
* @param em the emitter typed with the empty stack
* @param localThis a handle to the local holding the {@code this} reference
* @param localCtxmod a handle to the local holding {@code ctxmod}
- * @param retReq an indication of what must be returned by this
- * {@link JitCompiledPassage#run(int)} method.
+ * @param retReq an indication of what must be returned by this {@link JitCompiledPassage#run}
+ * method.
* @param op the op
* @param block the block containing the op
* @param opIdx the index of the op within the whole passage
@@ -823,9 +779,8 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Emit the bytecode translation for the ops in the given p-code block
* <p>
- * This simply invokes {@link #genOp(Emitter, Local, Local, RetReq, PcodeOp, JitBlock, int)} on
- * each op in the block and counts up the indices. Other per-block instrumentation is not
- * included.
+ * This simply invokes {@link #genOp} on each op in the block and counts up the indices. Other
+ * per-block instrumentation is not included.
*
* @param em the emitter
* @param localThis a handle to {@code this}
@@ -834,7 +789,8 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* @param block the block
* @param opIdx the index, within the whole passage, of the first op in the block
* @return the result of block generation
- * @see #genOp(Emitter, Local, Local, RetReq, PcodeOp, JitBlock, int)
+ * @see #genOp
+ * @see #genBlock
*/
protected GenBlockResult genBlockOps(Emitter<Bot> em, Local<TRef<THIS>> localThis,
Local<TInt> localCtxmod, RetReq<TRef<EntryPoint>> retReq, JitBlock block, int opIdx) {
@@ -940,12 +896,15 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* Emit the bytecode translation for the given p-code block
* <p>
* This checks if the block needs a label, i.e., it is an entry or the target of a branch, and
- * then optionally emits an invocation of {@link JitCompiledPassage#count(int, int)}. Finally,
- * it emits the actual ops' translations via
- * {@link #genBlockOps(Emitter, Local, Local, RetReq, JitBlock, int)}.
+ * then optionally emits an invocation of {@link JitCompiledPassage#count}. Finally, it emits
+ * the actual ops' translations via {@link #genBlockOps}.
*
+ * @param prev the result of the previous block's generation
+ * @param localThis a handle to the local holding the {@code this} reference
+ * @param localCtxmod a handle to the local holding {@code ctxmod}
+ * @param retReq an indication of what must be returned
* @param block the block
- * @return the index, within the whole passage, of the op immediately after the block
+ * @return the result of generating the given block
*/
protected GenBlockResult genBlock(GenBlockResult prev, Local<TRef<THIS>> localThis,
Local<TInt> localCtxmod, RetReq<TRef<EntryPoint>> retReq, JitBlock block) {
@@ -956,9 +915,10 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
System.err.println(" gen: has branch into");
}
hasBranchInto = true;
+ var lbl = labelForBlock(block, prev.opResult.em());
live = new LiveOpResult(switch (prev.opResult) {
- case DeadOpResult r -> r.em().emit(Lbl::placeDead, labelForBlock(block));
- case LiveOpResult r -> r.em().emit(Lbl::place, labelForBlock(block));
+ case DeadOpResult r -> r.em().emit(Lbl::placeDead, lbl);
+ case LiveOpResult r -> r.em().emit(Lbl::place, lbl);
});
}
else if (prev.opResult instanceof LiveOpResult r) {
@@ -1001,9 +961,10 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
Emitter<Bot> em;
if (block.first() instanceof DecodedPcodeOp first &&
context.getConfiguration().emitCounters()) {
- ExceptionHandler handler = requestExceptionHandler(first, block);
+ ExceptionHandler handler = requestExceptionHandler(first, block, live.em());
- var tryCatch = Misc.tryCatch(live.em(), Lbl.create(), handler.lbl(), T_THROWABLE);
+ var tryCatch =
+ Misc.tryCatch(live.em(), Lbl.create(live.em()), handler.lbl(), T_THROWABLE);
em = tryCatch.em()
.emit(Op::aload, localThis)
.emit(Op::ldc__i, counter.instructionCount())
@@ -1132,17 +1093,18 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* requests are not known until the run-method generator has finished.
*
* @param em the emitter
+ * @param clb the class builder
* @return the same emitter
*/
- protected Emitter<Bot> genClInitMethod(Emitter<Bot> em) {
+ protected Emitter<Bot> genClInitMethod(Emitter<Bot> em, ClassBuilder clb) {
for (FieldForContext fCtx : fieldsForContext.values()) {
- em = fCtx.genClInitCode(em, this, cv);
+ em = fCtx.genClInitCode(em, this, clb);
}
for (FieldForVarnode fVn : fieldsForVarnode.values()) {
- em = fVn.genClInitCode(em, this, cv);
+ em = fVn.genClInitCode(em, this, clb);
}
for (FieldForPcodeOp fOp : fieldsForOp.values()) {
- em = fOp.genClInitCode(em, this, cv);
+ em = fOp.genClInitCode(em, this, clb);
}
return em;
}
@@ -1162,10 +1124,12 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* generators, but the order would be less helpful.
*
* @param em the emitter
+ * @param clb the class builder
* @param localThis a handle to the local holding the {@code this} reference
* @return the same emitter
*/
- protected Emitter<Bot> genInitMethod(Emitter<Bot> em, Local<TRef<THIS>> localThis) {
+ protected Emitter<Bot> genInitMethod(Emitter<Bot> em, ClassBuilder clb,
+ Local<TRef<THIS>> localThis) {
// NOTE: Ops don't need init. They'll invoke field requests as needed.
// Locals and values first, because they may request fields
@@ -1177,40 +1141,37 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
}
for (FieldForArrDirect fArr : fieldsForArrDirect.values()) {
- em = fArr.genInit(em, localThis, this, cv);
+ em = fArr.genInit(em, localThis, this, clb);
}
for (FieldForExitSlot fExit : fieldsForExitSlot.values()) {
- em = fExit.genInit(em, localThis, this, cv);
+ em = fExit.genInit(em, localThis, this, clb);
}
for (FieldForSpaceIndirect fSpace : fieldsForSpaceIndirect.values()) {
- em = fSpace.genInit(em, localThis, this, cv);
+ em = fSpace.genInit(em, localThis, this, clb);
}
for (FieldForUserop fUserop : fieldsForUserop.values()) {
- em = fUserop.genInit(em, localThis, this, cv);
+ em = fUserop.genInit(em, localThis, this, clb);
}
return em;
}
/**
- * Emit all the bytecode for the {@link JitCompiledPassage#run(int) run} method.
+ * Emit all the bytecode for the {@link JitCompiledPassage#run run} method.
* <p>
* The structure of this method is described by this class's documentation. It first declares
* all the locals allocated by the {@link JitAllocationModel}. It then collects the list of
* entries points and assigns a label to each. These are used when emitting the entry dispatch
* code. Several of those labels may also be re-used when translating branch ops. We must
- * iterate over the blocks in the same order as {@link #genStaticEntries(Emitter)}, so that our
- * indices and its match. Thus, we emit a {@link Op#tableswitch(Emitter, int, Lbl, List)
- * tableswitch} where each value maps to the blocks label identified in the same position of the
- * {@code ENTRIES} field. We also provide a default case that just throws an
- * {@link IllegalArgumentException}. We do not jump directly to the block's translation. Instead
- * we emit a prologue for each block, wherein we birth the variables that block expects to be
- * live, and then jump to the translation. Then, we emit the translation for each block using
- * {@link #genBlock(GenBlockResult, Local, Local, RetReq, JitBlock)}, placing transitions between
- * those connected by fall through using
- * {@link VarGen#computeBlockTransition(Local, JitCodeGenerator, BlockFlow)}. Finally, we emit
- * each requested exception handler using
- * {@link ExceptionHandler#genRun(Emitter, Local, JitCodeGenerator, int)}.
+ * iterate over the blocks in the same order as {@link #genStaticEntries}, so that our indices
+ * and its match. Thus, we emit a {@link Op#tableswitch tableswitch} where each value maps to
+ * the blocks label identified in the same position of the {@code ENTRIES} field. We also
+ * provide a default case that just throws an {@link IllegalArgumentException}. We do not jump
+ * directly to the block's translation. Instead we emit a prologue for each block, wherein we
+ * birth the variables that block expects to be live, and then jump to the translation. Then, we
+ * emit the translation for each block using {@link #genBlock}, placing transitions between
+ * those connected by fall through using {@link VarGen#computeBlockTransition}. Finally, we emit
+ * each requested exception handler using {@link ExceptionHandler#genRun}.
*
* @param em the emitter
* @param localThis a handle to the local holding the {@code this} reference
@@ -1232,10 +1193,10 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
for (JitBlock block : cfm.getBlocks()) {
AddrCtx entry = getOpEntry(block.first());
if (entry != null) {
- entries.put(block, Lbl.create());
+ entries.put(block, Lbl.create(em));
}
}
- Lbl<Bot> lblBadEntry = Lbl.create();
+ Lbl<Bot> lblBadEntry = Lbl.create(em);
var dead = em
.emit(Op::iload, localBlockId)
@@ -1249,7 +1210,7 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
dead = dead
.emit(Lbl::placeDead, ent.getValue())
.emit(VarGen.computeBlockTransition(localThis, this, null, block)::genFwd)
- .emit(Op::goto_, labelForBlock(block));
+ .emit(Op::goto_, labelForBlock(block, dead));
}
if (DEEP_TRACE) {
@@ -1368,7 +1329,11 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
dest.getParentFile().mkdirs();
try (OutputStream os = new FileOutputStream(dest)) {
os.write(bytes);
- new ProcessBuilder("javap", "-c", "-l", dest.getPath()).inheritIO().start().waitFor();
+ if (JitCompiler.ENABLE_DIAGNOSTICS.contains(Diag.TRACE_CLASS))
+ new ProcessBuilder("javap", "-c", "-l", dest.getPath())
+ .inheritIO()
+ .start()
+ .waitFor();
}
catch (IOException | InterruptedException e) {
Msg.warn(this, "Could not dump class file: " + nameThis + " (" + e + ")");
@@ -1379,68 +1344,109 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
/**
* Generate the classfile and get the raw bytes
* <p>
- * This emits all the bytecode for all the required methods, static initializer, and
- * constructor. Once complete, this closes out the methods by letting the ASM library compute
- * the JVM stack frames as well as the maximum stack size and local variable count. Finally, it
- * closes out the class a retrieves the resulting bytes.
- *
+ * This emits all the bytecode for all the required methods, static initializer, and constructor
+ * using the Class-File API. Stack map frames, maximum stack size, and local variable counts are
+ * computed automatically.
+ *
* @return the classfile bytes
- * @implNote The frame and maximums computation does not always succeed, and unfortunately, the
- * ASM library is not terribly keen to explain why. If {@link Diag#DUMP_CLASS} is
- * enabled, we will catch whatever hairy exception gets thrown and close out the
- * method anyway. The resulting class will not likely load into any JVM, but at least
- * you might be able to examine it.
*/
protected byte[] generate() {
- var paramsRun = new Object() {
- Local<TRef<THIS>> this_;
- Local<TInt> blockId;
- };
- if (DEEP_TRACE) {
- System.err.println("Generate: run() {");
+ AddrCtx entry = context.getPassage().getEntry();
+ ClassDesc classDesc = ClassDesc.ofInternalName(nameThis);
+
+ ClassFile.Option[] options;
+ if (entry.address.getOffset() == JitCompiler.EXCLUDE_MAXS) {
+ options = new ClassFile.Option[] { ClassFile.StackMapsOption.DROP_STACK_MAPS };
}
- var retRun = Emitter.start(typeThis, cv, ACC_PUBLIC, "run",
- MthDesc.returns(T_ENTRY_POINT).param(Types.T_INT).build())
- .param(Def::param, Types.T_INT, "blockId", l -> paramsRun.blockId = l)
- .param(Def::done, typeThis, l -> paramsRun.this_ = l);
- retRun.em()
- .emit(this::genRunMethod, paramsRun.this_, paramsRun.blockId, retRun.ret())
- .emit(Misc::finish);
- if (DEEP_TRACE) {
- System.err.println("} // end run()");
+ else {
+ options = new ClassFile.Option[0];
}
- // Run may make requests of Init and ClInit
- var paramsInit = new Object() {
- Local<TRef<THIS>> this_;
- Local<TRef<JitPcodeThread>> thread;
- };
- var retInit = Emitter.start(typeThis, cv, ACC_PUBLIC, "<init>",
- MthDesc.returns(Types.T_VOID).param(T_JIT_PCODE_THREAD).build())
- .param(Def::param, T_JIT_PCODE_THREAD, "thread", l -> paramsInit.thread = l)
- .param(Def::done, typeThis, l -> paramsInit.this_ = l);
- retInit.em()
- .emit(this::startInitMethod, paramsInit.this_, paramsInit.thread)
- .emit(this::genInitMethod, paramsInit.this_)
- .emit(Op::return_, retInit.ret())
- .emit(Misc::finish);
-
- // Run and Init may make requests of ClInit
- var retClInit = Emitter.start(cv, ACC_PUBLIC, "<clinit>",
- MthDesc.returns(Types.T_VOID).build())
- .param(Def::done);
- retClInit.em()
- .emit(this::startClInitMethod)
- .emit(this::genClInitMethod)
- .emit(this::genStaticEntries)
- .emit(Op::return_, retClInit.ret())
- .emit(Misc::finish);
-
- cv.visitEnd();
- if (JitCompiler.ENABLE_DIAGNOSTICS.contains(Diag.DUMP_CLASS)) {
- return dumpBytecode(cw.toByteArray());
+ byte[] bytes = ClassFile.of(options).build(classDesc, clb -> {
+ clb.withFlags(ACC_PUBLIC);
+ clb.withSuperclass(T_OBJECT.classDesc());
+ clb.withInterfaceSymbols(T_JIT_COMPILED_PASSAGE.classDesc());
+
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_STRING, "LANGUAGE_ID",
+ context.getLanguage().getLanguageID().toString());
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_LANGUAGE, "LANGUAGE");
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, T_ADDRESS_FACTORY,
+ "ADDRESS_FACTORY");
+ Fld.decl(clb, ACC_PRIVATE | ACC_STATIC | ACC_FINAL, new TypeLiteral<List<AddrCtx>>() {},
+ "ENTRIES");
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, T_JIT_PCODE_THREAD, "thread");
+ Fld.decl(clb, ACC_PRIVATE | ACC_FINAL, T_JIT_BYTES_PCODE_EXECUTOR_STATE, "state");
+
+ // thread() method
+ var mdescThread = MthDesc.returns(T_JIT_PCODE_THREAD).build();
+ Emitter.instanceWithBody(clb, typeThis, "thread", mdescThread, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ };
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(Op::aload, p.this_)
+ .emit(Op::getfield, typeThis, "thread", T_JIT_PCODE_THREAD)
+ .emit(Op::areturn, spec.ret());
+ });
+
+ // run() method
+ var mdescRun = MthDesc.returns(T_ENTRY_POINT).param(Types.T_INT).build();
+ Emitter.instanceWithBody(clb, typeThis, "run", mdescRun, ACC_PUBLIC, mb -> {
+ if (DEEP_TRACE) {
+ System.err.println("Generate: run() {");
+ }
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ Local<TInt> blockId;
+ };
+ var spec = mb.startSpec()
+ .param(Def::param, Types.T_INT, "blockId", i -> p.blockId = i)
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ var dead = spec.em()
+ .emit(this::genRunMethod, p.this_, p.blockId, spec.ret());
+ if (DEEP_TRACE) {
+ System.err.println("} // end run()");
+ }
+ return dead;
+ });
+
+ // Run may make requests of Init and ClInit
+ var mdescInit =
+ MthDesc.returns(Types.T_VOID).param(T_JIT_PCODE_THREAD).build();
+ Emitter.instanceWithBody(clb, typeThis, "<init>", mdescInit, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ Local<TRef<JitPcodeThread>> thread;
+ };
+ var spec = mb.startSpec()
+ .param(Def::param, T_JIT_PCODE_THREAD, "thread", t -> p.thread = t)
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(this::startInitMethod, p.this_, p.thread)
+ .emit(this::genInitMethod, clb, p.this_)
+ .emit(Op::return_, spec.ret());
+ });
+
+ // Run and Init may make requests of ClInit
+ var mdescClInit = MthDesc.returns(Types.T_VOID).build();
+ Emitter.staticWithBody(clb, "<clinit>", mdescClInit, ACC_STATIC, mb -> {
+ var spec = mb.startSpec()
+ .param(Def::done);
+ return spec.em()
+ .emit(this::startClInitMethod)
+ .emit(this::genClInitMethod, clb)
+ .emit(this::genStaticEntries)
+ .emit(Op::return_, spec.ret());
+ });
+ });
+
+ if (JitCompiler.ENABLE_DIAGNOSTICS.contains(Diag.TRACE_CLASS) ||
+ JitCompiler.ENABLE_DIAGNOSTICS.contains(Diag.DUMP_CLASS)) {
+ return dumpBytecode(bytes);
}
- return cw.toByteArray();
+ return bytes;
}
/**
@@ -1606,8 +1612,8 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* Emit code to exit the passage
* <p>
* This retires all the variables of the current block as well as the program counter and decode
- * context. It does not generate the actual {@link Opcodes#ARETURN areturn} or
- * {@link Opcodes#ATHROW athrow}, but everything required up to that point.
+ * context. It does not generate the actual {@code areturn} or {@code athrow}, but everything
+ * required up to that point.
*
* @param <N> the incoming stack
* @param em the emitter typed with the incoming stack
@@ -1658,25 +1664,23 @@ public class JitCodeGenerator<THIS extends JitCompiledPassage> {
* line number, so that tools expecting/requiring line numbers will display something useful.
*/
public static class LineNumberer {
- final MethodVisitor mv;
+ final CodeBuilder cb;
int nextLine = 1;
/**
- * Prepare to number lines on the given method visitor
- *
- * @param mv the method visitor
+ * Prepare to number lines on the given code builder
+ *
+ * @param cb the code builder
*/
- public LineNumberer(MethodVisitor mv) {
- this.mv = mv;
+ public LineNumberer(CodeBuilder cb) {
+ this.cb = cb;
}
/**
* Increment the line number and add info on the next bytecode index
*/
public void nextLine() {
- Label label = new Label();
- mv.visitLabel(label);
- mv.visitLineNumber(nextLine++, label);
+ cb.lineNumber(nextLine++);
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/StaticFieldReq.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/StaticFieldReq.java
index b12b1ea4af..f040aeec32 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/StaticFieldReq.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/StaticFieldReq.java
@@ -15,7 +15,7 @@
*/
package ghidra.pcode.emu.jit.gen;
-import org.objectweb.asm.ClassVisitor;
+import java.lang.classfile.ClassBuilder;
import ghidra.pcode.emu.jit.gen.util.Emitter;
import ghidra.pcode.emu.jit.gen.util.Emitter.Ent;
@@ -31,7 +31,6 @@ public interface StaticFieldReq<T extends BNonVoid> extends FieldReq<T> {
/**
* Emit the field declaration and its initialization bytecode
- *
* <p>
* The declaration is emitted into the class definition, and the initialization code is emitted
* into the class initializer.
@@ -39,11 +38,11 @@ public interface StaticFieldReq<T extends BNonVoid> extends FieldReq<T> {
* @param <N> the incoming stack
* @param em the emitter typed with the incoming stack
* @param gen the code generator
- * @param cv the visitor for the class definition
+ * @param clb the builder for the class definition
* @return the emitter typed with the incoming stack
*/
<N extends Next> Emitter<N> genClInitCode(Emitter<N> em, JitCodeGenerator<?> gen,
- ClassVisitor cv);
+ ClassBuilder clb);
/**
* Emit code to load the field onto the JVM stack
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchIndOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchIndOpGen.java
index e11f81de53..c13141249e 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchIndOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchIndOpGen.java
@@ -120,7 +120,7 @@ public enum BranchIndOpGen implements OpGen<JitBranchIndOp> {
Local<TLong> localTarget = ss.decl(Types.T_LONG, "target");
PcGen missGen = PcGen.loadLocal(localTarget);
BlockFlow flow = block.flowsFrom().get(branch);
- Lbl<Bot> intTargetLabel = gen.labelForBlock(flow.to());
+ Lbl<Bot> intTargetLabel = gen.labelForBlock(flow.to(), em);
var lblHit = em
.emit(targetGen::gen)
.emit(Op::lstore, localTarget)
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchOpGen.java
index dff9e76322..ce0c4e3df7 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/BranchOpGen.java
@@ -214,7 +214,7 @@ public enum BranchOpGen implements OpGen<JitBranchOp> {
Local<TRef<THIS>> localThis, RetReq<TRef<EntryPoint>> retReq,
JitCodeGenerator<THIS> gen, JitOp op, RIntBranch branch, JitBlock block) {
BlockFlow flow = block.flowsFrom().get(branch);
- Lbl<Bot> label = gen.labelForBlock(flow.to());
+ Lbl<Bot> label = gen.labelForBlock(flow.to(), em);
return em
.emit(VarGen.computeBlockTransition(localThis, gen, flow)::genFwd)
.emit(Op::goto_, label);
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CBranchOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CBranchOpGen.java
index 9e712f9834..a94e3cdcfd 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CBranchOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CBranchOpGen.java
@@ -107,7 +107,7 @@ public enum CBranchOpGen implements OpGen<JitCBranchOp> {
RetReq<TRef<EntryPoint>> retReq, JitCodeGenerator<THIS> gen, JitCBranchOp op,
RIntBranch branch, JitBlock block) {
BlockFlow flow = block.flowsFrom().get(branch);
- Lbl<Bot> label = gen.labelForBlock(flow.to());
+ Lbl<Bot> label = gen.labelForBlock(flow.to(), em);
BlockTransition<THIS> transition = VarGen.computeBlockTransition(localThis, gen, flow);
if (!transition.needed()) {
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CallOtherOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CallOtherOpGen.java
index d47c677b1e..0a23fac90b 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CallOtherOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/CallOtherOpGen.java
@@ -311,8 +311,8 @@ public enum CallOtherOpGen implements OpGen<JitCallOtherOpIf> {
}
};
- var tryCatchBlock = Misc.tryCatch(em, Lbl.create(),
- gen.requestExceptionHandler((DecodedPcodeOp) op.op(), block).lbl(),
+ var tryCatchBlock = Misc.tryCatch(em, Lbl.create(em),
+ gen.requestExceptionHandler((DecodedPcodeOp) op.op(), block, em).lbl(),
GenConsts.T_THROWABLE);
em = tryCatchBlock.em();
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/Int2CompOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/Int2CompOpGen.java
index 0c9443b097..091676383d 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/Int2CompOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/Int2CompOpGen.java
@@ -53,14 +53,14 @@ public enum Int2CompOpGen implements IntOpUnOpGen<JitInt2CompOp> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>>
- opForInt(Emitter<N0> em) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>> opForInt(
+ Emitter<N0> em) {
return Op.ineg(em);
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TLong>>
- opForLong(Emitter<N0> em) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TLong>> opForLong(
+ Emitter<N0> em) {
return Op.lneg(em);
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntAddOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntAddOpGen.java
index dc758f3add..2a2ba7139d 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntAddOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntAddOpGen.java
@@ -47,14 +47,14 @@ public enum IntAddOpGen implements IntOpBinOpGen<JitIntAddOp> {
}
@Override
- public <N2 extends Next, N1 extends Ent<N2, TInt>, N0 extends Ent<N1, TInt>>
- Emitter<Ent<N2, TInt>> opForInt(Emitter<N0> em, IntJitType type) {
+ public <N2 extends Next, N1 extends Ent<N2, TInt>, N0 extends Ent<N1, TInt>> Emitter<Ent<N2, TInt>> opForInt(
+ Emitter<N0> em, IntJitType type) {
return Op.iadd(em);
}
@Override
- public <N2 extends Next, N1 extends Ent<N2, TLong>, N0 extends Ent<N1, TLong>>
- Emitter<Ent<N2, TLong>> opForLong(Emitter<N0> em, LongJitType type) {
+ public <N2 extends Next, N1 extends Ent<N2, TLong>, N0 extends Ent<N1, TLong>> Emitter<Ent<N2, TLong>> opForLong(
+ Emitter<N0> em, LongJitType type) {
return Op.ladd(em);
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntCompareBinOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntCompareBinOpGen.java
index 51e53c9f96..799187fc3c 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntCompareBinOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntCompareBinOpGen.java
@@ -195,7 +195,7 @@ public interface IntCompareBinOpGen<T extends JitIntTestOp> extends IntPredBinOp
int legCount = type.legsAlloc();
Local<TInt> localLLeg = scope.decl(Types.T_INT, "lLeg");
Local<TInt> localRLeg = scope.decl(Types.T_INT, "rLeg");
- Lbl<Bot> lblDone = Lbl.create();
+ Lbl<Bot> lblDone = Lbl.create(em);
for (int i = legCount - 1; i > 0; i--) { // Yes, stop one before 0, so use >, not >=
em = em
.emit(gen::genReadLegToStack, localThis, op.l(), type, i, ext())
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntSubOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntSubOpGen.java
index a2545fff32..98b2843441 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntSubOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/IntSubOpGen.java
@@ -47,14 +47,14 @@ public enum IntSubOpGen implements IntOpBinOpGen<JitIntSubOp> {
}
@Override
- public <N2 extends Next, N1 extends Ent<N2, TInt>, N0 extends Ent<N1, TInt>>
- Emitter<Ent<N2, TInt>> opForInt(Emitter<N0> em, IntJitType type) {
+ public <N2 extends Next, N1 extends Ent<N2, TInt>, N0 extends Ent<N1, TInt>> Emitter<Ent<N2, TInt>> opForInt(
+ Emitter<N0> em, IntJitType type) {
return Op.isub(em);
}
@Override
- public <N2 extends Next, N1 extends Ent<N2, TLong>, N0 extends Ent<N1, TLong>>
- Emitter<Ent<N2, TLong>> opForLong(Emitter<N0> em, LongJitType type) {
+ public <N2 extends Next, N1 extends Ent<N2, TLong>, N0 extends Ent<N1, TLong>> Emitter<Ent<N2, TLong>> opForLong(
+ Emitter<N0> em, LongJitType type) {
return Op.lsub(em);
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/LzCountOpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/LzCountOpGen.java
index 0c3b33d5cb..2126449568 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/LzCountOpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/LzCountOpGen.java
@@ -103,7 +103,7 @@ public enum LzCountOpGen implements IntCountUnOpGen<JitLzCountOp> {
* right before the last.
*/
int legCount = type.legsAlloc();
- Lbl<Ent<Bot, TInt>> lblDone = Lbl.create();
+ Lbl<Ent<Bot, TInt>> lblDone = Lbl.create(em);
var emCount = em
.emit(gen::genReadLegToStack, localThis, op.u(), type, legCount - 1, ext())
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/OpGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/OpGen.java
index d1a6ae761a..87c95f92fb 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/OpGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/op/OpGen.java
@@ -17,18 +17,16 @@ package ghidra.pcode.emu.jit.gen.op;
import static ghidra.pcode.emu.jit.gen.GenConsts.*;
+import java.lang.classfile.CodeBuilder;
import java.util.List;
import java.util.stream.Collectors;
-import org.objectweb.asm.Opcodes;
-
import ghidra.pcode.emu.jit.analysis.*;
import ghidra.pcode.emu.jit.analysis.JitControlFlowModel.JitBlock;
import ghidra.pcode.emu.jit.analysis.JitType.IntJitType;
import ghidra.pcode.emu.jit.analysis.JitType.MpIntJitType;
import ghidra.pcode.emu.jit.gen.JitCodeGenerator;
import ghidra.pcode.emu.jit.gen.opnd.Opnd;
-import ghidra.pcode.emu.jit.gen.opnd.Opnd.Ext;
import ghidra.pcode.emu.jit.gen.opnd.SimpleOpnd;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage.EntryPoint;
@@ -40,7 +38,8 @@ import ghidra.pcode.emu.jit.gen.util.Types.TInt;
import ghidra.pcode.emu.jit.gen.util.Types.TRef;
import ghidra.pcode.emu.jit.gen.var.VarGen;
import ghidra.pcode.emu.jit.op.*;
-import ghidra.pcode.emu.jit.var.*;
+import ghidra.pcode.emu.jit.var.JitOutVar;
+import ghidra.pcode.emu.jit.var.JitVal;
import ghidra.pcode.exec.PcodeExecutor;
import ghidra.pcode.exec.PcodeUseropLibrary;
import ghidra.pcode.exec.PcodeUseropLibrary.PcodeUseropDefinition;
@@ -48,13 +47,11 @@ import ghidra.program.model.pcode.PcodeOp;
/**
* The bytecode generator for a specific p-code op
- *
* <p>
* The {@link JitCodeGenerator} selects the correct generator for each {@link PcodeOp} using
* {@link JitDataFlowModel#getJitOp(PcodeOp)} and {@link #lookup(JitOp)}. The following table lists
* each p-code op, its use-def class, its generator class, and a brief strategy for its bytecode
* implementation.
- *
* <table border="1">
* <tr>
* <th>P-code Op</th>
@@ -69,7 +66,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#UNIMPLEMENTED unimplemented}</td>
* <td>{@link JitUnimplementedOp}</td>
* <td>{@link UnimplementedOpGen}</td>
- * <td>{@link Opcodes#NEW new}, {@link Opcodes#ATHROW athrow}</td>
+ * <td>{@link CodeBuilder#new_ new}, {@link CodeBuilder#athrow athrow}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#COPY copy}</td>
@@ -97,14 +94,14 @@ import ghidra.program.model.pcode.PcodeOp;
* {@link PcodeOp#CALL call}</td>
* <td>{@link JitBranchOp}</td>
* <td>{@link BranchOpGen}</td>
- * <td>{@link Opcodes#GOTO goto}, {@link Opcodes#ARETURN areturn}</td>
+ * <td>{@link CodeBuilder#goto_ goto}, {@link CodeBuilder#areturn areturn}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#CBRANCH cbranch}</td>
* <td>{@link JitCBranchOp}</td>
* <td>{@link CBranchOpGen}</td>
- * <td>{@link Opcodes#IFEQ ifeq}, {@link Opcodes#IFEQ ifne}, {@link Opcodes#GOTO goto},
- * {@link Opcodes#ARETURN areturn}</td>
+ * <td>{@link CodeBuilder#ifeq ifeq}, {@link CodeBuilder#ifne ifne}, {@link CodeBuilder#goto_ goto},
+ * {@link CodeBuilder#areturn areturn}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#BRANCHIND branchind},<br/>
@@ -112,7 +109,7 @@ import ghidra.program.model.pcode.PcodeOp;
* {@link PcodeOp#RETURN return}</td>
* <td>{@link JitBranchIndOp}</td>
* <td>{@link BranchIndOpGen}</td>
- * <td>{@link Opcodes#ARETURN areturn}</td>
+ * <td>{@link CodeBuilder#areturn areturn}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#CALLOTHER callother}</td>
@@ -128,8 +125,8 @@ import ghidra.program.model.pcode.PcodeOp;
* <li><b>Standard</b>:
* {@link PcodeUseropDefinition#execute(PcodeExecutor, PcodeUseropLibrary, PcodeOp)}</li>
* <li><b>Inlining</b>: userop's p-code</li>
- * <li><b>Direct</b>: {@link Opcodes#INVOKEVIRTUAL invokevirtual}</li>
- * <li><b>Missing</b>: {@link Opcodes#NEW new}, {@link Opcodes#ATHROW athrow}</li>
+ * <li><b>Direct</b>: {@link CodeBuilder#invokevirtual invokevirtual}</li>
+ * <li><b>Missing</b>: {@link CodeBuilder#new_ new}, {@link CodeBuilder#athrow athrow}</li>
* </ul>
* </td>
* </tr>
@@ -140,37 +137,37 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#INT_EQUAL int_equal}</td>
* <td>{@link JitIntEqualOp}</td>
* <td>{@link IntEqualOpGen}</td>
- * <td>{@link Opcodes#IF_ICMPEQ if_icmpeq}, {@link Opcodes#IFEQ ifeq}</td>
+ * <td>{@link CodeBuilder#if_icmpeq if_icmpeq}, {@link CodeBuilder#ifeq ifeq}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_NOTEQUAL int_notequal}</td>
* <td>{@link JitIntNotEqualOp}</td>
* <td>{@link IntNotEqualOpGen}</td>
- * <td>{@link Opcodes#IF_ICMPNE if_icmpne}, {@link Opcodes#IFNE ifne}</td>
+ * <td>{@link CodeBuilder#if_icmpne if_icmpne}, {@link CodeBuilder#ifne ifne}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_SLESS int_sless}</td>
* <td>{@link JitIntSLessOp}</td>
* <td>{@link IntSLessOpGen}</td>
- * <td>{@link Opcodes#IF_ICMPLT if_icmplt}, {@link Opcodes#IFLT iflt}</td>
+ * <td>{@link CodeBuilder#if_icmplt if_icmplt}, {@link CodeBuilder#iflt iflt}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_SLESSEQUAL int_slessequal}</td>
* <td>{@link JitIntSLessEqualOp}</td>
* <td>{@link IntSLessEqualOpGen}</td>
- * <td>{@link Opcodes#IF_ICMPLE if_icmple}, {@link Opcodes#IFLE ifle}</td>
+ * <td>{@link CodeBuilder#if_icmple if_icmple}, {@link CodeBuilder#ifle ifle}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_LESS int_less}</td>
* <td>{@link JitIntLessOp}</td>
* <td>{@link IntLessOpGen}</td>
- * <td>{@link Integer#compareUnsigned(int, int)}, {@link Opcodes#IFLT iflt}, etc.</td>
+ * <td>{@link Integer#compareUnsigned(int, int)}, {@link CodeBuilder#iflt iflt}, etc.</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_LESSEQUAL int_lessequal}</td>
* <td>{@link JitIntLessEqualOp}</td>
* <td>{@link IntLessEqualOpGen}</td>
- * <td>{@link Integer#compareUnsigned(int, int)}, {@link Opcodes#IFLE ifle}, etc.</td>
+ * <td>{@link Integer#compareUnsigned(int, int)}, {@link CodeBuilder#ifle ifle}, etc.</td>
* </tr>
* <tr>
* <td colspan="4"><em>Integer Arithmetic</em></td>
@@ -191,62 +188,62 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#INT_ADD int_add}</td>
* <td>{@link JitIntAddOp}</td>
* <td>{@link IntAddOpGen}</td>
- * <td>{@link Opcodes#IADD iadd}, {@link Opcodes#LADD ladd}</td>
+ * <td>{@link CodeBuilder#iadd iadd}, {@link CodeBuilder#ladd ladd}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_SUB int_sub}</td>
* <td>{@link JitIntSubOp}</td>
* <td>{@link IntSubOpGen}</td>
- * <td>{@link Opcodes#ISUB isub}, {@link Opcodes#LSUB lsub}</td>
+ * <td>{@link CodeBuilder#isub isub}, {@link CodeBuilder#lsub lsub}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_CARRY int_carry}</td>
* <td>{@link JitIntCarryOp}</td>
* <td>{@link IntCarryOpGen}</td>
- * <td>{@link Integer#compareUnsigned(int, int)}, {@link Opcodes#IADD iadd}, {@link Opcodes#ISHR
- * ishr}, etc.</td>
+ * <td>{@link Integer#compareUnsigned(int, int)}, {@link CodeBuilder#iadd iadd},
+ * {@link CodeBuilder#ishr ishr}, etc.</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_SCARRY int_scarry}</td>
* <td>{@link JitIntSCarryOp}</td>
* <td>{@link IntSCarryOpGen}</td>
- * <td>{@link JitCompiledPassage#sCarryIntRaw(int, int)}, {@link Opcodes#ISHR ishr}, etc.</td>
+ * <td>{@link JitCompiledPassage#sCarryIntRaw(int, int)}, {@link CodeBuilder#ishr ishr}, etc.</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_SBORROW int_sborrow}</td>
* <td>{@link JitIntSBorrowOp}</td>
* <td>{@link IntSBorrowOpGen}</td>
- * <td>{@link JitCompiledPassage#sBorrowIntRaw(int, int)}, {@link Opcodes#ISHR ishr}, etc.</td>
+ * <td>{@link JitCompiledPassage#sBorrowIntRaw(int, int)}, {@link CodeBuilder#ishr ishr}, etc.</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_2COMP int_2comp}</td>
* <td>{@link JitInt2CompOp}</td>
* <td>{@link Int2CompOpGen}</td>
- * <td>{@link Opcodes#INEG ineg}, {@link Opcodes#LNEG lneg}</td>
+ * <td>{@link CodeBuilder#ineg ineg}, {@link CodeBuilder#lneg lneg}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_NEGATE int_negate}</td>
* <td>{@link JitIntNegateOp}</td>
* <td>{@link IntNegateOpGen}</td>
- * <td>{@link Opcodes#ICONST_M1 iconst_m1}, {@link Opcodes#IXOR ixor}, etc.</td>
+ * <td>{@link CodeBuilder#iconst_m1 iconst_m1}, {@link CodeBuilder#ixor ixor}, etc.</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_XOR int_xor}</td>
* <td>{@link JitIntXorOp}</td>
* <td>{@link IntXorOpGen}</td>
- * <td>{@link Opcodes#IXOR ixor}, {@link Opcodes#LXOR lxor}</td>
+ * <td>{@link CodeBuilder#ixor ixor}, {@link CodeBuilder#lxor lxor}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_AND int_and}</td>
* <td>{@link JitIntAndOp}</td>
* <td>{@link IntAndOpGen}</td>
- * <td>{@link Opcodes#IAND iand}, {@link Opcodes#LAND land}</td>
+ * <td>{@link CodeBuilder#iand iand}, {@link CodeBuilder#land land}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_OR int_or}</td>
* <td>{@link JitIntOrOp}</td>
* <td>{@link IntOrOpGen}</td>
- * <td>{@link Opcodes#IOR ior}, {@link Opcodes#LOR lor}</td>
+ * <td>{@link CodeBuilder#ior ior}, {@link CodeBuilder#lor lor}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_LEFT int_left}</td>
@@ -270,7 +267,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#INT_MULT int_mult}</td>
* <td>{@link JitIntMultOp}</td>
* <td>{@link IntMultOpGen}</td>
- * <td>{@link Opcodes#IMUL imul}, {@link Opcodes#LMUL lmul}</td>
+ * <td>{@link CodeBuilder#imul imul}, {@link CodeBuilder#lmul lmul}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_DIV int_div}</td>
@@ -282,7 +279,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#INT_SDIV int_sdiv}</td>
* <td>{@link JitIntSDivOp}</td>
* <td>{@link IntSDivOpGen}</td>
- * <td>{@link Opcodes#IDIV idiv}, {@link Opcodes#LDIV ldiv}</td>
+ * <td>{@link CodeBuilder#idiv idiv}, {@link CodeBuilder#ldiv ldiv}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#INT_REM int_rem}</td>
@@ -294,7 +291,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#INT_SREM int_srem}</td>
* <td>{@link JitIntSRemOp}</td>
* <td>{@link IntSRemOpGen}</td>
- * <td>{@link Opcodes#IREM irem}, {@link Opcodes#LREM lrem}</td>
+ * <td>{@link CodeBuilder#irem irem}, {@link CodeBuilder#lrem lrem}</td>
* </tr>
* <tr>
* <td colspan="4"><em>Boolean Logic</em></td>
@@ -303,25 +300,25 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#BOOL_NEGATE bool_negate}</td>
* <td>{@link JitBoolNegateOp}</td>
* <td>{@link BoolNegateOpGen}</td>
- * <td>Conditional jumps to {@link Opcodes#LDC ldc} 0 or 1</td>
+ * <td>Conditional jumps to {@link CodeBuilder#ldc ldc} 0 or 1</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#BOOL_XOR bool_xor}</td>
* <td>{@link JitBoolXorOp}</td>
* <td>{@link BoolXorOpGen}</td>
- * <td>Conditional jumps to {@link Opcodes#LDC ldc} 0 or 1</td>
+ * <td>Conditional jumps to {@link CodeBuilder#ldc ldc} 0 or 1</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#BOOL_AND bool_and}</td>
* <td>{@link JitBoolAndOp}</td>
* <td>{@link BoolAndOpGen}</td>
- * <td>Conditional jumps to {@link Opcodes#LDC ldc} 0 or 1</td>
+ * <td>Conditional jumps to {@link CodeBuilder#ldc ldc} 0 or 1</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#BOOL_OR bool_or}</td>
* <td>{@link JitBoolOrOp}</td>
* <td>{@link BoolOrOpGen}</td>
- * <td>Conditional jumps to {@link Opcodes#LDC ldc} 0 or 1</td>
+ * <td>Conditional jumps to {@link CodeBuilder#ldc ldc} 0 or 1</td>
* </tr>
* <tr>
* <td colspan="4"><em>Float Comparison</em></td>
@@ -330,25 +327,29 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#FLOAT_EQUAL float_equal}</td>
* <td>{@link JitFloatEqualOp}</td>
* <td>{@link FloatEqualOpGen}</td>
- * <td>{@link Opcodes#FCMPL fcmpl}, {@link Opcodes#FCMPL dcmpl}, {@link Opcodes#IFNE ifeq}</td>
+ * <td>{@link CodeBuilder#fcmpl fcmpl}, {@link CodeBuilder#dcmpl dcmpl}, {@link CodeBuilder#ifne
+ * ifeq}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_NOTEQUAL float_notequal}</td>
* <td>{@link JitFloatNotEqualOp}</td>
* <td>{@link FloatNotEqualOpGen}</td>
- * <td>{@link Opcodes#FCMPL fcmpl}, {@link Opcodes#FCMPL dcmpl}, {@link Opcodes#IFEQ ifne}</td>
+ * <td>{@link CodeBuilder#fcmpl fcmpl}, {@link CodeBuilder#dcmpl dcmpl}, {@link CodeBuilder#ifne
+ * ifne}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_LESS float_less}</td>
* <td>{@link JitFloatLessOp}</td>
* <td>{@link FloatLessOpGen}</td>
- * <td>{@link Opcodes#FCMPG fcmpg}, {@link Opcodes#FCMPL dcmpg}, {@link Opcodes#IFGE iflt}</td>
+ * <td>{@link CodeBuilder#fcmpg fcmpg}, {@link CodeBuilder#dcmpl dcmpg}, {@link CodeBuilder#iflt
+ * iflt}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_LESSEQUAL float_lessequal}</td>
* <td>{@link JitFloatLessEqualOp}</td>
* <td>{@link FloatLessEqualOpGen}</td>
- * <td>{@link Opcodes#FCMPG fcmpg}, {@link Opcodes#FCMPL dcmpg}, {@link Opcodes#IFGT ifle}</td>
+ * <td>{@link CodeBuilder#fcmpg fcmpg}, {@link CodeBuilder#dcmpg dcmpg}, {@link CodeBuilder#ifle
+ * ifle}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_NAN float_nan}</td>
@@ -363,31 +364,31 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#FLOAT_ADD float_add}</td>
* <td>{@link JitFloatAddOp}</td>
* <td>{@link FloatAddOpGen}</td>
- * <td>{@link Opcodes#FADD fadd}, {@link Opcodes#DADD dadd}</td>
+ * <td>{@link CodeBuilder#fadd fadd}, {@link CodeBuilder#dadd dadd}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_DIV float_div}</td>
* <td>{@link JitFloatDivOp}</td>
* <td>{@link FloatDivOpGen}</td>
- * <td>{@link Opcodes#FDIV fdiv}, {@link Opcodes#DDIV ddiv}</td>
+ * <td>{@link CodeBuilder#fdiv fdiv}, {@link CodeBuilder#ddiv ddiv}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_MULT float_mult}</td>
* <td>{@link JitFloatMultOp}</td>
* <td>{@link FloatMultOpGen}</td>
- * <td>{@link Opcodes#FMUL fmul}, {@link Opcodes#DMUL dmul}</td>
+ * <td>{@link CodeBuilder#fmul fmul}, {@link CodeBuilder#dmul dmul}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_SUB float_sub}</td>
* <td>{@link JitFloatSubOp}</td>
* <td>{@link FloatSubOpGen}</td>
- * <td>{@link Opcodes#FSUB fsub}, {@link Opcodes#DSUB dsub}</td>
+ * <td>{@link CodeBuilder#fsub fsub}, {@link CodeBuilder#dsub dsub}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_NEG float_neg}</td>
* <td>{@link JitFloatNegOp}</td>
* <td>{@link FloatNegOpGen}</td>
- * <td>{@link Opcodes#FNEG fneg}, {@link Opcodes#DNEG dneg}</td>
+ * <td>{@link CodeBuilder#fneg fneg}, {@link CodeBuilder#dneg dneg}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_ABS float_abs}</td>
@@ -405,21 +406,21 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#FLOAT_INT2FLOAT float_int2float}</td>
* <td>{@link JitFloatInt2FloatOp}</td>
* <td>{@link FloatInt2FloatOpGen}</td>
- * <td>{@link Opcodes#I2F i2f}, {@link Opcodes#I2D i2d}, {@link Opcodes#L2F l2f}, {@link Opcodes#L2D
- * l2d}</td>
+ * <td>{@link CodeBuilder#i2f i2f}, {@link CodeBuilder#i2d i2d}, {@link CodeBuilder#l2f l2f},
+ * {@link CodeBuilder#l2d l2d}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_FLOAT2FLOAT float_float2float}</td>
* <td>{@link JitFloatFloat2FloatOp}</td>
* <td>{@link FloatFloat2FloatOpGen}</td>
- * <td>{@link Opcodes#F2D f2d}, {@link Opcodes#D2F d2f}</td>
+ * <td>{@link CodeBuilder#f2d f2d}, {@link CodeBuilder#d2f d2f}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_TRUNC float_trunc}</td>
* <td>{@link JitFloatTruncOp}</td>
* <td>{@link FloatTruncOpGen}</td>
- * <td>{@link Opcodes#F2I f2i}, {@link Opcodes#F2L f2l}, {@link Opcodes#D2I d2i}, {@link Opcodes#D2L
- * d2l}</td>
+ * <td>{@link CodeBuilder#f2i f2i}, {@link CodeBuilder#f2l f2l}, {@link CodeBuilder#d2i d2i},
+ * {@link CodeBuilder#d2l d2l}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#FLOAT_CEIL float_ceil}</td>
@@ -446,7 +447,7 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PcodeOp#SUBPIECE subpiece}</td>
* <td>{@link JitSubPieceOp}</td>
* <td>{@link SubPieceOpGen}</td>
- * <td>{@link Opcodes#IUSHR iushr}, {@link Opcodes#LUSHR lushr}</td>
+ * <td>{@link CodeBuilder#iushr iushr}, {@link CodeBuilder#lushr lushr}</td>
* </tr>
* <tr>
* <td>{@link PcodeOp#POPCOUNT popcount}</td>
@@ -479,17 +480,14 @@ import ghidra.program.model.pcode.PcodeOp;
* <td>{@link PhiOpGen}</td>
* </tr>
* </table>
- *
* <p>
* There are other p-code ops. Some are only used in "high" p-code, and so we need not implement
* them here. Others are used in abstract virtual machines, e.g., {@link PcodeOp#NEW} or are just
* not yet implemented, e.g., {@link PcodeOp#SEGMENTOP}.
- *
* <p>
* The mapping from {@link PcodeOp} opcode to {@link JitOp} is done in, e.g.,
* {@link JitOp#binOp(PcodeOp, JitOutVar, JitVal, JitVal)}, and the mapping from {@link JitOp} to
* {@link OpGen} is done in {@link #lookup(JitOp)}.
- *
* <p>
* The synthetic use-def nodes do not correspond to any p-code op. They are synthesized based on
* access patterns to the {@link JitDataFlowState}. Their generators do not emit any bytecode. See
@@ -508,71 +506,71 @@ public interface OpGen<T extends JitOp> {
@SuppressWarnings("unchecked")
static <T extends JitOp> OpGen<T> lookup(T op) {
return (OpGen<T>) switch (op) {
- case JitBoolAndOp andOp -> BoolAndOpGen.GEN;
- case JitBoolNegateOp negOp -> BoolNegateOpGen.GEN;
- case JitBoolOrOp andOp -> BoolOrOpGen.GEN;
- case JitBoolXorOp andOp -> BoolXorOpGen.GEN;
- case JitBranchIndOp branchIndOp -> BranchIndOpGen.GEN;
- case JitBranchOp branchOp -> BranchOpGen.GEN;
- case JitCallOtherOp callOtherOp -> CallOtherOpGen.GEN;
- case JitCallOtherDefOp callOtherOp -> CallOtherOpGen.GEN;
- case JitCallOtherMissingOp callOtherOp -> CallOtherMissingOpGen.GEN;
- case JitCatenateOp catenateOp -> CatenateOpGen.GEN;
- case JitCBranchOp cBranchOp -> CBranchOpGen.GEN;
- case JitCopyOp copyOp -> CopyOpGen.GEN;
- case JitFloatAbsOp absOp -> FloatAbsOpGen.GEN;
- case JitFloatAddOp addOp -> FloatAddOpGen.GEN;
- case JitFloatCeilOp ceilOp -> FloatCeilOpGen.GEN;
- case JitFloatDivOp divOp -> FloatDivOpGen.GEN;
- case JitFloatEqualOp eqOp -> FloatEqualOpGen.GEN;
- case JitFloatFloat2FloatOp f2fOp -> FloatFloat2FloatOpGen.GEN;
- case JitFloatFloorOp floorOp -> FloatFloorOpGen.GEN;
- case JitFloatInt2FloatOp int2FloatOp -> FloatInt2FloatOpGen.GEN;
- case JitFloatLessEqualOp leqOp -> FloatLessEqualOpGen.GEN;
- case JitFloatLessOp lessOp -> FloatLessOpGen.GEN;
- case JitFloatMultOp multOp -> FloatMultOpGen.GEN;
- case JitFloatNaNOp nanOp -> FloatNaNOpGen.GEN;
- case JitFloatNegOp negOp -> FloatNegOpGen.GEN;
- case JitFloatNotEqualOp neqOp -> FloatNotEqualOpGen.GEN;
- case JitFloatRoundOp roundOp -> FloatRoundOpGen.GEN;
- case JitFloatSqrtOp sqrtOp -> FloatSqrtOpGen.GEN;
- case JitFloatSubOp subOp -> FloatSubOpGen.GEN;
- case JitFloatTruncOp truccOp -> FloatTruncOpGen.GEN;
- case JitInt2CompOp twoCompOp -> Int2CompOpGen.GEN;
- case JitIntAddOp addOp -> IntAddOpGen.GEN;
- case JitIntAndOp andOp -> IntAndOpGen.GEN;
- case JitIntCarryOp carryOp -> IntCarryOpGen.GEN;
- case JitIntDivOp divOp -> IntDivOpGen.GEN;
- case JitIntEqualOp eqOp -> IntEqualOpGen.GEN;
- case JitIntNegateOp negOp -> IntNegateOpGen.GEN;
- case JitIntLeftOp leftOp -> IntLeftOpGen.GEN;
- case JitIntLessEqualOp leqOp -> IntLessEqualOpGen.GEN;
- case JitIntLessOp lessOp -> IntLessOpGen.GEN;
- case JitIntMultOp multOp -> IntMultOpGen.GEN;
- case JitIntNotEqualOp neqOp -> IntNotEqualOpGen.GEN;
- case JitIntOrOp orOp -> IntOrOpGen.GEN;
- case JitIntRemOp remOp -> IntRemOpGen.GEN;
- case JitIntRightOp rightOp -> IntRightOpGen.GEN;
- case JitIntSBorrowOp sborrowOp -> IntSBorrowOpGen.GEN;
- case JitIntSCarryOp scarryOp -> IntSCarryOpGen.GEN;
- case JitIntSExtOp sExtOp -> IntSExtOpGen.GEN;
- case JitIntSLessEqualOp sleqOp -> IntSLessEqualOpGen.GEN;
- case JitIntSLessOp sleqOp -> IntSLessOpGen.GEN;
- case JitIntSDivOp sdivOp -> IntSDivOpGen.GEN;
- case JitIntSRemOp sremOp -> IntSRemOpGen.GEN;
- case JitIntSRightOp srightOp -> IntSRightOpGen.GEN;
- case JitIntSubOp subOp -> IntSubOpGen.GEN;
- case JitIntXorOp xorOp -> IntXorOpGen.GEN;
- case JitIntZExtOp sExtOp -> IntZExtOpGen.GEN;
- case JitLoadOp loadOp -> LoadOpGen.GEN;
- case JitLzCountOp lzCountOp -> LzCountOpGen.GEN;
- case JitPhiOp phiOp -> PhiOpGen.GEN;
- case JitPopCountOp popCountOp -> PopCountOpGen.GEN;
- case JitNopOp nopOp -> NopOpGen.GEN;
- case JitStoreOp storeOp -> StoreOpGen.GEN;
- case JitSubPieceOp spOp -> SubPieceOpGen.GEN;
- case JitSynthSubPieceOp subPieceOp -> SynthSubPieceOpGen.GEN;
- case JitUnimplementedOp unimplOp -> UnimplementedOpGen.GEN;
+ case JitBoolAndOp _ -> BoolAndOpGen.GEN;
+ case JitBoolNegateOp _ -> BoolNegateOpGen.GEN;
+ case JitBoolOrOp _ -> BoolOrOpGen.GEN;
+ case JitBoolXorOp _ -> BoolXorOpGen.GEN;
+ case JitBranchIndOp _ -> BranchIndOpGen.GEN;
+ case JitBranchOp _ -> BranchOpGen.GEN;
+ case JitCallOtherOp _ -> CallOtherOpGen.GEN;
+ case JitCallOtherDefOp _ -> CallOtherOpGen.GEN;
+ case JitCallOtherMissingOp _ -> CallOtherMissingOpGen.GEN;
+ case JitCatenateOp _ -> CatenateOpGen.GEN;
+ case JitCBranchOp _ -> CBranchOpGen.GEN;
+ case JitCopyOp _ -> CopyOpGen.GEN;
+ case JitFloatAbsOp _ -> FloatAbsOpGen.GEN;
+ case JitFloatAddOp _ -> FloatAddOpGen.GEN;
+ case JitFloatCeilOp _ -> FloatCeilOpGen.GEN;
+ case JitFloatDivOp _ -> FloatDivOpGen.GEN;
+ case JitFloatEqualOp _ -> FloatEqualOpGen.GEN;
+ case JitFloatFloat2FloatOp _ -> FloatFloat2FloatOpGen.GEN;
+ case JitFloatFloorOp _ -> FloatFloorOpGen.GEN;
+ case JitFloatInt2FloatOp _ -> FloatInt2FloatOpGen.GEN;
+ case JitFloatLessEqualOp _ -> FloatLessEqualOpGen.GEN;
+ case JitFloatLessOp _ -> FloatLessOpGen.GEN;
+ case JitFloatMultOp _ -> FloatMultOpGen.GEN;
+ case JitFloatNaNOp _ -> FloatNaNOpGen.GEN;
+ case JitFloatNegOp _ -> FloatNegOpGen.GEN;
+ case JitFloatNotEqualOp _ -> FloatNotEqualOpGen.GEN;
+ case JitFloatRoundOp _ -> FloatRoundOpGen.GEN;
+ case JitFloatSqrtOp _ -> FloatSqrtOpGen.GEN;
+ case JitFloatSubOp _ -> FloatSubOpGen.GEN;
+ case JitFloatTruncOp _ -> FloatTruncOpGen.GEN;
+ case JitInt2CompOp _ -> Int2CompOpGen.GEN;
+ case JitIntAddOp _ -> IntAddOpGen.GEN;
+ case JitIntAndOp _ -> IntAndOpGen.GEN;
+ case JitIntCarryOp _ -> IntCarryOpGen.GEN;
+ case JitIntDivOp _ -> IntDivOpGen.GEN;
+ case JitIntEqualOp _ -> IntEqualOpGen.GEN;
+ case JitIntNegateOp _ -> IntNegateOpGen.GEN;
+ case JitIntLeftOp _ -> IntLeftOpGen.GEN;
+ case JitIntLessEqualOp _ -> IntLessEqualOpGen.GEN;
+ case JitIntLessOp _ -> IntLessOpGen.GEN;
+ case JitIntMultOp _ -> IntMultOpGen.GEN;
+ case JitIntNotEqualOp _ -> IntNotEqualOpGen.GEN;
+ case JitIntOrOp _ -> IntOrOpGen.GEN;
+ case JitIntRemOp _ -> IntRemOpGen.GEN;
+ case JitIntRightOp _ -> IntRightOpGen.GEN;
+ case JitIntSBorrowOp _ -> IntSBorrowOpGen.GEN;
+ case JitIntSCarryOp _ -> IntSCarryOpGen.GEN;
+ case JitIntSExtOp _ -> IntSExtOpGen.GEN;
+ case JitIntSLessEqualOp _ -> IntSLessEqualOpGen.GEN;
+ case JitIntSLessOp _ -> IntSLessOpGen.GEN;
+ case JitIntSDivOp _ -> IntSDivOpGen.GEN;
+ case JitIntSRemOp _ -> IntSRemOpGen.GEN;
+ case JitIntSRightOp _ -> IntSRightOpGen.GEN;
+ case JitIntSubOp _ -> IntSubOpGen.GEN;
+ case JitIntXorOp _ -> IntXorOpGen.GEN;
+ case JitIntZExtOp _ -> IntZExtOpGen.GEN;
+ case JitLoadOp _ -> LoadOpGen.GEN;
+ case JitLzCountOp _ -> LzCountOpGen.GEN;
+ case JitPhiOp _ -> PhiOpGen.GEN;
+ case JitPopCountOp _ -> PopCountOpGen.GEN;
+ case JitNopOp _ -> NopOpGen.GEN;
+ case JitStoreOp _ -> StoreOpGen.GEN;
+ case JitSubPieceOp _ -> SubPieceOpGen.GEN;
+ case JitSynthSubPieceOp _ -> SynthSubPieceOpGen.GEN;
+ case JitUnimplementedOp _ -> UnimplementedOpGen.GEN;
default -> throw new AssertionError("Unrecognized op: " + op);
};
}
@@ -587,7 +585,7 @@ public interface OpGen<T extends JitOp> {
*/
static <N extends Next> Emitter<N> generateSyserrInts(Emitter<N> em, Opnd<MpIntJitType> opnd) {
List<SimpleOpnd<TInt, IntJitType>> legs = opnd.type().castLegsLE(opnd);
- String fmt = legs.stream().map(l -> "%08x").collect(Collectors.joining(":"));
+ String fmt = legs.stream().map(_ -> "%08x").collect(Collectors.joining(":"));
var emArr = em
.emit(Op::getstatic, T_SYSTEM, "err", T_PRINT_STREAM)
.emit(Op::ldc__a, fmt)
@@ -621,6 +619,12 @@ public interface OpGen<T extends JitOp> {
* The result of emitting code for a p-code op
*/
sealed interface OpResult {
+ /**
+ * {@return the emitter with unknown stack}
+ * <p>
+ * Switch on the actual type to ascertain the stack's actual contents.
+ */
+ Emitter<?> em();
}
/**
@@ -638,22 +642,19 @@ public interface OpGen<T extends JitOp> {
record DeadOpResult(Emitter<Dead> em) implements OpResult {}
/**
- * Emit bytecode into the {@link JitCompiledPassage#run(int) run} method.
- *
+ * Emit bytecode into the {@link JitCompiledPassage#run run} method.
* <p>
* This method must emit the code needed to load any input operands, convert them to the
* appropriate type, perform the actual operation, and then if applicable, store the output
- * operand. The implementations should delegate to
- * {@link JitCodeGenerator#genReadToStack(Emitter, Local, JitVal, ghidra.pcode.emu.jit.analysis.JitType.SimpleJitType, Ext)},
- * {@link JitCodeGenerator#genWriteFromStack(Emitter, Local, JitVar, ghidra.pcode.emu.jit.analysis.JitType.SimpleJitType, Ext, Scope)}
- * or similar for mp-int types.
+ * operand. The implementations should delegate to {@link JitCodeGenerator#genReadToStack},
+ * {@link JitCodeGenerator#genWriteFromStack} or similar for mp-int types.
*
* @param <THIS> the type of the generated passage
* @param em the emitter typed with the empty stack
* @param localThis a handle to the local holding the {@code this} reference
* @param localCtxmod a handle to the local holding {@code ctxmod}
- * @param retReq an indication of what must be returned by this
- * {@link JitCompiledPassage#run(int)} method.
+ * @param retReq an indication of what must be returned by this {@link JitCompiledPassage#run}
+ * method.
* @param gen the code generator
* @param op the p-code op (use-def node) to translate
* @param block the basic block containing the p-code op
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/opnd/Opnd.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/opnd/Opnd.java
index 9cc2b59211..544220a66a 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/opnd/Opnd.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/opnd/Opnd.java
@@ -68,9 +68,7 @@ public interface Opnd<T extends JitType> {
* @param <TT> the "to" JVM type
* @param <TJT> the "to" p-code type
*/
- interface StackToStackConv<
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>> {
+ interface StackToStackConv<FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>> {
/**
* Convert a stack operand to another stack operand
@@ -83,8 +81,8 @@ public interface Opnd<T extends JitType> {
* @param ext the kind of extension to apply
* @return the emitter with ..., result
*/
- <N1 extends Next, N0 extends Ent<N1, FT>> Emitter<Ent<N1, TT>>
- convertStackToStack(Emitter<N0> em, FJT from, TJT to, Ext ext);
+ <N1 extends Next, N0 extends Ent<N1, FT>> Emitter<Ent<N1, TT>> convertStackToStack(
+ Emitter<N0> em, FJT from, TJT to, Ext ext);
}
/**
@@ -96,10 +94,7 @@ public interface Opnd<T extends JitType> {
* @param <TLT> the "to" p-code type for each mp leg
* @param <TJT> the "to" p-code type
*/
- interface StackToMpConv<
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>,
- TJT extends LeggedJitType<TT, TLT>> {
+ interface StackToMpConv<FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>, TJT extends LeggedJitType<TT, TLT>> {
/**
* Convert a stack operand to an mp operand in locals
@@ -144,10 +139,7 @@ public interface Opnd<T extends JitType> {
* @param <TT> the "to" JVM type
* @param <TJT> the "to" p-code type
*/
- interface MpToStackConv<
- FT extends BPrim<?>, FLT extends SimpleJitType<FT, FLT>,
- FJT extends LeggedJitType<FT, FLT>,
- TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>> {
+ interface MpToStackConv<FT extends BPrim<?>, FLT extends SimpleJitType<FT, FLT>, FJT extends LeggedJitType<FT, FLT>, TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>> {
/**
* Convert an mp operand in locals to a stack operand
@@ -173,8 +165,8 @@ public interface Opnd<T extends JitType> {
* @param ext the kind of extension to apply
* @return the emitter with ..., result
*/
- <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TT>>
- convertArrayToStack(Emitter<N0> em, FJT from, TJT to, Ext ext);
+ <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TT>> convertArrayToStack(
+ Emitter<N0> em, FJT from, TJT to, Ext ext);
}
/**
@@ -187,11 +179,7 @@ public interface Opnd<T extends JitType> {
* @param <TLT> the "to" p-code type for each mp leg
* @param <TJT> the "to" p-code type
*/
- interface MpToMpConv<
- FT extends BPrim<?>, FLT extends SimpleJitType<FT, FLT>,
- FJT extends LeggedJitType<FT, FLT>,
- TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>,
- TJT extends LeggedJitType<TT, TLT>> {
+ interface MpToMpConv<FT extends BPrim<?>, FLT extends SimpleJitType<FT, FLT>, FJT extends LeggedJitType<FT, FLT>, TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>, TJT extends LeggedJitType<TT, TLT>> {
/**
* Convert an operand in locals to another in locals
@@ -258,11 +246,8 @@ public interface Opnd<T extends JitType> {
* @param ext the kind of extension to apply
* @return the emitter with ..., result
*/
- static <
- N2 extends Next,
- N1 extends Ent<N2, TLong>,
- N0 extends Ent<N1, TInt>>
- Emitter<Ent<N2, TLong>> lextshr(Emitter<N0> em, Ext ext) {
+ static <N2 extends Next, N1 extends Ent<N2, TLong>, N0 extends Ent<N1, TInt>> Emitter<Ent<N2, TLong>> lextshr(
+ Emitter<N0> em, Ext ext) {
return switch (ext) {
case ZERO -> em.emit(Op::lushr);
case SIGN -> em.emit(Op::lshr);
@@ -276,8 +261,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>>
- convertStackToStack(Emitter<N0> em, IntJitType from, IntJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>> convertStackToStack(
+ Emitter<N0> em, IntJitType from, IntJitType to, Ext ext) {
if (!needsIntExt(from, to)) {
return em.emit(Misc::cast1);
}
@@ -308,8 +293,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TLong>>
- convertStackToStack(Emitter<N0> em, IntJitType from, LongJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TLong>> convertStackToStack(
+ Emitter<N0> em, IntJitType from, LongJitType to, Ext ext) {
return switch (ext) {
case ZERO -> em
.emit(Op::invokestatic, GenConsts.TR_INTEGER, "toUnsignedLong",
@@ -358,9 +343,9 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> OpndEm<MpIntJitType, N1>
- convertStackToOpnd(Emitter<N0> em, IntJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> OpndEm<MpIntJitType, N1> convertStackToOpnd(
+ Emitter<N0> em, IntJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope) {
IntJitType typeLsl = to.legTypesLE().get(0);
var lsl = em
.emit(IntToInt.INSTANCE::convertStackToStack, from, typeLsl, ext)
@@ -370,9 +355,9 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TRef<int[]>>>
- convertStackToArray(Emitter<N0> em, IntJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope, int slack) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TRef<int[]>>> convertStackToArray(
+ Emitter<N0> em, IntJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope, int slack) {
int legCount = to.legsAlloc();
Local<TRef<int[]>> arr = scope.decl(Types.T_INT_ARR, "%s_convArr".formatted(name));
try (SubScope ss = scope.sub()) {
@@ -420,8 +405,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TFloat>>
- convertStackToStack(Emitter<N0> em, IntJitType from, FloatJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TFloat>> convertStackToStack(
+ Emitter<N0> em, IntJitType from, FloatJitType to, Ext ext) {
return em
.emit(Op::invokestatic, GenConsts.TR_FLOAT, "intBitsToFloat",
GenConsts.MDESC_FLOAT__INT_BITS_TO_FLOAT, false)
@@ -437,8 +422,8 @@ public interface Opnd<T extends JitType> {
INSTANCE; // In theory, should never happen, but if it does, truncate.
@Override
- public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TDouble>>
- convertStackToStack(Emitter<N0> em, IntJitType from, DoubleJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TDouble>> convertStackToStack(
+ Emitter<N0> em, IntJitType from, DoubleJitType to, Ext ext) {
return em
.emit(IntToLong.INSTANCE::convertStackToStack, from, LongJitType.I8, ext)
.emit(LongToDouble.INSTANCE::convertStackToStack, LongJitType.I8, to, ext);
@@ -452,8 +437,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TInt>>
- convertStackToStack(Emitter<N0> em, LongJitType from, IntJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TInt>> convertStackToStack(
+ Emitter<N0> em, LongJitType from, IntJitType to, Ext ext) {
return em
.emit(Op::l2i)
.emit(IntToInt.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -467,8 +452,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TLong>>
- convertStackToStack(Emitter<N0> em, LongJitType from, LongJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TLong>> convertStackToStack(
+ Emitter<N0> em, LongJitType from, LongJitType to, Ext ext) {
if (!needsLongExt(from, to)) {
return em.emit(Misc::cast1);
}
@@ -493,9 +478,9 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> OpndEm<MpIntJitType, N1>
- convertStackToOpnd(Emitter<N0> em, LongJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> OpndEm<MpIntJitType, N1> convertStackToOpnd(
+ Emitter<N0> em, LongJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope) {
var upperOnStack = em
.emit(Op::dup2__2)
.emit(Op::ldc__i, Integer.SIZE)
@@ -533,9 +518,9 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TRef<int[]>>>
- convertStackToArray(Emitter<N0> em, LongJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope, int slack) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TRef<int[]>>> convertStackToArray(
+ Emitter<N0> em, LongJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope, int slack) {
int legCount = to.legsAlloc();
Local<TRef<int[]>> arr = scope.decl(Types.T_INT_ARR, "%s_convArr".formatted(name));
try (SubScope ss = scope.sub()) {
@@ -598,8 +583,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TFloat>>
- convertStackToStack(Emitter<N0> em, LongJitType from, FloatJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TFloat>> convertStackToStack(
+ Emitter<N0> em, LongJitType from, FloatJitType to, Ext ext) {
return em
.emit(LongToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToFloat.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -613,8 +598,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TDouble>>
- convertStackToStack(Emitter<N0> em, LongJitType from, DoubleJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TLong>> Emitter<Ent<N1, TDouble>> convertStackToStack(
+ Emitter<N0> em, LongJitType from, DoubleJitType to, Ext ext) {
if (to.size() != from.size()) {
throw new AssertionError("Size mismatch");
}
@@ -642,8 +627,8 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TInt>>
- convertArrayToStack(Emitter<N0> em, MpIntJitType from, IntJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TInt>> convertArrayToStack(
+ Emitter<N0> em, MpIntJitType from, IntJitType to, Ext ext) {
var typeLsl = from.legTypesLE().get(0);
return em
.emit(Op::ldc__i, 0)
@@ -675,8 +660,8 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TLong>>
- convertArrayToStack(Emitter<N0> em, MpIntJitType from, LongJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TLong>> convertArrayToStack(
+ Emitter<N0> em, MpIntJitType from, LongJitType to, Ext ext) {
return em
.emit(Op::dup)
.emit(Op::ldc__i, 1)
@@ -850,8 +835,8 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TFloat>>
- convertArrayToStack(Emitter<N0> em, MpIntJitType from, FloatJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TFloat>> convertArrayToStack(
+ Emitter<N0> em, MpIntJitType from, FloatJitType to, Ext ext) {
return em
.emit(MpIntToInt.INSTANCE::convertArrayToStack, from, IntJitType.I4, ext)
.emit(IntToFloat.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -874,8 +859,8 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TDouble>>
- convertArrayToStack(Emitter<N0> em, MpIntJitType from, DoubleJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TRef<int[]>>> Emitter<Ent<N1, TDouble>> convertArrayToStack(
+ Emitter<N0> em, MpIntJitType from, DoubleJitType to, Ext ext) {
return em
.emit(MpIntToLong.INSTANCE::convertArrayToStack, from, LongJitType.I8, ext)
.emit(LongToDouble.INSTANCE::convertStackToStack, LongJitType.I8, to, ext);
@@ -889,8 +874,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TInt>>
- convertStackToStack(Emitter<N0> em, FloatJitType from, IntJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TInt>> convertStackToStack(
+ Emitter<N0> em, FloatJitType from, IntJitType to, Ext ext) {
if (to.size() != from.size()) {
throw new AssertionError("Size mismatch");
}
@@ -909,8 +894,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TLong>>
- convertStackToStack(Emitter<N0> em, FloatJitType from, LongJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TLong>> convertStackToStack(
+ Emitter<N0> em, FloatJitType from, LongJitType to, Ext ext) {
return em
.emit(FloatToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToLong.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -925,9 +910,9 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> OpndEm<MpIntJitType, N1>
- convertStackToOpnd(Emitter<N0> em, FloatJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> OpndEm<MpIntJitType, N1> convertStackToOpnd(
+ Emitter<N0> em, FloatJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope) {
return em
.emit(FloatToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToMpInt.INSTANCE::convertStackToOpnd, IntJitType.I4, name, to, ext,
@@ -935,9 +920,9 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TRef<int[]>>>
- convertStackToArray(Emitter<N0> em, FloatJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope, int slack) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TRef<int[]>>> convertStackToArray(
+ Emitter<N0> em, FloatJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope, int slack) {
return em
.emit(FloatToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToMpInt.INSTANCE::convertStackToArray, IntJitType.I4, name, to, ext,
@@ -952,8 +937,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TFloat>>
- convertStackToStack(Emitter<N0> em, FloatJitType from, FloatJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TFloat>> convertStackToStack(
+ Emitter<N0> em, FloatJitType from, FloatJitType to, Ext ext) {
return em.emit(Misc::cast1);
}
}
@@ -965,8 +950,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TDouble>>
- convertStackToStack(Emitter<N0> em, FloatJitType from, DoubleJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TFloat>> Emitter<Ent<N1, TDouble>> convertStackToStack(
+ Emitter<N0> em, FloatJitType from, DoubleJitType to, Ext ext) {
return em
.emit(FloatToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToDouble.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -980,8 +965,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TInt>>
- convertStackToStack(Emitter<N0> em, DoubleJitType from, IntJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TInt>> convertStackToStack(
+ Emitter<N0> em, DoubleJitType from, IntJitType to, Ext ext) {
return em
.emit(DoubleToLong.INSTANCE::convertStackToStack, from, LongJitType.I8, ext)
.emit(LongToInt.INSTANCE::convertStackToStack, LongJitType.I8, to, ext);
@@ -995,8 +980,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TLong>>
- convertStackToStack(Emitter<N0> em, DoubleJitType from, LongJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TLong>> convertStackToStack(
+ Emitter<N0> em, DoubleJitType from, LongJitType to, Ext ext) {
if (to.size() != from.size()) {
throw new AssertionError("Size mismatch");
}
@@ -1016,9 +1001,9 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> OpndEm<MpIntJitType, N1>
- convertStackToOpnd(Emitter<N0> em, DoubleJitType from, String name, MpIntJitType to,
- Ext ext, Scope scope) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> OpndEm<MpIntJitType, N1> convertStackToOpnd(
+ Emitter<N0> em, DoubleJitType from, String name, MpIntJitType to,
+ Ext ext, Scope scope) {
return em
.emit(DoubleToLong.INSTANCE::convertStackToStack, from, LongJitType.I8, ext)
.emit(LongToMpInt.INSTANCE::convertStackToOpnd, LongJitType.I8, name, to, ext,
@@ -1026,9 +1011,9 @@ public interface Opnd<T extends JitType> {
}
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TRef<int[]>>>
- convertStackToArray(Emitter<N0> em, DoubleJitType from, String name,
- MpIntJitType to, Ext ext, Scope scope, int slack) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TRef<int[]>>> convertStackToArray(
+ Emitter<N0> em, DoubleJitType from, String name,
+ MpIntJitType to, Ext ext, Scope scope, int slack) {
return em
.emit(DoubleToLong.INSTANCE::convertStackToStack, from, LongJitType.I8, ext)
.emit(LongToMpInt.INSTANCE::convertStackToArray, LongJitType.I8, name, to, ext,
@@ -1043,8 +1028,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TFloat>>
- convertStackToStack(Emitter<N0> em, DoubleJitType from, FloatJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TFloat>> convertStackToStack(
+ Emitter<N0> em, DoubleJitType from, FloatJitType to, Ext ext) {
return em
.emit(DoubleToInt.INSTANCE::convertStackToStack, from, IntJitType.I4, ext)
.emit(IntToFloat.INSTANCE::convertStackToStack, IntJitType.I4, to, ext);
@@ -1059,8 +1044,8 @@ public interface Opnd<T extends JitType> {
INSTANCE;
@Override
- public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TDouble>>
- convertStackToStack(Emitter<N0> em, DoubleJitType from, DoubleJitType to, Ext ext) {
+ public <N1 extends Next, N0 extends Ent<N1, TDouble>> Emitter<Ent<N1, TDouble>> convertStackToStack(
+ Emitter<N0> em, DoubleJitType from, DoubleJitType to, Ext ext) {
return em.emit(Misc::cast1);
}
}
@@ -1169,11 +1154,8 @@ public interface Opnd<T extends JitType> {
* @return the emitter with ..., value (unchanged)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- public static <
- TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>,
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- N1 extends Next, N0 extends Ent<N1, FT>>
- Emitter<Ent<N1, TT>> castStack1(Emitter<N0> em, FJT from, TJT to) {
+ public static <TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>, FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, N1 extends Next, N0 extends Ent<N1, FT>> Emitter<Ent<N1, TT>> castStack1(
+ Emitter<N0> em, FJT from, TJT to) {
assert from == to;
return (Emitter) em;
}
@@ -1191,10 +1173,8 @@ public interface Opnd<T extends JitType> {
* @param scope a scope for the local variable
* @return the operand and emitter with ...
*/
- public static <
- T extends BPrim<?>, JT extends SimpleJitType<T, JT>,
- N1 extends Next, N0 extends Ent<N1, T>>
- SimpleOpndEm<T, JT, N1> create(Emitter<N0> em, JT type, String name, Scope scope) {
+ public static <T extends BPrim<?>, JT extends SimpleJitType<T, JT>, N1 extends Next, N0 extends Ent<N1, T>> SimpleOpndEm<T, JT, N1> create(
+ Emitter<N0> em, JT type, String name, Scope scope) {
return switch (type) {
case IntJitType t -> IntLocalOpnd.create(castStack1(em, type, t), t, name, scope)
.castBack(type);
@@ -1219,8 +1199,8 @@ public interface Opnd<T extends JitType> {
* @param scope a scope for the local variable
* @return the operand and emitter with ...
*/
- public static <N1 extends Next, N0 extends Ent<N1, TInt>> SimpleOpndEm<TInt, IntJitType, N1>
- createInt(Emitter<N0> em, IntJitType type, String name, Scope scope) {
+ public static <N1 extends Next, N0 extends Ent<N1, TInt>> SimpleOpndEm<TInt, IntJitType, N1> createInt(
+ Emitter<N0> em, IntJitType type, String name, Scope scope) {
return IntLocalOpnd.create(em, type, name, scope);
}
@@ -1236,8 +1216,8 @@ public interface Opnd<T extends JitType> {
* @return the operand and emitter with ...
* @see SimpleOpnd#ofIntReadOnly(IntJitType, Local)
*/
- public static <N1 extends Next, N0 extends Ent<N1, TInt>> SimpleOpndEm<TInt, IntJitType, N1>
- createIntReadOnly(Emitter<N0> em, IntJitType type, String name, Scope scope) {
+ public static <N1 extends Next, N0 extends Ent<N1, TInt>> SimpleOpndEm<TInt, IntJitType, N1> createIntReadOnly(
+ Emitter<N0> em, IntJitType type, String name, Scope scope) {
return IntReadOnlyLocalOpnd.create(em, type, name, scope);
}
@@ -1253,10 +1233,8 @@ public interface Opnd<T extends JitType> {
* @return the converter
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- static <
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>>
- StackToStackConv<FT, FJT, TT, TJT> getStackToStack(FJT from, TJT to) {
+ static <FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>> StackToStackConv<FT, FJT, TT, TJT> getStackToStack(
+ FJT from, TJT to) {
return (StackToStackConv) switch (from) {
case IntJitType ft -> switch (to) {
case IntJitType tt -> IntToInt.INSTANCE;
@@ -1305,11 +1283,8 @@ public interface Opnd<T extends JitType> {
* @param ext the kind of extension to apply
* @return the emitter with ..., result
*/
- public static <
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>,
- N1 extends Next, N0 extends Ent<N1, FT>>
- Emitter<Ent<N1, TT>> convert(Emitter<N0> em, FJT from, TJT to, Ext ext) {
+ public static <FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TJT extends SimpleJitType<TT, TJT>, N1 extends Next, N0 extends Ent<N1, FT>> Emitter<Ent<N1, TT>> convert(
+ Emitter<N0> em, FJT from, TJT to, Ext ext) {
return getStackToStack(from, to).convertStackToStack(em, from, to, ext);
}
@@ -1324,8 +1299,8 @@ public interface Opnd<T extends JitType> {
* @param ext the kind of extension to apply
* @return the emitter with ..., result
*/
- public static <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>>
- convertIntToInt(Emitter<N0> em, IntJitType from, IntJitType to, Ext ext) {
+ public static <N1 extends Next, N0 extends Ent<N1, TInt>> Emitter<Ent<N1, TInt>> convertIntToInt(
+ Emitter<N0> em, IntJitType from, IntJitType to, Ext ext) {
return IntToInt.INSTANCE.convertStackToStack(em, from, to, ext);
}
@@ -1342,11 +1317,8 @@ public interface Opnd<T extends JitType> {
* @return the converter
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
- static <
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>,
- TJT extends LeggedJitType<TT, TLT>>
- StackToMpConv<FT, FJT, TT, TLT, TJT> getStackToMp(FJT from, TJT to) {
+ static <FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>, TJT extends LeggedJitType<TT, TLT>> StackToMpConv<FT, FJT, TT, TLT, TJT> getStackToMp(
+ FJT from, TJT to) {
return (StackToMpConv) switch (from) {
case IntJitType ft -> switch (to) {
case MpIntJitType tt -> IntToMpInt.INSTANCE;
@@ -1386,13 +1358,8 @@ public interface Opnd<T extends JitType> {
* @param scope a scope for generated variables
* @return the resulting operand and emitter with ...
*/
- public static <
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>,
- TJT extends LeggedJitType<TT, TLT>,
- N1 extends Next, N0 extends Ent<N1, FT>>
- OpndEm<TJT, N1>
- convertToOpnd(Emitter<N0> em, FJT from, String name, TJT to, Ext ext, Scope scope) {
+ public static <FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>, TJT extends LeggedJitType<TT, TLT>, N1 extends Next, N0 extends Ent<N1, FT>> OpndEm<TJT, N1> convertToOpnd(
+ Emitter<N0> em, FJT from, String name, TJT to, Ext ext, Scope scope) {
return getStackToMp(from, to).convertStackToOpnd(em, from, name, to, ext, scope);
}
@@ -1415,13 +1382,9 @@ public interface Opnd<T extends JitType> {
* @param slack the number of extra (more significant) elements to allocate in the array
* @return the emitter with ..., arrayref
*/
- public static <
- FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>,
- TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>,
- TJT extends LeggedJitType<TT, TLT>,
- N1 extends Next, N0 extends Ent<N1, FT>>
- Emitter<Ent<N1, TRef<int[]>>> convertToArray(Emitter<N0> em, FJT from, String name,
- TJT to, Ext ext, Scope scope, int slack) {
+ public static <FT extends BPrim<?>, FJT extends SimpleJitType<FT, FJT>, TT extends BPrim<?>, TLT extends SimpleJitType<TT, TLT>, TJT extends LeggedJitType<TT, TLT>, N1 extends Next, N0 extends Ent<N1, FT>> Emitter<Ent<N1, TRef<int[]>>> convertToArray(
+ Emitter<N0> em, FJT from, String name,
+ TJT to, Ext ext, Scope scope, int slack) {
return getStackToMp(from, to).convertStackToArray(em, from, name, to, ext, scope, slack);
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/tgt/JitCompiledPassage.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/tgt/JitCompiledPassage.java
index 1ed567ab30..3fe917f40f 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/tgt/JitCompiledPassage.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/tgt/JitCompiledPassage.java
@@ -15,13 +15,12 @@
*/
package ghidra.pcode.emu.jit.gen.tgt;
+import java.lang.classfile.CodeBuilder;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
-import org.objectweb.asm.Opcodes;
-
import ghidra.pcode.emu.jit.JitCompiler;
import ghidra.pcode.emu.jit.JitPassage.*;
import ghidra.pcode.emu.jit.JitPcodeThread;
@@ -1176,7 +1175,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_LEFT int_left} on multi-precision ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
@@ -1202,7 +1201,7 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_LEFT int_left} on an mp-int with a JVM long shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
@@ -1222,7 +1221,7 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_LEFT int_left} on an mp-int with a JVM int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
@@ -1242,7 +1241,7 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_LEFT int_left} on a JVM long with an mp-int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1264,7 +1263,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_LEFT int_left} on JVM longs.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1281,7 +1280,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_LEFT int_left} on JVM long with int amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1299,7 +1298,7 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_LEFT int_left} on a JVM int with an mp-int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1321,7 +1320,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_LEFT int_left} on JVM int with long amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1338,7 +1337,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_LEFT int_left} on JVM ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHL ishl}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishl ishl}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val << amt}
@@ -1355,8 +1354,8 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on multi-precision ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
* @param outBytes the actual size in bytes of the output operand
@@ -1381,8 +1380,8 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on an mp-int with a JVM long shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
* @param outBytes the actual size in bytes of the output operand
@@ -1401,8 +1400,8 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on an mp-int with a JVM int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param out the array to receive the output, in little-endian order
* @param outBytes the actual size in bytes of the output operand
@@ -1421,8 +1420,8 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on a JVM long with an mp-int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}, in little-endian order
@@ -1443,8 +1442,8 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on JVM longs.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}
@@ -1460,8 +1459,8 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on JVM long with int amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}
@@ -1478,8 +1477,8 @@ public interface JitCompiledPassage {
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on a JVM int with an mp-int shift
* amount.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}, in little-endian order
@@ -1500,8 +1499,8 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on JVM int with long amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}
@@ -1517,8 +1516,8 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_right} on JVM ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#IUSHR iushr}: 1) The
- * amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#iushr iushr}: 1)
+ * The amount must be treated as unsigned. 2) Shifts in excess of val's size clear the register.
*
* @param val the value as in {@code val >> amt}
* @param amt the amt as in {@code val >> amt}
@@ -1534,7 +1533,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_RIGHT int_sright} on multi-precision ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHR ishr}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishr ishr}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size fill the register with
* the sign bit.
*
@@ -1561,7 +1560,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_SRIGHT int_sright} on JVM longs.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHR ishr}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishr ishr}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size fill the register with
* the sign bit.
*
@@ -1579,7 +1578,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_SRIGHT int_sright} on JVM long with int amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHR ishr}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishr ishr}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size fill the register with
* the sign bit.
*
@@ -1597,7 +1596,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_SRIGHT int_sright} on JVM int with long amt.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHR ishr}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishr ishr}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size fill the register with
* the sign bit.
*
@@ -1615,7 +1614,7 @@ public interface JitCompiledPassage {
/**
* The implementation of {@link PcodeOp#INT_SRIGHT int_sright} on JVM ints.
* <p>
- * The semantics here are subtly different than the JVM's {@link Opcodes#ISHR ishr}: 1) The
+ * The semantics here are subtly different than the JVM's {@link CodeBuilder#ishr ishr}: 1) The
* amount must be treated as unsigned. 2) Shifts in excess of val's size fill the register with
* the sign bit.
*
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Emitter.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Emitter.java
index bc46359b81..09cc6c5ab2 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Emitter.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Emitter.java
@@ -16,12 +16,12 @@
package ghidra.pcode.emu.jit.gen.util;
import java.lang.System.Logger;
+import java.lang.classfile.ClassBuilder;
+import java.lang.classfile.CodeBuilder;
import java.util.ArrayList;
import java.util.function.BiFunction;
import java.util.function.Function;
-import org.objectweb.asm.*;
-
import ghidra.pcode.emu.jit.gen.util.Methods.*;
import ghidra.pcode.emu.jit.gen.util.Types.*;
@@ -31,21 +31,8 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
* This is either genius or a sign of some deep pathology. On one hand it allows the type-safe
* generation of bytecode in Java classfiles. On the other, it requires an often onerous type
* signature on any method of appreciable sophistication that uses it. The justification for this
- * utility library stems from our difficulties with error reporting in the ASM library. We certainly
- * appreciate the effort that has gone into that library, and must recognize its success in that it
- * has been used by the OpenJDK itself and eventually prompted them to devise an official classfile
- * API. Nevertheless, its analyses (e.g., max-stack computation) fail with inscrutable messages.
- * Admittedly, this only happens when we have generated invalid bytecode. For example, popping too
- * many items off the stack usually results in an {@link ArrayIndexOutOfBoundsException} instead of,
- * "Hey, you can't pop that here: [offset]". Similarly, if you push a long and then pop an int, you
- * typically get a {@link NullPointerException}. Unfortunately, these errors do not occur with the
- * offending {@code visitXInstruction()} call on the stack, but instead during
- * {@link MethodVisitor#visitMaxs(int, int)}, and so we could not easily debug and identify the
- * cause. We did find some ways to place breakpoints and at least derive the bytecode offset. We
- * then used additional dumps and instrumentation to map that back to our source that generated the
- * offending instruction. This has been an extremely onerous process. Additionally, when refactoring
- * bytecode generation, we are left with little if any assistance from the compiler or IDE. These
- * utilities seek to improve the situation.
+ * utility library stems from our difficulties with error reporting in bytecode generation
+ * libraries.
* <p>
* Our goal is to devise a way leverage Java's Generics and its type checker to enforce stack
* consistency of generated JVM bytecode. We want the Java compiler to reject code that tries, for
@@ -71,7 +58,7 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
* <p>
* This presents a different problem. We'd like to provide a syntax where the ops appear in the
* order they are emitted. Usually, we'd chain instance methods, like such:
- *
+ *
* <pre>
* em
* .ldc(1)
@@ -80,27 +67,27 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
* <p>
* However, we've already ruled out instance methods. Were we to use static methods, we'd get
* something like:
- *
+ *
* <pre>
* Op.pop(Op.ldc(em, 1));
* </pre>
- *
+ *
* <p>
* However, that fails to display the ops in order. We could instead use:
- *
+ *
* <pre>
* var em1 = Op.ldc(em, 1);
* var em2 = Op.pop(em1);
* </pre>
- *
+ * <p>
* However, that requires more syntactic kruft, not to mention the manual bookkeeping to ensure we
- * use the previous {@code em}<em>n</em> at each step. To work around this, we define instance
+ * use the previous <code>em<em>n</em></code> at each step. To work around this, we define instance
* methods, e.g., {@link #emit(Function)}, that can accept references to static methods we provide,
* each representing a JVM bytecode instruction. This allows those static methods to impose a
* required structure on the stack. The static method can then return an emitter with a type
* encoding the new stack contents. (See the {@link Op} class for examples.) Thus, we have a syntax
* like:
- *
+ *
* <pre>
* em
* .emit(Op::ldc__i, 1)
@@ -110,92 +97,46 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
* While not ideal, it is succinct, allows method chaining, and displays the ops in order of
* emission. (Note that we use this pattern even for pure pushes, where restricting {@code <N>} is
* not necessary, just for syntactic consistency.) There are some rubs for operators that have
- * different forms, e.g., {@link Op#ldc__i(Emitter, int)}, but as a matter of opinion, having to
- * specify the intended form here is a benefit. The meat of this class is just the specification of
- * the many arities of {@code emit}. It also includes some utilities for declaring local variables,
- * and the entry points for generating and defining methods.
+ * different forms, e.g., {@link Op#ldc__i}, but as a matter of opinion, having to specify the
+ * intended form here is a benefit. The meat of this class is just the specification of the many
+ * arities of {@link #emit}. It also includes some utilities for declaring local variables, and the
+ * entry points for generating and defining methods.
* <p>
* To give an overall taste of using this utility library, here is an example for dynamically
* generating a class that implements an interface. Note that the interface is <em>not</em>
* dynamically generated. This is a common pattern as it allows the generated method to be invoked
* without reflection.
*
- * <pre>
- * interface MyIf {
- * int myMethod(int a, String b);
- * }
+ * {@snippet class = ghidra.pcode.emu.jit.gen.util.MyMethodExample region = MyIf}
*
- * &lt;THIS extends MyIf&gt; void doGenerate(ClassVisitor cv) {
- * var mdescMyMethod = MthDesc.derive(MyIf::myMethod)
- * .check(MthDesc::returns, Types.T_INT)
- * .check(MthDesc::param, Types.T_INT)
- * .check(MthDesc::param, Types.refOf(String.class))
- * .check(MthDesc::build);
- * TRef&lt;THIS&gt; typeThis = Types.refExtends(MyIf.class, "Lmy.pkg.ImplMyIf;");
- * var paramsMyMethod = new Object() {
- * Local&lt;TRef&lt;THIS&gt;&gt; this_;
- * Local&lt;TInt&gt; a;
- * Local&lt;TRef&lt;String&gt;&gt; b;
- * };
- * var retMyMethod = Emitter.start(typeThis, cv, ACC_PUBLIC, "myMethod", mdescMyMethod)
- * .param(Def::param, Types.refOf(String.class), l -> paramsMyMethod.b = l)
- * .param(Def::param, Types.T_INT, l -> paramsMyMethod.a = l)
- * .param(Def::done, typeThis, l -> paramsMyMethod.this_ = l);
- * retMyMethod.em()
- * .emit(Op::iload, paramsMyMethod.a)
- * .emit(Op::ldc__i, 10)
- * .emit(Op::imul)
- * .emit(Op::ireturn, retMyMethod.ret())
- * .emit(Misc::finish);
- * }
- * </pre>
- * <p>
- * Yes, there is a bit of repetition; however, this accomplishes all our goals and a little more.
- * Note that the generated bytecode is essentially type checked all the way through to the method
- * definition in the {@code MyIf} interface. Here is the key: <em>We were to change the {@code MyIf}
- * interface, the compiler (and our IDE) would point out the inconsistency.</em> The first such
- * errors would be on {@code mdescMyMethod}. So, we would adjust it to match the new definition. The
- * compiler would then point out issues at {@code retMyMethod} -- assuming the parameters to
- * {@code myMethod} changed, and not just the return type. We would adjust it, along with the
- * contents of {@code paramsMyMethod} to accept the new parameter handles. If the return type of
- * {@code myMethod} changed, then the inferred type of {@code retMyMethod} will change accordingly.
- * <p>
- * Now for the generated bytecode. The {@link Op#iload(Emitter, Local)} requires the given variable
- * handle to have type {@link TInt}, and so if the parameter "{@code a}" changed type, the compiler
- * will point out that the opcode must also change. Similarly, the {@link Op#imul(Emitter)} requires
- * two ints and pushes an int result, so any resulting inconsistency will be caught. Finally, when
- * calling {@link Op#ireturn(Emitter, RetReq)}, two things are checked: 1) there is indeed an int on
- * the stack, and 2) the return type of the method, witnessed by {@code retMyMethod.ret()}, is also
- * an int. There are some occasional wrinkles, but for the most part, once we resolve all the
- * compilation errors, we are assured of type consistency in the generated code, both internally and
- * in its interface to other compiled code.
+ * {@snippet class = ghidra.pcode.emu.jit.gen.util.MyMethodExample region = gen}
*
* @param <N> the contents of the stack after having emitted all the previous bytecodes
*/
public class Emitter<N> {
static final Logger LOGGER = System.getLogger("Emitter");
- /** The wrapped ASM method visitor */
- final MethodVisitor mv;
+ /** The wrapped Class-File API code builder */
+ final CodeBuilder cb;
/** The root scope of local declarations */
final Scope rootScope;
/**
- * Create a new emitter by wrapping the given method visitor.
+ * Create a new emitter by wrapping the given code builder.
* <p>
* Direct use of this constructor is not recommended, but is useful during transition from
* unchecked to checked bytecode generation.
- *
- * @param mv the ASM method visitor
+ *
+ * @param cb the Class-File API code builder
*/
- public Emitter(MethodVisitor mv) {
- this.mv = mv;
+ public Emitter(CodeBuilder cb) {
+ this.cb = cb;
rootScope = new RootScope<>(this, 0);
}
/**
* Stack contents
- *
+ *
* <p>
* There is really only one instance of {@link Next} and that is {@link SingletonEnt#INSTANCE}.
* We just cast it to the various types. Otherwise, these interfaces just exist as a means of
@@ -210,7 +151,7 @@ public class Emitter<N> {
/**
* An entry on the stack
- *
+ *
* @param <N> the tail (portions below) of the stack
* @param <T> the top entry of this stack (or portion)
*/
@@ -234,7 +175,7 @@ public class Emitter<N> {
/**
* Defines the singleton instance of {@link Next}
- *
+ *
* @param <N> the tail
* @param <T> the top entry
*/
@@ -244,7 +185,7 @@ public class Emitter<N> {
/**
* Get the root scope for declaring local variables
- *
+ *
* @return the root scope
*/
public Scope rootScope() {
@@ -255,7 +196,7 @@ public class Emitter<N> {
* Emit a 0-argument operator
* <p>
* This can also be used to invoke generator subroutines whose only argument is the emitter.
- *
+ *
* @param <R> the return type
* @param func the method reference, e.g., {@link Op#pop(Emitter)}.
* @return the value returned by {@code func}
@@ -268,7 +209,7 @@ public class Emitter<N> {
* Emit a 1-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference, e.g., {@link Op#ldc__i(Emitter, int)}.
* @param arg1 the argument (other than the emitter) to pass to {@code func}
@@ -280,7 +221,7 @@ public class Emitter<N> {
/**
* A 3-argument function
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -289,7 +230,7 @@ public class Emitter<N> {
public interface A3Function<A0, A1, A2, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -300,7 +241,7 @@ public class Emitter<N> {
/**
* A 3-argument consumer
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -308,7 +249,7 @@ public class Emitter<N> {
public interface A3Consumer<A0, A1, A2> {
/**
* Invoke the consumer
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -320,7 +261,7 @@ public class Emitter<N> {
* Emit a 2-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -333,7 +274,7 @@ public class Emitter<N> {
/**
* A 4-argument function
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -343,7 +284,7 @@ public class Emitter<N> {
public interface A4Function<A0, A1, A2, A3, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -355,7 +296,7 @@ public class Emitter<N> {
/**
* A 4-argument consumer
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -364,7 +305,7 @@ public class Emitter<N> {
public interface A4Consumer<A0, A1, A2, A3> {
/**
* Invoke the consumer
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -377,7 +318,7 @@ public class Emitter<N> {
* Emit a 3-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -392,7 +333,7 @@ public class Emitter<N> {
/**
* A 5-argument function
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -403,7 +344,7 @@ public class Emitter<N> {
public interface A5Function<A0, A1, A2, A3, A4, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -418,7 +359,7 @@ public class Emitter<N> {
* Emit a 4-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -434,7 +375,7 @@ public class Emitter<N> {
/**
* A 6-argument function
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -446,7 +387,7 @@ public class Emitter<N> {
public interface A6Function<A0, A1, A2, A3, A4, A5, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -462,7 +403,7 @@ public class Emitter<N> {
* Emit a 5-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -480,7 +421,7 @@ public class Emitter<N> {
/**
* A 7-argument function
- *
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -493,7 +434,7 @@ public class Emitter<N> {
public interface A7Function<A0, A1, A2, A3, A4, A5, A6, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -510,7 +451,7 @@ public class Emitter<N> {
* Emit a 6-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -528,8 +469,8 @@ public class Emitter<N> {
}
/**
- * A 7-argument function
- *
+ * A 8-argument function
+ *
* @param <A0> the first argument type
* @param <A1> the next argument type
* @param <A2> the next argument type
@@ -543,7 +484,7 @@ public class Emitter<N> {
public interface A8Function<A0, A1, A2, A3, A4, A5, A6, A7, R> {
/**
* Invoke the function
- *
+ *
* @param arg0 the first argument
* @param arg1 the next argument
* @param arg2 the next argument
@@ -561,7 +502,7 @@ public class Emitter<N> {
* Emit a 7-argument operator
* <p>
* This can also be used to invoke generator subroutines.
- *
+ *
* @param <R> the return type
* @param func the method reference
* @param arg1 an argument (other than the emitter) to pass to {@code func}
@@ -580,69 +521,75 @@ public class Emitter<N> {
}
/**
- * (Not recommended) Wrap the given method visitor with assumed stack contents
+ * (Not recommended) Wrap the given code builder with assumed stack contents
* <p>
- * {@link #start(ClassVisitor, int, String, MthDesc)} or
- * {@link #start(TRef, ClassVisitor, int, String, MthDesc)} is recommended instead.
- *
+ * Use {@link #instanceWithBody} or {@link #staticWithBody} instead.
+ *
* @param <N> the stack contents
- * @param mv the ASM method visitor
+ * @param cb the code builder
* @param assumedStack the assumed stack contents
* @return the emitter
*/
- public static <N extends Next> Emitter<N> assume(MethodVisitor mv, N assumedStack) {
- return new Emitter<>(mv);
+ static <N extends Next> Emitter<N> assume(CodeBuilder cb, N assumedStack) {
+ return new Emitter<>(cb);
}
/**
- * Wrap the given method visitor assuming an empty stack
+ * Wrap the given code builder assuming an empty stack
* <p>
- * {@link #start(ClassVisitor, int, String, MthDesc)} or
- * {@link #start(TRef, ClassVisitor, int, String, MthDesc)} is recommended instead.
- *
- * @param mv the ASM method visitor
+ * Use {@link #instanceWithBody} or {@link #staticWithBody} instead.
+ *
+ * @param cb the code builder
* @return the emitter
*/
- public static Emitter<Bot> start(MethodVisitor mv) {
- mv.visitCode();
- return assume(mv, Next.BOTTOM);
+ static Emitter<Bot> start(CodeBuilder cb) {
+ return assume(cb, Next.BOTTOM);
}
/**
* Define a static method
*
- * @param <MR> the type returned by the method
- * @param <N> the parameter types of the method
- * @param cv the ASM class visitor
- * @param access the access flags (static is added automatically)
+ * @param clb The builder for the class to which this method definition is added.
* @param name the name of the method
- * @param desc the method descriptor
- * @return an object to aid further definition of the method
+ * @param desc the method descriptor (signature)
+ * @param flags the flags (e.g., access modifiers)
+ * @param handler a lambda method to handle specification and code generation
*/
- public static <MR extends BType, N extends Next> Def<MR, N> start(ClassVisitor cv, int access,
- String name, MthDesc<MR, N> desc) {
- access |= Opcodes.ACC_STATIC;
- MethodVisitor mv = cv.visitMethod(access, name, desc.desc(), null, null);
- return new Def<>(start(mv), new ArrayList<>());
+ public static <MR extends BType, N extends Next> void staticWithBody(ClassBuilder clb,
+ String name, MthDesc<MR, N> desc, int flags,
+ Function<StaticMethodBuilder<MR, N>, Emitter<Dead>> handler) {
+ clb.withMethodBody(name, desc.desc(), flags, cb -> {
+ var dead = handler.apply(new StaticMethodBuilder<>(cb, name, desc, flags));
+ Misc.finish(dead);
+ });
+ }
+
+ static <MR extends BType, N extends Next> Def<MR, N> startStatic(CodeBuilder cb,
+ MthDesc<MR, N> desc) {
+ return new Def<>(start(cb), new ArrayList<>());
}
/**
* Define an instance method
*
- * @param <MR> the type returned by the method
- * @param <OT> the type owning the method
- * @param <N> the parameter types of the method
- * @param owner the owner type (as a reference type)
- * @param cv the ASM class visitor
- * @param access the access flags (static is forcibly removed)
+ * @param clb the builder for the class to which this method definition is added.
+ * @param owner the owning type (must be same as that for the builder)
* @param name the name of the method
- * @param desc the method descriptor
- * @return an object to aid further definition of the method
+ * @param desc the method descriptor (signature)
+ * @param flags the flags (e.g., access modifiers)
+ * @param handler a lambda method to handle specification and code generation
*/
- public static <MR extends BType, OT, N extends Next> ObjDef<MR, OT, N> start(TRef<OT> owner,
- ClassVisitor cv, int access, String name, MthDesc<MR, N> desc) {
- access &= ~Opcodes.ACC_STATIC;
- MethodVisitor mv = cv.visitMethod(access, name, desc.desc(), null, null);
- return new ObjDef<>(start(mv), new ArrayList<>());
+ public static <OT, MR extends BType, N extends Next> void instanceWithBody(ClassBuilder clb,
+ TRef<OT> owner, String name, MthDesc<MR, N> desc, int flags,
+ Function<InstanceMethodBuilder<OT, MR, N>, Emitter<Dead>> handler) {
+ clb.withMethodBody(name, desc.desc(), flags, cb -> {
+ var dead = handler.apply(new InstanceMethodBuilder<>(cb, owner, name, desc, flags));
+ Misc.finish(dead);
+ });
+ }
+
+ static <MR extends BType, OT, N extends Next> ObjDef<MR, OT, N> startInstance(
+ TRef<OT> owner, CodeBuilder cb, MthDesc<MR, N> desc) {
+ return new ObjDef<>(start(cb), new ArrayList<>());
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Fld.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Fld.java
index 2a770770a3..f1bcb5fb65 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Fld.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Fld.java
@@ -15,15 +15,17 @@
*/
package ghidra.pcode.emu.jit.gen.util;
+import java.lang.classfile.ClassBuilder;
+import java.lang.classfile.attribute.ConstantValueAttribute;
+import java.lang.classfile.attribute.SignatureAttribute;
+
import org.apache.commons.lang3.reflect.TypeLiteral;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.Type;
import ghidra.pcode.emu.jit.JitJvmTypeUtils;
import ghidra.pcode.emu.jit.gen.util.Types.*;
/**
- * Utilities for declaring fields in an ASM {@link ClassVisitor}
+ * Utilities for declaring fields in a {@link ClassBuilder}
* <p>
* LATER: We do not yet return a "field handle." Ideally, we would and that would be the required
* argument for {@link Op#getfield(Emitter, TRef, String, BNonVoid)} and related ops.
@@ -31,100 +33,114 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
public interface Fld {
/**
* Declare an initialized boolean field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TBool type, String name, boolean init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TBool type, String name, boolean init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of(init ? 1 : 0));
+ });
}
/**
* Declare an initialized byte field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TByte type, String name, byte init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TByte type, String name, byte init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of((int) init));
+ });
}
/**
* Declare an initialized short field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TShort type, String name, short init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TShort type, String name, short init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of((int) init));
+ });
}
/**
* Declare an initialized int field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TInt type, String name, int init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TInt type, String name, int init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of(init));
+ });
}
/**
* Declare an initialized long field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TLong type, String name, long init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TLong type, String name, long init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of(init));
+ });
}
/**
* Declare an initialized float field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TFloat type, String name, float init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TFloat type, String name, float init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of(init));
+ });
}
/**
* Declare an initialized double field
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static void decl(ClassVisitor cv, int flags, TDouble type, String name, double init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static void decl(ClassBuilder clb, int flags, TDouble type, String name, double init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ fb.with(ConstantValueAttribute.of(init));
+ });
}
/**
@@ -133,45 +149,53 @@ public interface Fld {
* Note that only certain types of fields can have initial values specified in this manner. A
* {@link String} is one such type. For other types, the initializer must be provided in a
* generated class initializer (for static fields) or constructor (for instance fields).
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
* @param init the initial value
*/
- static <T> void decl(ClassVisitor cv, int flags, TRef<T> type, String name, T init) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, init);
+ static <T> void decl(ClassBuilder clb, int flags, TRef<T> type, String name, T init) {
+ clb.withField(name, type.classDesc(), fb -> {
+ fb.withFlags(flags);
+ if (init instanceof String s) {
+ fb.with(ConstantValueAttribute.of(s));
+ }
+ });
}
/**
* Declare an uninitialized field of any type
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type
* @param name the name
*/
- static <T> void decl(ClassVisitor cv, int flags, SNonVoid type, String name) {
- cv.visitField(flags, name, type.type().getDescriptor(), null, null);
+ static <T> void decl(ClassBuilder clb, int flags, SNonVoid type, String name) {
+ clb.withField(name, type.classDesc(), flags);
}
/**
* Declare an uninitialized field of any type with a type signature
- *
- * @param cv the class visitor
- * @param flags the flags as in
- * {@link ClassVisitor#visitField(int, String, String, String, Object)}
+ *
+ * @param clb the class builder
+ * @param flags the access flags
* @param type the type with signature
* @param name the name
*/
- static <T> void decl(ClassVisitor cv, int flags, TypeLiteral<T> type, String name) {
+ static <T> void decl(ClassBuilder clb, int flags, TypeLiteral<T> type, String name) {
Class<?> erased = JitJvmTypeUtils.erase(type.value);
String signature = erased == type.value
? null
: JitJvmTypeUtils.typeToSignature(type.value);
- cv.visitField(flags, name, Type.getDescriptor(erased), signature, null);
+ clb.withField(name, erased.describeConstable().orElseThrow(), fb -> {
+ fb.withFlags(flags);
+ if (signature != null) {
+ fb.with(SignatureAttribute.of(
+ fb.constantPool().utf8Entry(signature)));
+ }
+ });
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Lbl.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Lbl.java
index 4503c7051c..ad0617084f 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Lbl.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Lbl.java
@@ -15,7 +15,8 @@
*/
package ghidra.pcode.emu.jit.gen.util;
-import org.objectweb.asm.Label;
+import java.lang.classfile.CodeBuilder;
+import java.lang.classfile.Label;
import ghidra.pcode.emu.jit.JitCompiler.Diag;
import ghidra.pcode.emu.jit.gen.util.Emitter.Dead;
@@ -49,7 +50,7 @@ import ghidra.pcode.emu.jit.gen.util.Methods.RetReq;
* in non-overloaded methods {@link #place(Emitter, Lbl)} and {@link #placeDead(Emitter, Lbl)}.
* <p>
* As an example, we show an {@code if-else} construct:
- *
+ *
* <pre>
* var lblLess = em
* .emit(Op::iload, params.a)
@@ -66,7 +67,7 @@ import ghidra.pcode.emu.jit.gen.util.Methods.RetReq;
* </pre>
* <p>
* This would be equivalent to
- *
+ *
* <pre>
* int myFunc(int a) {
* if (a &lt;= 20) {
@@ -101,10 +102,10 @@ import ghidra.pcode.emu.jit.gen.util.Methods.RetReq;
* we get that wrong, the compiler reports it as inconsistent, anyway. One drawback to using type
* inference is that the label's name does not appear in the jump instruction that targets it. We do
* not currently have a solution to that complaint.
- *
+ *
* @param <N> the stack contents where the label is placed (or must be placed)
* @param id if {@link Diag#DEEP_TRACE} is enabled, a globally-unique 0-up counter, or -1
- * @param label the wrapped ASM label
+ * @param label the wrapped Class-File API label
*/
public record Lbl<N extends Next>(int id, Label label) {
static int nextId = 0; // for diagnostics only
@@ -122,7 +123,7 @@ public record Lbl<N extends Next>(int id, Label label) {
/**
* A tuple providing both a (new) label and a resulting emitter
- *
+ *
* @param <LN> the label's stack contents
* @param <N> the emitter's stack contents, which will be the same as the label's, unless it is
* {@link Dead}.
@@ -134,34 +135,46 @@ public record Lbl<N extends Next>(int id, Label label) {
/**
* Create a fresh label with any expected stack contents
* <p>
- * Using this to forward declare labels requires the user to explicate the expected stack, which
- * may not be ideal, as it may require updating during refactoring. Consider using
- * {@link Lbl#place(Emitter)} instead, which facilitates inference of the stack contents.
- *
+ * The label is allocated from the given code builder.
+ *
+ * @param <N> the expected stack contents
+ * @param cb the code builder (needed to allocate the label)
+ * @return the label
+ */
+ public static <N extends Next> Lbl<N> create(CodeBuilder cb) {
+ return new Lbl<>(cb.newLabel());
+ }
+
+ /**
+ * Create a fresh label with any expected stack contents
+ * <p>
+ * The label is allocated from the given emitter's code builder.
+ *
* @param <N> the expected stack contents
+ * @param em the emitter (needed to allocate the label from its code builder)
* @return the label
*/
- public static <N extends Next> Lbl<N> create() {
- return new Lbl<>(new Label());
+ public static <N extends Next> Lbl<N> create(Emitter<?> em) {
+ return create(em.cb);
}
/**
- * Generate a place a label where execution could already reach
+ * Generate and place a label where execution could already reach
* <p>
* The returned label's stack will match this emitter's stack, since the code could be reached
* by multiple paths, likely fall-through and a jump to the returned label.
- *
+ *
* @param <N> the emitter's and the label's stack, i.e., as where the returned label is
* referenced
* @param em the emitter
* @return the label and emitter
*/
public static <N extends Next> LblEm<N, N> place(Emitter<N> em) {
- Lbl<N> lbl = create();
+ Lbl<N> lbl = create(em);
if (Op.DEEP_TRACE) {
System.err.println(" jvm<%s>".formatted(lbl));
}
- em.mv.visitLabel(lbl.label);
+ em.cb.labelBinding(lbl.label);
return new LblEm<>(lbl, em);
}
@@ -170,7 +183,7 @@ public record Lbl<N extends Next>(int id, Label label) {
* <p>
* The emitter's stack and the label's stack must agree, since the code is reachable by multiple
* paths, likely fallthrough and a jump to the given label.
- *
+ *
* @param <N> the emitter's and the label's stack, i.e., as where the given label is referenced
* @param em the emitter
* @param lbl the label to place
@@ -180,7 +193,7 @@ public record Lbl<N extends Next>(int id, Label label) {
if (Op.DEEP_TRACE) {
System.err.println(" jvm<%s>".formatted(lbl));
}
- em.mv.visitLabel(lbl.label);
+ em.cb.labelBinding(lbl.label);
return em;
}
@@ -193,7 +206,7 @@ public record Lbl<N extends Next>(int id, Label label) {
* the label has not yet been referenced, it must be forward declared with the expected stack.
* There is no equivalent of {@link #place(Emitter)} for a dead emitter, because there is no way
* to know the resulting stack.
- *
+ *
* @param <N> the stack where the given label is referenced
* @param em the emitter for otherwise-unreachable code
* @param lbl the label to place
@@ -204,7 +217,7 @@ public record Lbl<N extends Next>(int id, Label label) {
if (Op.DEEP_TRACE) {
System.err.println(" jvm<%s>".formatted(lbl));
}
- em.mv.visitLabel(lbl.label);
+ em.cb.labelBinding(lbl.label);
return (Emitter) em;
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Local.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Local.java
index 16bb97e49a..28acd6f100 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Local.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Local.java
@@ -17,8 +17,6 @@ package ghidra.pcode.emu.jit.gen.util;
import java.util.function.Consumer;
-import org.objectweb.asm.MethodVisitor;
-
import ghidra.pcode.emu.jit.gen.util.Methods.Def;
import ghidra.pcode.emu.jit.gen.util.Methods.Def.ParamFunction;
import ghidra.pcode.emu.jit.gen.util.Methods.ObjDef;
@@ -36,7 +34,7 @@ import ghidra.pcode.emu.jit.gen.util.Types.*;
* {@link Def#param(ParamFunction, BNonVoid, String, Consumer)}, and
* {@link Def#done(ObjDef, TRef, Consumer)}. For the most part, the user need not worry at all about
* indices, only types.
- *
+ *
* @param <T> the (machine) type of the variable.
* @param type the type
* @param name the name
@@ -48,7 +46,7 @@ public record Local<T extends BNonVoid>(T type, String name, int index) {
* Construct a local variable handle
* <p>
* Direct use of this method is not recommended. It may be made private later.
- *
+ *
* @param <T> the type of the variable
* @param type the type
* @param name the name
@@ -61,18 +59,17 @@ public record Local<T extends BNonVoid>(T type, String name, int index) {
/**
* Declare a given local variable
- *
+ *
* @param <N> the stack contents of the emitter
- * @param em the emitter (Nothing is actually emitted, but we need the wrapped ASM
- * {@link MethodVisitor}.)
+ * @param em the emitter (needed to access the code builder for local variable declaration)
* @param local the handle to the local
* @param start the start of the scope
* @param end the end of the scope
* @return the same emitter
*/
static <N> Emitter<N> decl(Emitter<N> em, Local<?> local, Lbl<?> start, Lbl<?> end) {
- em.mv.visitLocalVariable(local.name, local.type.type().getDescriptor(), null,
- start.label(), end.label(), local.index);
+ em.cb.localVariable(local.index, local.name, local.type.classDesc(),
+ start.label(), end.label());
return em;
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Methods.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Methods.java
index cf074e22cb..04398a3bb9 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Methods.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Methods.java
@@ -15,14 +15,15 @@
*/
package ghidra.pcode.emu.jit.gen.util;
+import java.lang.classfile.CodeBuilder;
+import java.lang.constant.ClassDesc;
+import java.lang.constant.MethodTypeDesc;
+import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.function.*;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Type;
-
import ghidra.pcode.emu.jit.gen.util.Emitter.*;
import ghidra.pcode.emu.jit.gen.util.Methods.Def.ParamFunction;
import ghidra.pcode.emu.jit.gen.util.Methods.Def.ThisFunction;
@@ -94,10 +95,9 @@ public interface Methods {
* @param <MR> the (machine) type returned by the method
* @param <N> the parameter types encoded as in {@link Emitter} where the top corresponds to the
* right-most parameter.
- * @param desc the descriptor as a string, as in
- * {@link MethodVisitor#visitMethodInsn(int, String, String, String, boolean)}.
+ * @param desc the method type descriptor
*/
- public record MthDesc<MR extends BType, N extends Next>(String desc) {
+ public record MthDesc<MR extends BType, N extends Next>(MethodTypeDesc desc) {
/**
* Begin building a method descriptor that returns the given (machine) type
@@ -107,7 +107,7 @@ public interface Methods {
* @return the builder
*/
public static <MR extends BType> MthDescBuilder<MR, Bot> returns(MR retType) {
- return new MthDescBuilder<>(retType.type());
+ return new MthDescBuilder<>(retType.classDesc());
}
/**
@@ -117,7 +117,7 @@ public interface Methods {
* @return the builder
*/
public static MthDescBuilder<TInt, Bot> returns(SType retType) {
- return new MthDescBuilder<>(retType.type());
+ return new MthDescBuilder<>(retType.classDesc());
}
/**
@@ -130,7 +130,9 @@ public interface Methods {
* @return the untyped descriptor
*/
public static MthDesc<?, ?> reflect(Method method) {
- return new MthDesc<>(Type.getMethodDescriptor(method));
+ MethodType mt =
+ MethodType.methodType(method.getReturnType(), method.getParameterTypes());
+ return new MthDesc<>(mt.describeConstable().orElseThrow());
}
/**
@@ -201,6 +203,23 @@ public interface Methods {
return new MthDescCheckedBuilderR<>();
}
+ /**
+ * Begin building a method descriptor derived from the given method reference
+ *
+ * @see #derive(Function)
+ * @param <R> the return type, boxed
+ * @param <A0> the first argument type, boxed
+ * @param <A1> another argument type, boxed
+ * @param <A2> another argument type, boxed
+ * @param func the method reference
+ * @return the checked builder
+ */
+ public static <R, A0, A1, A2>
+ MthDescCheckedBuilderR<R, CkEnt<CkEnt<CkBot, A2>, A1>>
+ deriveInst(A3Function<A0, A1, A2, R> func) {
+ return new MthDescCheckedBuilderR<>();
+ }
+
/**
* Begin building a method descriptor derived from the given method reference
*
@@ -336,7 +355,7 @@ public interface Methods {
*/
public static <R, CN extends CkNext> MthDescCheckedBuilderP<TRef<R>, Bot, CN>
returns(MthDescCheckedBuilderR<R, CN> builder, TRef<R> retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -349,7 +368,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TVoid, Bot, CN>
returns(MthDescCheckedBuilderR<Void, CN> builder, TVoid retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -362,7 +381,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TInt, Bot, CN>
returns(MthDescCheckedBuilderR<Boolean, CN> builder, TBool retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -375,7 +394,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TInt, Bot, CN>
returns(MthDescCheckedBuilderR<Boolean, CN> builder, TByte retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -388,7 +407,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TInt, Bot, CN>
returns(MthDescCheckedBuilderR<Boolean, CN> builder, TChar retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -401,7 +420,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TInt, Bot, CN>
returns(MthDescCheckedBuilderR<Boolean, CN> builder, TShort retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -414,7 +433,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TInt, Bot, CN>
returns(MthDescCheckedBuilderR<Integer, CN> builder, TInt retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -427,7 +446,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TLong, Bot, CN>
returns(MthDescCheckedBuilderR<Long, CN> builder, TLong retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -440,7 +459,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TFloat, Bot, CN>
returns(MthDescCheckedBuilderR<Integer, CN> builder, TFloat retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -453,7 +472,7 @@ public interface Methods {
*/
public static <CN extends CkNext> MthDescCheckedBuilderP<TDouble, Bot, CN>
returns(MthDescCheckedBuilderR<Long, CN> builder, TDouble retType) {
- return new MthDescCheckedBuilderP<>(retType.type());
+ return new MthDescCheckedBuilderP<>(retType.classDesc());
}
/**
@@ -472,7 +491,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, P, CN1 extends CkNext,
CN0 extends CkEnt<CN1, P>> MthDescCheckedBuilderP<MR, Ent<N, TRef<P>>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TRef<P> paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -491,7 +510,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Integer>> MthDescCheckedBuilderP<MR, Ent<N, TInt>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TBool paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -510,7 +529,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Integer>> MthDescCheckedBuilderP<MR, Ent<N, TInt>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TByte paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -529,7 +548,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Integer>> MthDescCheckedBuilderP<MR, Ent<N, TInt>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TChar paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -548,7 +567,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Integer>> MthDescCheckedBuilderP<MR, Ent<N, TInt>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TShort paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -567,7 +586,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Integer>> MthDescCheckedBuilderP<MR, Ent<N, TInt>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TInt paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -586,7 +605,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Long>> MthDescCheckedBuilderP<MR, Ent<N, TLong>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TLong paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -605,7 +624,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Float>> MthDescCheckedBuilderP<MR, Ent<N, TFloat>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TFloat paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -624,7 +643,7 @@ public interface Methods {
public static <MR extends BType, N extends Next, CN1 extends CkNext,
CN0 extends CkEnt<CN1, Double>> MthDescCheckedBuilderP<MR, Ent<N, TDouble>, CN1>
param(MthDescCheckedBuilderP<MR, N, CN0> builder, TDouble paramType) {
- builder.paramTypes.add(paramType.type());
+ builder.paramTypes.add(paramType.classDesc());
return (MthDescCheckedBuilderP) builder;
}
@@ -640,8 +659,8 @@ public interface Methods {
*/
public static <MR extends BType, N extends Next> MthDesc<MR, N>
build(MthDescCheckedBuilderP<MR, N, CkBot> builder) {
- return new MthDesc<>(
- Type.getMethodDescriptor(builder.retType, builder.paramTypes.toArray(Type[]::new)));
+ return new MthDesc<>(MethodTypeDesc.of(builder.retType,
+ builder.paramTypes.toArray(ClassDesc[]::new)));
}
}
@@ -652,10 +671,10 @@ public interface Methods {
* @param <N> the parameter (machine) types specified so far, encoded as in {@link Emitter}.
*/
public static class MthDescBuilder<MR extends BType, N extends Next> {
- private final Type retType;
- private final List<Type> paramTypes = new ArrayList<>();
+ private final ClassDesc retType;
+ private final List<ClassDesc> paramTypes = new ArrayList<>();
- MthDescBuilder(Type retType) {
+ MthDescBuilder(ClassDesc retType) {
this.retType = retType;
}
@@ -668,7 +687,7 @@ public interface Methods {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public <P extends BNonVoid> MthDescBuilder<MR, Ent<N, P>> param(P paramType) {
- paramTypes.add(paramType.type());
+ paramTypes.add(paramType.classDesc());
return (MthDescBuilder) this;
}
@@ -680,7 +699,7 @@ public interface Methods {
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public MthDescBuilder<MR, Ent<N, TInt>> param(SType paramType) {
- paramTypes.add(paramType.type());
+ paramTypes.add(paramType.classDesc());
return (MthDescBuilder) this;
}
@@ -691,7 +710,7 @@ public interface Methods {
*/
public MthDesc<MR, N> build() {
return new MthDesc<>(
- Type.getMethodDescriptor(retType, paramTypes.toArray(Type[]::new)));
+ MethodTypeDesc.of(retType, paramTypes.toArray(ClassDesc[]::new)));
}
}
@@ -757,10 +776,10 @@ public interface Methods {
*/
public static class MthDescCheckedBuilderP<MR extends BType, N extends Next,
CN extends CkNext> {
- private final Type retType;
- private final List<Type> paramTypes = new ArrayList<>();
+ private final ClassDesc retType;
+ private final List<ClassDesc> paramTypes = new ArrayList<>();
- MthDescCheckedBuilderP(Type retType) {
+ MthDescCheckedBuilderP(ClassDesc retType) {
this.retType = retType;
}
@@ -1212,6 +1231,15 @@ public interface Methods {
return new RetReqEm<>(new RetReq<>(), mdef.em);
}
+ /**
+ * Drop a parameter handle
+ *
+ * @param <T> the type of the parameter
+ * @param param the parameter handle
+ */
+ public static <T extends BNonVoid> void ignore(Local<T> param) {
+ }
+
/**
* A syntactic workaround for static method chaining
*
@@ -1301,4 +1329,44 @@ public interface Methods {
* @param <T> the required return type
*/
record RetReqEm<T extends BType>(RetReq<T> ret, Emitter<Bot> em) {}
+
+ public static class AbstractMethodBuilder<MR extends BType, N extends Next> {
+ final CodeBuilder cb;
+ final String name;
+ final MthDesc<MR, N> desc;
+ final int flags;
+
+ AbstractMethodBuilder(CodeBuilder cb, String name, MthDesc<MR, N> desc, int flags) {
+ this.name = name;
+ this.cb = cb;
+ this.desc = desc;
+ this.flags = flags;
+ }
+ }
+
+ public static class InstanceMethodBuilder<OT, MR extends BType, N extends Next>
+ extends AbstractMethodBuilder<MR, N> {
+ final TRef<OT> owner;
+
+ InstanceMethodBuilder(CodeBuilder cb, TRef<OT> owner, String name, MthDesc<MR, N> desc,
+ int flags) {
+ this.owner = owner;
+ super(cb, name, desc, flags);
+ }
+
+ public ObjDef<MR, OT, N> startSpec() {
+ return Emitter.startInstance(owner, cb, desc);
+ }
+ }
+
+ public static class StaticMethodBuilder<MR extends BType, N extends Next>
+ extends AbstractMethodBuilder<MR, N> {
+ StaticMethodBuilder(CodeBuilder cb, String name, MthDesc<MR, N> desc, int flags) {
+ super(cb, name, desc, flags);
+ }
+
+ public Def<MR, N> startSpec() {
+ return Emitter.startStatic(cb, desc);
+ }
+ }
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Misc.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Misc.java
index 1b5685e63f..e71eb70930 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Misc.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Misc.java
@@ -15,11 +15,6 @@
*/
package ghidra.pcode.emu.jit.gen.util;
-import java.lang.System.Logger.Level;
-
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-
import ghidra.pcode.emu.jit.gen.util.Emitter.*;
import ghidra.pcode.emu.jit.gen.util.Types.BNonVoid;
import ghidra.pcode.emu.jit.gen.util.Types.TRef;
@@ -35,7 +30,7 @@ public interface Misc {
* <p>
* This may be necessary when a code generating method is typed to pop then push something of
* the same type, but in some conditions actually just leaves the stack as is.
- *
+ *
* @param <T1> the type at the top of the stack
* @param <N1> the tail of the stack
* @param <N0> the full stack
@@ -51,7 +46,7 @@ public interface Misc {
/**
* A handle to an (incomplete) {@code try-catch} block
- *
+ *
* @param <T> the type caught by the block
* @param <N> the stack contents at the start and end of the {@code try} block
* @param end the label to place at the end of the {@code try} block
@@ -73,12 +68,12 @@ public interface Misc {
* correctly placed, it cannot check if placement is altogether forgotten. Ideally, the handler
* label is placed where code is otherwise unreachable, i.e., using
* {@code Lbl#placeDead(Emitter, Lbl)}.
- *
+ *
* @param <T> the type caught by the block
* @param <N> the stack contents at the bounds of the {@code try} block
* @param em the emitter
- * @param end the end label, often just {@link Lbl#create()}.
- * @param handler the handler label, often just {@link Lbl#create()}
+ * @param end the end label, often just {@link Lbl#create(Emitter)}.
+ * @param handler the handler label, often just {@link Lbl#create(Emitter)}
* @param type the exception type. If multiple types are caught, this must be the join of those
* types, and the user must emit code to distinguish each, possibly re-throwing if
* the join is larger than the union.
@@ -86,43 +81,41 @@ public interface Misc {
*/
static <T extends Throwable, N extends Next> TryCatchBlock<T, N> tryCatch(Emitter<N> em,
Lbl<N> end, Lbl<Ent<N, TRef<T>>> handler, TRef<T> type) {
- Lbl<N> start = Lbl.create();
+ Lbl<N> start = Lbl.create(em);
em = em.emit(Lbl::place, start);
if (Op.DEEP_TRACE) {
System.err.println(
" jvm<try-catch> %s handler=%s, end=%s".formatted(type, handler, end));
}
- em.mv.visitTryCatchBlock(start.label(), end.label(), handler.label(),
- type.internalName());
+ em.cb.exceptionCatch(start.label(), end.label(), handler.label(), type.classDesc());
return new TryCatchBlock<>(end, handler, em);
}
/**
* Place a line number
- *
+ *
* @param <N> any live stack
* @param em the emitter
* @param number the (non zero) line number
* @return the emitter
*/
static <N extends Next> Emitter<N> lineNumber(Emitter<N> em, int number) {
- Label label = new Label();
if (Op.DEEP_TRACE) {
System.err.println(" jvm<Line %d>".formatted(number));
}
- em.mv.visitLabel(label);
- em.mv.visitLineNumber(number, label);
+ em.cb.lineNumber(number);
return em;
}
/**
* Finish emitting bytecode
* <p>
- * This is where we invoke {@link MethodVisitor#visitMaxs(int, int)}. Frameworks that require
- * bytecode generation can try to enforce this by requiring bytecode generation methods to
- * return {@link Void}. Sure, a user can just return null, but this will at least remind them
+ * With the Class-File API, stack map frames and max values are computed automatically, so this
+ * method only needs to close the root scope for local variable declarations. Frameworks that
+ * require bytecode generation can try to enforce this by requiring bytecode generation methods
+ * to return {@link Void}. Sure, a user can just return null, but this will at least remind them
* that they should call this method, as convention is to use a pattern like:
- *
+ *
* <pre>
* return em
* .emit(Op::ldc__i, 0)
@@ -132,19 +125,12 @@ public interface Misc {
* <p>
* A user of this pattern would be reminded were {@code finish} missing. Provided the generation
* method returns {@link Void}, this pattern should compile.
- *
- * @param em the emittter
+ *
+ * @param em the emitter
* @return null
*/
static Void finish(Emitter<Dead> em) {
em.rootScope.close();
- try {
- em.mv.visitMaxs(0, 0);
- }
- catch (Exception e) {
- Emitter.LOGGER.log(Level.WARNING, "Failed to compute Maxs", e);
- }
- em.mv.visitEnd();
return null;
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Op.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Op.java
index 608376e688..2bfcff88f1 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Op.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Op.java
@@ -15,13 +15,13 @@
*/
package ghidra.pcode.emu.jit.gen.util;
-import java.util.List;
-import java.util.Map;
+import java.lang.classfile.CodeBuilder;
+import java.lang.classfile.instruction.SwitchCase;
+import java.lang.constant.*;
+import java.util.*;
import java.util.Map.Entry;
import java.util.function.Function;
-import org.objectweb.asm.*;
-
import ghidra.pcode.emu.jit.JitCompiler;
import ghidra.pcode.emu.jit.JitCompiler.Diag;
import ghidra.pcode.emu.jit.gen.util.Emitter.*;
@@ -74,7 +74,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: aaload");
}
- em.mv.visitInsn(Opcodes.AALOAD);
+ em.cb.aaload();
return (Emitter) em;
}
@@ -98,7 +98,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: aastore");
}
- em.mv.visitInsn(Opcodes.AASTORE);
+ em.cb.aastore();
return (Emitter) em;
}
@@ -117,7 +117,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: aconst_null %s".formatted(type));
}
- em.mv.visitInsn(Opcodes.ACONST_NULL);
+ em.cb.aconst_null();
return (Emitter) em;
}
@@ -136,7 +136,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: aload %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.ALOAD, local.index());
+ em.cb.aload(local.index());
return (Emitter) em;
}
@@ -157,7 +157,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: anewarray %s".formatted(elemType));
}
- em.mv.visitTypeInsn(Opcodes.ANEWARRAY, elemType.internalName());
+ em.cb.anewarray(elemType.classDesc());
return (Emitter) em;
}
@@ -179,7 +179,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: areturn %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.ARETURN);
+ em.cb.areturn();
return (Emitter) em;
}
@@ -200,7 +200,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: arraylength %s".formatted(elemType));
}
- em.mv.visitInsn(Opcodes.ARRAYLENGTH);
+ em.cb.arraylength();
return (Emitter) em;
}
@@ -220,7 +220,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: arraylength");
}
- em.mv.visitInsn(Opcodes.ARRAYLENGTH);
+ em.cb.arraylength();
return (Emitter) em;
}
@@ -242,7 +242,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: astore %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.ASTORE, local.index());
+ em.cb.astore(local.index());
return (Emitter) em;
}
@@ -262,7 +262,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: athrow");
}
- em.mv.visitInsn(Opcodes.ATHROW);
+ em.cb.athrow();
return (Emitter) em;
}
@@ -283,7 +283,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: baload");
}
- em.mv.visitInsn(Opcodes.BALOAD);
+ em.cb.baload();
return (Emitter) em;
}
@@ -304,7 +304,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: baload");
}
- em.mv.visitInsn(Opcodes.BALOAD);
+ em.cb.baload();
return (Emitter) em;
}
@@ -327,7 +327,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: bastore");
}
- em.mv.visitInsn(Opcodes.BASTORE);
+ em.cb.bastore();
return (Emitter) em;
}
@@ -350,7 +350,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: bastore");
}
- em.mv.visitInsn(Opcodes.BASTORE);
+ em.cb.bastore();
return (Emitter) em;
}
@@ -371,7 +371,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: caload");
}
- em.mv.visitInsn(Opcodes.CALOAD);
+ em.cb.caload();
return (Emitter) em;
}
@@ -394,7 +394,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: castore");
}
- em.mv.visitInsn(Opcodes.CASTORE);
+ em.cb.castore();
return (Emitter) em;
}
@@ -417,7 +417,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: checkcast %s".formatted(type));
}
- em.mv.visitTypeInsn(Opcodes.CHECKCAST, type.internalName());
+ em.cb.checkcast(type.classDesc());
return (Emitter) em;
}
@@ -436,7 +436,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: d2f");
}
- em.mv.visitInsn(Opcodes.D2F);
+ em.cb.d2f();
return (Emitter) em;
}
@@ -455,7 +455,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: d2i");
}
- em.mv.visitInsn(Opcodes.D2I);
+ em.cb.d2i();
return (Emitter) em;
}
@@ -474,7 +474,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: d2l");
}
- em.mv.visitInsn(Opcodes.D2L);
+ em.cb.d2l();
return (Emitter) em;
}
@@ -495,7 +495,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dadd");
}
- em.mv.visitInsn(Opcodes.DADD);
+ em.cb.dadd();
return (Emitter) em;
}
@@ -516,7 +516,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: daload");
}
- em.mv.visitInsn(Opcodes.DALOAD);
+ em.cb.daload();
return (Emitter) em;
}
@@ -539,7 +539,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dastore");
}
- em.mv.visitInsn(Opcodes.DASTORE);
+ em.cb.dastore();
return (Emitter) em;
}
@@ -560,7 +560,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dcmpg");
}
- em.mv.visitInsn(Opcodes.DCMPG);
+ em.cb.dcmpg();
return (Emitter) em;
}
@@ -581,7 +581,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dcmpl");
}
- em.mv.visitInsn(Opcodes.DCMPL);
+ em.cb.dcmpl();
return (Emitter) em;
}
@@ -602,7 +602,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ddiv");
}
- em.mv.visitInsn(Opcodes.DDIV);
+ em.cb.ddiv();
return (Emitter) em;
}
@@ -619,7 +619,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dload %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.DLOAD, local.index());
+ em.cb.dload(local.index());
return (Emitter) em;
}
@@ -640,7 +640,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dmul");
}
- em.mv.visitInsn(Opcodes.DMUL);
+ em.cb.dmul();
return (Emitter) em;
}
@@ -659,7 +659,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dneg");
}
- em.mv.visitInsn(Opcodes.DNEG);
+ em.cb.dneg();
return (Emitter) em;
}
@@ -680,7 +680,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: drem");
}
- em.mv.visitInsn(Opcodes.DREM);
+ em.cb.drem();
return (Emitter) em;
}
@@ -700,7 +700,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dreturn %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.DRETURN);
+ em.cb.dreturn();
return (Emitter) em;
}
@@ -720,7 +720,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dstore %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.DSTORE, local.index());
+ em.cb.dstore(local.index());
return (Emitter) em;
}
@@ -741,7 +741,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dsub");
}
- em.mv.visitInsn(Opcodes.DSUB);
+ em.cb.dsub();
return (Emitter) em;
}
@@ -761,7 +761,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup");
}
- em.mv.visitInsn(Opcodes.DUP);
+ em.cb.dup();
return (Emitter) em;
}
@@ -784,7 +784,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup_x1");
}
- em.mv.visitInsn(Opcodes.DUP_X1);
+ em.cb.dup_x1();
return (Emitter) em;
}
@@ -810,7 +810,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup_x2 (111)");
}
- em.mv.visitInsn(Opcodes.DUP_X2);
+ em.cb.dup_x2();
return (Emitter) em;
}
@@ -833,7 +833,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup_x2 (21)");
}
- em.mv.visitInsn(Opcodes.DUP_X2);
+ em.cb.dup_x2();
return (Emitter) em;
}
@@ -856,7 +856,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2 (11)");
}
- em.mv.visitInsn(Opcodes.DUP2);
+ em.cb.dup2();
return (Emitter) em;
}
@@ -876,7 +876,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2 (2)");
}
- em.mv.visitInsn(Opcodes.DUP2);
+ em.cb.dup2();
return (Emitter) em;
}
@@ -899,10 +899,10 @@ public interface Op {
N1 extends Ent<N2, V2>,
N0 extends Ent<N1, V1>>
Emitter<Ent<Ent<Ent<Ent<Ent<N3, V2>, V1>, V3>, V2>, V1>> dup2_x1__111(Emitter<N0> em) {
- em.mv.visitInsn(Opcodes.DUP2_X1);
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x1 (111)");
}
+ em.cb.dup2_x1();
return (Emitter) em;
}
@@ -925,7 +925,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x1 (12)");
}
- em.mv.visitInsn(Opcodes.DUP2_X1);
+ em.cb.dup2_x1();
return (Emitter) em;
}
@@ -952,10 +952,10 @@ public interface Op {
N0 extends Ent<N1, V1>>
Emitter<Ent<Ent<Ent<Ent<Ent<Ent<N4, V2>, V1>, V4>, V3>, V2>, V1>>
dup2_x2_1111(Emitter<N0> em) {
- em.mv.visitInsn(Opcodes.DUP2_X2);
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x2 (1111)");
}
+ em.cb.dup2_x2();
return (Emitter) em;
}
@@ -981,7 +981,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x2 (112)");
}
- em.mv.visitInsn(Opcodes.DUP2_X2);
+ em.cb.dup2_x2();
return (Emitter) em;
}
@@ -1007,7 +1007,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x2 (211)");
}
- em.mv.visitInsn(Opcodes.DUP2_X2);
+ em.cb.dup2_x2();
return (Emitter) em;
}
@@ -1030,7 +1030,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: dup2_x2 (22)");
}
- em.mv.visitInsn(Opcodes.DUP2_X2);
+ em.cb.dup2_x2();
return (Emitter) em;
}
@@ -1049,7 +1049,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: f2d");
}
- em.mv.visitInsn(Opcodes.F2D);
+ em.cb.f2d();
return (Emitter) em;
}
@@ -1068,7 +1068,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: f2i");
}
- em.mv.visitInsn(Opcodes.F2I);
+ em.cb.f2i();
return (Emitter) em;
}
@@ -1087,7 +1087,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: f2l");
}
- em.mv.visitInsn(Opcodes.F2L);
+ em.cb.f2l();
return (Emitter) em;
}
@@ -1108,7 +1108,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fadd");
}
- em.mv.visitInsn(Opcodes.FADD);
+ em.cb.fadd();
return (Emitter) em;
}
@@ -1129,7 +1129,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: faload");
}
- em.mv.visitInsn(Opcodes.FALOAD);
+ em.cb.faload();
return (Emitter) em;
}
@@ -1152,7 +1152,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fastore");
}
- em.mv.visitInsn(Opcodes.FASTORE);
+ em.cb.fastore();
return (Emitter) em;
}
@@ -1173,7 +1173,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fcmpg");
}
- em.mv.visitInsn(Opcodes.FCMPG);
+ em.cb.fcmpg();
return (Emitter) em;
}
@@ -1194,7 +1194,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fcmpl");
}
- em.mv.visitInsn(Opcodes.FCMPL);
+ em.cb.fcmpl();
return (Emitter) em;
}
@@ -1215,7 +1215,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fdiv");
}
- em.mv.visitInsn(Opcodes.FDIV);
+ em.cb.fdiv();
return (Emitter) em;
}
@@ -1232,7 +1232,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fload %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.FLOAD, local.index());
+ em.cb.fload(local.index());
return (Emitter) em;
}
@@ -1253,7 +1253,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fmul");
}
- em.mv.visitInsn(Opcodes.FMUL);
+ em.cb.fmul();
return (Emitter) em;
}
@@ -1272,7 +1272,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fneg");
}
- em.mv.visitInsn(Opcodes.FNEG);
+ em.cb.fneg();
return (Emitter) em;
}
@@ -1293,7 +1293,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: frem");
}
- em.mv.visitInsn(Opcodes.FREM);
+ em.cb.frem();
return (Emitter) em;
}
@@ -1313,7 +1313,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: freturn %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.FRETURN);
+ em.cb.freturn();
return (Emitter) em;
}
@@ -1333,7 +1333,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fstore %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.FSTORE, local.index());
+ em.cb.fstore(local.index());
return (Emitter) em;
}
@@ -1354,7 +1354,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: fsub");
}
- em.mv.visitInsn(Opcodes.FSUB);
+ em.cb.fsub();
return (Emitter) em;
}
@@ -1386,8 +1386,7 @@ public interface Op {
jvm: getfield %s %s
.%s""".formatted(type, owner, name));
}
- em.mv.visitFieldInsn(Opcodes.GETFIELD, owner.type().getInternalName(), name,
- type.type().getDescriptor());
+ em.cb.getfield(owner.classDesc(), name, type.classDesc());
return (Emitter) em;
}
@@ -1413,8 +1412,7 @@ public interface Op {
jvm: getstatic %s %s
.%s""".formatted(type, owner, name));
}
- em.mv.visitFieldInsn(Opcodes.GETSTATIC, owner.type().getInternalName(), name,
- type.type().getDescriptor());
+ em.cb.getstatic(owner.classDesc(), name, type.classDesc());
return (Emitter) em;
}
@@ -1427,11 +1425,11 @@ public interface Op {
*/
static <N extends Next>
LblEm<N, Dead> goto_(Emitter<N> em) {
- Lbl<N> target = Lbl.create();
+ Lbl<N> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: goto %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.GOTO, target.label());
+ em.cb.goto_(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1448,7 +1446,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: goto %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.GOTO, target.label());
+ em.cb.goto_(target.label());
return (Emitter) em;
}
@@ -1467,7 +1465,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2b");
}
- em.mv.visitInsn(Opcodes.I2B);
+ em.cb.i2b();
return (Emitter) em;
}
@@ -1486,7 +1484,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2c");
}
- em.mv.visitInsn(Opcodes.I2C);
+ em.cb.i2c();
return (Emitter) em;
}
@@ -1505,7 +1503,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2d");
}
- em.mv.visitInsn(Opcodes.I2D);
+ em.cb.i2d();
return (Emitter) em;
}
@@ -1524,13 +1522,13 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2f");
}
- em.mv.visitInsn(Opcodes.I2F);
+ em.cb.i2f();
return (Emitter) em;
}
/**
* Emit an {@code i2l} instruction
- *
+ *
* @param <N1> the tail of the stack (...)
* @param <N0> ..., value
* @param em the emitter
@@ -1543,7 +1541,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2l");
}
- em.mv.visitInsn(Opcodes.I2L);
+ em.cb.i2l();
return (Emitter) em;
}
@@ -1562,7 +1560,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: i2s");
}
- em.mv.visitInsn(Opcodes.I2S);
+ em.cb.i2s();
return (Emitter) em;
}
@@ -1583,7 +1581,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iadd");
}
- em.mv.visitInsn(Opcodes.IADD);
+ em.cb.iadd();
return (Emitter) em;
}
@@ -1604,7 +1602,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iaload");
}
- em.mv.visitInsn(Opcodes.IALOAD);
+ em.cb.iaload();
return (Emitter) em;
}
@@ -1625,7 +1623,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iand");
}
- em.mv.visitInsn(Opcodes.IAND);
+ em.cb.iand();
return (Emitter) em;
}
@@ -1648,7 +1646,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iastore");
}
- em.mv.visitInsn(Opcodes.IASTORE);
+ em.cb.iastore();
return (Emitter) em;
}
@@ -1669,7 +1667,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: idiv");
}
- em.mv.visitInsn(Opcodes.IDIV);
+ em.cb.idiv();
return (Emitter) em;
}
@@ -1687,11 +1685,11 @@ public interface Op {
N1 extends Ent<N2, TRef<?>>,
N0 extends Ent<N1, TRef<?>>>
LblEm<N2, N2> if_acmpeq(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_acmpeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ACMPEQ, target.label());
+ em.cb.if_acmpeq(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1713,7 +1711,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_acmpeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ACMPEQ, target.label());
+ em.cb.if_acmpeq(target.label());
return (Emitter) em;
}
@@ -1731,11 +1729,11 @@ public interface Op {
N1 extends Ent<N2, TRef<?>>,
N0 extends Ent<N1, TRef<?>>>
LblEm<N2, N2> if_acmpne(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_acmpne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ACMPNE, target.label());
+ em.cb.if_acmpne(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1757,7 +1755,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_acmpne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ACMPNE, target.label());
+ em.cb.if_acmpne(target.label());
return (Emitter) em;
}
@@ -1775,11 +1773,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmpeq(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPEQ, target.label());
+ em.cb.if_icmpeq(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1801,7 +1799,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPEQ, target.label());
+ em.cb.if_icmpeq(target.label());
return (Emitter) em;
}
@@ -1819,11 +1817,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmpge(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpge %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPGE, target.label());
+ em.cb.if_icmpge(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1845,7 +1843,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpge %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPGE, target.label());
+ em.cb.if_icmpge(target.label());
return (Emitter) em;
}
@@ -1863,11 +1861,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmpgt(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpgt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPGT, target.label());
+ em.cb.if_icmpgt(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1889,7 +1887,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpgt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPGT, target.label());
+ em.cb.if_icmpgt(target.label());
return (Emitter) em;
}
@@ -1907,11 +1905,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmple(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmple %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPLE, target.label());
+ em.cb.if_icmple(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1933,7 +1931,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmple %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPLE, target.label());
+ em.cb.if_icmple(target.label());
return (Emitter) em;
}
@@ -1951,11 +1949,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmplt(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmplt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPLT, target.label());
+ em.cb.if_icmplt(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -1977,7 +1975,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmplt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPLT, target.label());
+ em.cb.if_icmplt(target.label());
return (Emitter) em;
}
@@ -1995,11 +1993,11 @@ public interface Op {
N1 extends Ent<N2, TInt>,
N0 extends Ent<N1, TInt>>
LblEm<N2, N2> if_icmpne(Emitter<N0> em) {
- Lbl<N2> target = Lbl.create();
+ Lbl<N2> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPNE, target.label());
+ em.cb.if_icmpne(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2021,7 +2019,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: if_icmpne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IF_ICMPNE, target.label());
+ em.cb.if_icmpne(target.label());
return (Emitter) em;
}
@@ -2037,11 +2035,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> ifeq(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFEQ, target.label());
+ em.cb.ifeq(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2061,7 +2059,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifeq %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFEQ, target.label());
+ em.cb.ifeq(target.label());
return (Emitter) em;
}
@@ -2077,11 +2075,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> ifge(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifge %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFGE, target.label());
+ em.cb.ifge(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2101,7 +2099,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifge %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFGE, target.label());
+ em.cb.ifge(target.label());
return (Emitter) em;
}
@@ -2117,11 +2115,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> ifgt(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifgt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFGT, target.label());
+ em.cb.ifgt(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2141,7 +2139,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifgt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFGT, target.label());
+ em.cb.ifgt(target.label());
return (Emitter) em;
}
@@ -2157,11 +2155,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> ifle(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifle %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFLE, target.label());
+ em.cb.ifle(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2181,7 +2179,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifle %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFLE, target.label());
+ em.cb.ifle(target.label());
return (Emitter) em;
}
@@ -2197,11 +2195,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> iflt(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: iflt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFLT, target.label());
+ em.cb.iflt(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2221,7 +2219,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iflt %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFLT, target.label());
+ em.cb.iflt(target.label());
return (Emitter) em;
}
@@ -2237,11 +2235,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
LblEm<N1, N1> ifne(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNE, target.label());
+ em.cb.ifne(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2261,7 +2259,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifne %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNE, target.label());
+ em.cb.ifne(target.label());
return (Emitter) em;
}
@@ -2277,11 +2275,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TRef<?>>>
LblEm<N1, N1> ifnonnull(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifnonnull %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNONNULL, target.label());
+ em.cb.ifnonnull(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2301,7 +2299,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifnonnull %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNONNULL, target.label());
+ em.cb.ifnonnull(target.label());
return (Emitter) em;
}
@@ -2317,11 +2315,11 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TRef<?>>>
LblEm<N1, N1> ifnull(Emitter<N0> em) {
- Lbl<N1> target = Lbl.create();
+ Lbl<N1> target = Lbl.create(em);
if (DEEP_TRACE) {
System.err.println(" jvm: ifnull %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNULL, target.label());
+ em.cb.ifnull(target.label());
return new LblEm<>(target, (Emitter) em);
}
@@ -2341,7 +2339,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ifnull %s".formatted(target));
}
- em.mv.visitJumpInsn(Opcodes.IFNULL, target.label());
+ em.cb.ifnull(target.label());
return (Emitter) em;
}
@@ -2359,7 +2357,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iinc %s %d".formatted(local, increment));
}
- em.mv.visitIincInsn(local.index(), increment);
+ em.cb.iinc(local.index(), increment);
return em;
}
@@ -2376,7 +2374,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iload %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.ILOAD, local.index());
+ em.cb.iload(local.index());
return (Emitter) em;
}
@@ -2397,7 +2395,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: imul");
}
- em.mv.visitInsn(Opcodes.IMUL);
+ em.cb.imul();
return (Emitter) em;
}
@@ -2416,7 +2414,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ineg");
}
- em.mv.visitInsn(Opcodes.INEG);
+ em.cb.ineg();
return (Emitter) em;
}
@@ -2436,7 +2434,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: instanceof %s".formatted(type));
}
- em.mv.visitTypeInsn(Opcodes.INSTANCEOF, type.internalName());
+ em.cb.instanceOf(type.classDesc());
return (Emitter) em;
}
@@ -2446,19 +2444,17 @@ public interface Op {
* <b>WARNING:</b> This is probably not implemented correctly. The JVM spec does not provide an
* example, but the best we can tell, after all the call site resolution machinery, the net
* arguments actually consumed from the stack is determined by the given method descriptor. We
- * also just let the ASM types {@link Type}, {@link Handle}, and {@link ConstantDynamic} leak
- * from an API perspective.
- *
+ * also just let the Class-File API types {@link DirectMethodHandleDesc}, {@link ConstantDesc},
+ * and {@link DynamicCallSiteDesc} leak from an API perspective.
+ *
* @param <SN> the JVM stack at the call site. Some may be popped as arguments
* @param <MN> the parameters expected by the method descriptor
* @param <MR> the return type from the method descriptor
* @param em the emitter
* @param name the name of the method
* @param desc the method descriptor
- * @param bootstrapMethodHandle as in
- * {@link MethodVisitor#visitInvokeDynamicInsn(String, String, Handle, Object...)}
- * @param bootstrapMethodArguments as in
- * {@link MethodVisitor#visitInvokeDynamicInsn(String, String, Handle, Object...)}
+ * @param bootstrapMethodHandle as in {@link CodeBuilder#invokedynamic}
+ * @param bootstrapMethodArguments as in {@link CodeBuilder#invokedynamic}
* @return an object to complete type checking of the arguments and, if applicable, the result
*/
static <
@@ -2466,16 +2462,16 @@ public interface Op {
MN extends Next,
MR extends BType>
Inv<MR, SN, MN> invokedynamic__unsupported(Emitter<SN> em, String name,
- MthDesc<MR, MN> desc, Handle bootstrapMethodHandle,
- Object... bootstrapMethodArguments) {
+ MthDesc<MR, MN> desc, DirectMethodHandleDesc bootstrapMethodHandle,
+ ConstantDesc... bootstrapMethodArguments) {
if (DEEP_TRACE) {
System.err.println("""
\
jvm: invokedynamic %s %s %s %s""".formatted(name, desc,
bootstrapMethodHandle, bootstrapMethodArguments));
}
- em.mv.visitInvokeDynamicInsn(name, desc.desc(), bootstrapMethodHandle,
- bootstrapMethodArguments);
+ em.cb.invokedynamic(DynamicCallSiteDesc.of(
+ bootstrapMethodHandle, name, desc.desc(), bootstrapMethodArguments));
return new Inv<>(em);
}
@@ -2504,9 +2500,7 @@ public interface Op {
jvm: invokeinterface %s
.%s %s""".formatted(ownerType, name, desc));
}
- em.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ownerType.internalName(),
- name,
- desc.desc(), true);
+ em.cb.invokeinterface(ownerType.classDesc(), name, desc.desc());
return new ObjInv<>(em);
}
@@ -2537,8 +2531,7 @@ public interface Op {
.%s %s (%s)""".formatted(ownerType, name, desc,
isInterface ? "interface" : "class"));
}
- em.mv.visitMethodInsn(Opcodes.INVOKESPECIAL, ownerType.internalName(), name,
- desc.desc(), isInterface);
+ em.cb.invokespecial(ownerType.classDesc(), name, desc.desc(), isInterface);
return new ObjInv<>(em);
}
@@ -2568,8 +2561,7 @@ public interface Op {
.%s %s (%s)""".formatted(ownerType, name, desc,
isInterface ? "interface" : "class"));
}
- em.mv.visitMethodInsn(Opcodes.INVOKESTATIC, ownerType.internalName(), name,
- desc.desc(), isInterface);
+ em.cb.invokestatic(ownerType.classDesc(), name, desc.desc(), isInterface);
return new Inv<>(em);
}
@@ -2600,8 +2592,7 @@ public interface Op {
.%s %s (%s)""".formatted(ownerType, name, desc,
isInterface ? "interface" : "class"));
}
- em.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, ownerType.internalName(), name,
- desc.desc(), isInterface);
+ em.cb.invokevirtual(ownerType.classDesc(), name, desc.desc());
return new ObjInv<>(em);
}
@@ -2622,7 +2613,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ior");
}
- em.mv.visitInsn(Opcodes.IOR);
+ em.cb.ior();
return (Emitter) em;
}
@@ -2643,7 +2634,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: irem");
}
- em.mv.visitInsn(Opcodes.IREM);
+ em.cb.irem();
return (Emitter) em;
}
@@ -2663,7 +2654,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ireturn %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.IRETURN);
+ em.cb.ireturn();
return (Emitter) em;
}
@@ -2684,7 +2675,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ishl");
}
- em.mv.visitInsn(Opcodes.ISHL);
+ em.cb.ishl();
return (Emitter) em;
}
@@ -2705,7 +2696,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ishr");
}
- em.mv.visitInsn(Opcodes.ISHR);
+ em.cb.ishr();
return (Emitter) em;
}
@@ -2725,7 +2716,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: istore %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.ISTORE, local.index());
+ em.cb.istore(local.index());
return (Emitter) em;
}
@@ -2746,7 +2737,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: isub");
}
- em.mv.visitInsn(Opcodes.ISUB);
+ em.cb.isub();
return (Emitter) em;
}
@@ -2767,7 +2758,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: iushr");
}
- em.mv.visitInsn(Opcodes.IUSHR);
+ em.cb.iushr();
return (Emitter) em;
}
@@ -2788,7 +2779,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ixor");
}
- em.mv.visitInsn(Opcodes.IXOR);
+ em.cb.ixor();
return (Emitter) em;
}
@@ -2826,7 +2817,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: l2d");
}
- em.mv.visitInsn(Opcodes.L2D);
+ em.cb.l2d();
return (Emitter) em;
}
@@ -2845,7 +2836,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: l2f");
}
- em.mv.visitInsn(Opcodes.L2F);
+ em.cb.l2f();
return (Emitter) em;
}
@@ -2864,7 +2855,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: l2i");
}
- em.mv.visitInsn(Opcodes.L2I);
+ em.cb.l2i();
return (Emitter) em;
}
@@ -2885,7 +2876,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ladd");
}
- em.mv.visitInsn(Opcodes.LADD);
+ em.cb.ladd();
return (Emitter) em;
}
@@ -2906,7 +2897,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: laload");
}
- em.mv.visitInsn(Opcodes.LALOAD);
+ em.cb.laload();
return (Emitter) em;
}
@@ -2927,7 +2918,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: land");
}
- em.mv.visitInsn(Opcodes.LAND);
+ em.cb.land();
return (Emitter) em;
}
@@ -2950,7 +2941,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lastore");
}
- em.mv.visitInsn(Opcodes.LASTORE);
+ em.cb.lastore();
return (Emitter) em;
}
@@ -2971,14 +2962,14 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lcmp");
}
- em.mv.visitInsn(Opcodes.LCMP);
+ em.cb.lcmp();
return (Emitter) em;
}
/**
* Emit an {@code ldc} instruction for an integer
* <p>
- * NOTE: The underlying ASM library may emit alternative instructions at its discretion.
+ * NOTE: The underlying Class-File API may emit alternative instructions at its discretion.
*
* @param <N> the tail of the stack (...)
* @param em the emitter
@@ -2990,14 +2981,14 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ldc (int) 0x%x %d".formatted(value, value));
}
- em.mv.visitLdcInsn(value);
+ em.cb.loadConstant(value);
return (Emitter) em;
}
/**
* Emit an {@code ldc} instruction for a long
* <p>
- * NOTE: The underlying ASM library may emit alternative instructions at its discretion.
+ * NOTE: The underlying Class-File API may emit alternative instructions at its discretion.
*
* @param <N> the tail of the stack (...)
* @param em the emitter
@@ -3009,14 +3000,14 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ldc (long) 0x%x %d".formatted(value, value));
}
- em.mv.visitLdcInsn(value);
+ em.cb.loadConstant(value);
return (Emitter) em;
}
/**
* Emit an {@code ldc} instruction for a float
* <p>
- * NOTE: The underlying ASM library may emit alternative instructions at its discretion.
+ * NOTE: The underlying Class-File API may emit alternative instructions at its discretion.
*
* @param <N> the tail of the stack (...)
* @param em the emitter
@@ -3028,14 +3019,14 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ldc (float) %s".formatted(value));
}
- em.mv.visitLdcInsn(value);
+ em.cb.loadConstant(value);
return (Emitter) em;
}
/**
* Emit an {@code ldc} instruction for a double
* <p>
- * NOTE: The underlying ASM library may emit alternative instructions at its discretion.
+ * NOTE: The underlying Class-File API may emit alternative instructions at its discretion.
*
* @param <N> the tail of the stack (...)
* @param em the emitter
@@ -3047,15 +3038,14 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ldc (double) %s".formatted(value));
}
- em.mv.visitLdcInsn(value);
+ em.cb.loadConstant(value);
return (Emitter) em;
}
/**
* Emit an {@code ldc} instruction for a reference
* <p>
- * NOTE: Only certain reference types are permitted. Some of the permitted types are those
- * leaked (API-wise) from the underlying ASM library. The underlying ASM library may emit
+ * NOTE: Only certain reference types are permitted. The underlying Class-File API may emit
* alternative instructions at its discretion.
*
* @param <N> the tail of the stack (...)
@@ -3070,7 +3060,9 @@ public interface Op {
System.err.println(" jvm: ldc (%s) %s"
.formatted(value.getClass().getSimpleName(), value));
}
- em.mv.visitLdcInsn(value);
+ // value must implement ConstantDesc. T is the runtime type on the stack, which
+ // for String constants is the same as the ConstantDesc type.
+ em.cb.loadConstant((ConstantDesc) value);
return (Emitter) em;
}
@@ -3091,7 +3083,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: ldiv");
}
- em.mv.visitInsn(Opcodes.LDIV);
+ em.cb.ldiv();
return (Emitter) em;
}
@@ -3108,7 +3100,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lload %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.LLOAD, local.index());
+ em.cb.lload(local.index());
return (Emitter) em;
}
@@ -3129,7 +3121,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lmul");
}
- em.mv.visitInsn(Opcodes.LMUL);
+ em.cb.lmul();
return (Emitter) em;
}
@@ -3148,7 +3140,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lneg");
}
- em.mv.visitInsn(Opcodes.LNEG);
+ em.cb.lneg();
return (Emitter) em;
}
@@ -3173,9 +3165,11 @@ public interface Op {
}
System.err.println(" }");
}
- em.mv.visitLookupSwitchInsn(dflt.label(),
- cases.keySet().stream().mapToInt(k -> k).toArray(),
- cases.values().stream().map(Lbl::label).toArray(Label[]::new));
+ em.cb.lookupswitch(dflt.label(),
+ cases.entrySet()
+ .stream()
+ .map(e -> SwitchCase.of(e.getKey(), e.getValue().label()))
+ .toList());
return (Emitter) em;
}
@@ -3196,7 +3190,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lor");
}
- em.mv.visitInsn(Opcodes.LOR);
+ em.cb.lor();
return (Emitter) em;
}
@@ -3217,7 +3211,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lrem");
}
- em.mv.visitInsn(Opcodes.LREM);
+ em.cb.lrem();
return (Emitter) em;
}
@@ -3237,7 +3231,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lreturn %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.LRETURN);
+ em.cb.lreturn();
return (Emitter) em;
}
@@ -3258,7 +3252,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lshl");
}
- em.mv.visitInsn(Opcodes.LSHL);
+ em.cb.lshl();
return (Emitter) em;
}
@@ -3279,7 +3273,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lshr");
}
- em.mv.visitInsn(Opcodes.LSHR);
+ em.cb.lshr();
return (Emitter) em;
}
@@ -3299,7 +3293,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lstore %s".formatted(local));
}
- em.mv.visitVarInsn(Opcodes.LSTORE, local.index());
+ em.cb.lstore(local.index());
return (Emitter) em;
}
@@ -3320,7 +3314,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lsub");
}
- em.mv.visitInsn(Opcodes.LSUB);
+ em.cb.lsub();
return (Emitter) em;
}
@@ -3341,7 +3335,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lushr");
}
- em.mv.visitInsn(Opcodes.LUSHR);
+ em.cb.lushr();
return (Emitter) em;
}
@@ -3362,7 +3356,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: lxor");
}
- em.mv.visitInsn(Opcodes.LXOR);
+ em.cb.lxor();
return (Emitter) em;
}
@@ -3381,7 +3375,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: monitorenter");
}
- em.mv.visitInsn(Opcodes.MONITORENTER);
+ em.cb.monitorenter();
return (Emitter) em;
}
@@ -3400,7 +3394,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: monitorexit");
}
- em.mv.visitInsn(Opcodes.MONITOREXIT);
+ em.cb.monitorexit();
return (Emitter) em;
}
@@ -3421,7 +3415,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: multianewarray %s %s".formatted(type, dimensions));
}
- em.mv.visitMultiANewArrayInsn(type.internalName(), dimensions);
+ em.cb.multianewarray(type.classDesc(), dimensions);
return em;
}
@@ -3444,7 +3438,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: new %s".formatted(type));
}
- em.mv.visitTypeInsn(Opcodes.NEW, type.internalName());
+ em.cb.new_(type.classDesc());
return (Emitter) em;
}
@@ -3466,7 +3460,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: newarray %s".formatted(elemType));
}
- em.mv.visitIntInsn(Opcodes.NEWARRAY, elemType.t());
+ em.cb.newarray(elemType.typeKind());
return (Emitter) em;
}
@@ -3482,7 +3476,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: nop");
}
- em.mv.visitInsn(Opcodes.NOP);
+ em.cb.nop();
return em;
}
@@ -3501,7 +3495,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: pop");
}
- em.mv.visitInsn(Opcodes.POP);
+ em.cb.pop();
return (Emitter) em;
}
@@ -3522,7 +3516,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: pop2 (11)");
}
- em.mv.visitInsn(Opcodes.POP2);
+ em.cb.pop2();
return (Emitter) em;
}
@@ -3541,7 +3535,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: pop2 (2)");
}
- em.mv.visitInsn(Opcodes.POP2);
+ em.cb.pop2();
return (Emitter) em;
}
@@ -3571,8 +3565,7 @@ public interface Op {
jvm: putfield %s %s
.%s""".formatted(type, owner, name));
}
- em.mv.visitFieldInsn(Opcodes.PUTFIELD, owner.internalName(), name,
- type.type().getDescriptor());
+ em.cb.putfield(owner.classDesc(), name, type.classDesc());
return (Emitter) em;
}
@@ -3598,8 +3591,7 @@ public interface Op {
jvm: putstatic %s %s
.%s""".formatted(type, owner, name));
}
- em.mv.visitFieldInsn(Opcodes.PUTSTATIC, owner.internalName(), name,
- type.type().getDescriptor());
+ em.cb.putstatic(owner.classDesc(), name, type.classDesc());
return (Emitter) em;
}
@@ -3636,7 +3628,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: return %s".formatted(retReq));
}
- em.mv.visitInsn(Opcodes.RETURN);
+ em.cb.return_();
return (Emitter) em;
}
@@ -3657,7 +3649,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: saload");
}
- em.mv.visitInsn(Opcodes.SALOAD);
+ em.cb.saload();
return (Emitter) em;
}
@@ -3680,7 +3672,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: sastore");
}
- em.mv.visitInsn(Opcodes.SASTORE);
+ em.cb.sastore();
return (Emitter) em;
}
@@ -3702,7 +3694,7 @@ public interface Op {
if (DEEP_TRACE) {
System.err.println(" jvm: swap");
}
- em.mv.visitInsn(Opcodes.SWAP);
+ em.cb.swap();
return (Emitter) em;
}
@@ -3721,7 +3713,6 @@ public interface Op {
N1 extends Next,
N0 extends Ent<N1, TInt>>
Emitter<Dead> tableswitch(Emitter<N0> em, int low, Lbl<N1> dflt, List<Lbl<N1>> cases) {
- int high = low + cases.size() - 1; // inclusive
if (DEEP_TRACE) {
System.err.println(" jvm: tableswitch default=%s cases=[".formatted(dflt));
for (int i = 0; i < cases.size(); i++) {
@@ -3729,8 +3720,11 @@ public interface Op {
}
System.err.println(" ]");
}
- em.mv.visitTableSwitchInsn(low, high, dflt.label(),
- cases.stream().map(Lbl::label).toArray(Label[]::new));
+ List<SwitchCase> switchCases = new ArrayList<>();
+ for (int i = 0; i < cases.size(); i++) {
+ switchCases.add(SwitchCase.of(low + i, cases.get(i).label()));
+ }
+ em.cb.tableswitch(dflt.label(), switchCases);
return (Emitter) em;
}
}
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/RootScope.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/RootScope.java
index 0b38ab20d1..e90e02d454 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/RootScope.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/RootScope.java
@@ -43,7 +43,8 @@ class RootScope<N extends Next> implements Scope {
this.em = (Emitter<N>) em;
this.nextLocal = nextLocal;
- this.start = Lbl.place(this.em).lbl();
+ this.start = Lbl.create(this.em);
+ this.em.cb.labelBinding(this.start.label());
}
@Override
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Types.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Types.java
index dd10497e2b..bf80140b6a 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Types.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/util/Types.java
@@ -15,10 +15,15 @@
*/
package ghidra.pcode.emu.jit.gen.util;
-import org.objectweb.asm.*;
+import java.lang.classfile.TypeKind;
+import java.lang.constant.ClassDesc;
+import java.lang.constant.ConstantDescs;
/**
* A namespace for types describing Java types
+ * <p>
+ * Type descriptors are represented using {@link ClassDesc} from the {@code java.lang.constant}
+ * package (the standard Class-File API), replacing the third-party ASM {@code Type} class.
*/
public interface Types {
/** The {@code void} type */
@@ -59,7 +64,7 @@ public interface Types {
/**
* Create a type describing a reference of the given class (or interface) type
- *
+ *
* @param <T> the type of the Java class
* @param cls the class
* @return the type
@@ -77,17 +82,18 @@ public interface Types {
* any number of classes and methods which support that generation, esp., since this is almost
* always required to describe the type of {@code this}, and {@code this} is frequently accessed
* in generated code. Conventionally, the type variable is called {@code THIS}:
- *
+ *
* <pre>
* class MyGenerator&lt;THIS extends MyIf&gt; {
* private final TRef&lt;THIS&gt; typeThis = refExtends(MyIf.class, generateDesc());
* }
* </pre>
- *
+ *
* @param <ST> the super type
* @param <T> the type variable used to refer to the extension
* @param cls the class of the super type
- * @param desc the internal name of the actual generated extension type
+ * @param desc the JVM type descriptor (e.g., {@code "Lmy/pkg/MyClass;"}) of the actual
+ * generated extension type
* @return the type
*/
static <ST, T extends ST> TRef<T> refExtends(Class<ST> cls, String desc) {
@@ -96,11 +102,11 @@ public interface Types {
/**
* See {@link #refExtends(Class, String)}
- *
+ *
* @param <ST> the super type
* @param <T> the type variable used to refer to the extension
* @param st the super type
- * @param desc the internal name of the actual generated extension type
+ * @param desc the JVM type descriptor of the actual generated extension type
* @return the type
*/
static <ST, T extends ST> TRef<T> refExtends(TRef<ST> st, String desc) {
@@ -113,7 +119,7 @@ public interface Types {
* This is used when the type is only known through reflection, but it is at least known to
* extend some other fixed type. This is best used with a type variable on the method that
* generates code wrt. the reflected class.
- *
+ *
* @param <ST> the super type
* @param <T> the type variable used to refer to the extension
* @param st the super type
@@ -121,7 +127,34 @@ public interface Types {
* @return the type
*/
static <ST, T extends ST> TRef<T> refExtends(TRef<ST> st, Class<?> reflected) {
- return TRef.ofExtends(st.cls, Type.getDescriptor(reflected));
+ return TRef.ofExtends(st.cls,
+ reflected.describeConstable().orElseThrow().descriptorString());
+ }
+
+ /**
+ * See {@link #refExtends(Class, String)}
+ *
+ * @param <ST> the super type
+ * @param <T> the type variable used to refer to the extension
+ * @param cls the super type
+ * @param desc the class descriptor of the actual generated extension type
+ * @return the type
+ */
+ static <ST, T extends ST> TRef<T> refExtends(Class<ST> cls, ClassDesc desc) {
+ return TRef.ofExtends(cls, desc.descriptorString());
+ }
+
+ /**
+ * See {@link #refExtends(Class, String)}
+ *
+ * @param <ST> the super type
+ * @param <T> the type variable used to refer to the extension
+ * @param st the super type
+ * @param desc the class descriptor of the actual generated extension type
+ * @return the type
+ */
+ static <ST, T extends ST> TRef<T> refExtends(TRef<ST> st, ClassDesc desc) {
+ return TRef.ofExtends(st.cls, desc.descriptorString());
}
/**
@@ -131,17 +164,17 @@ public interface Types {
*/
public interface SType {
/**
- * Get the ASM type for this type
- *
- * @return the type
+ * Get the {@link ClassDesc} for this type
+ *
+ * @return the class descriptor
*/
- Type type();
+ ClassDesc classDesc();
/**
* Get the Java class to describe this type
* <p>
* For generated types, this may instead be a suitable super type.
- *
+ *
* @return the class
*/
Class<?> cls();
@@ -159,17 +192,17 @@ public interface Types {
* The primitive types that may be ascribed to a variable in Java source
* <p>
* This is essentially "all non-reference types" as far as Java is concerned.
- *
+ *
* @param <A> the array type for which this primitive is the element type
*/
public interface SPrim<A> extends SNonVoid {
/**
- * The type id, as in {@link MethodVisitor#visitIntInsn(int, int)} for
- * {@link Opcodes#NEWARRAY}, e.g., {@link Opcodes#T_INT}.
- *
- * @return the type id
+ * The {@link TypeKind} for this primitive type, used with
+ * {@link java.lang.classfile.CodeBuilder#newarray(TypeKind)}.
+ *
+ * @return the type kind
*/
- int t();
+ TypeKind typeKind();
}
/**
@@ -181,15 +214,22 @@ public interface Types {
*/
public interface BType extends SType {
@Override
- Type type();
+ ClassDesc classDesc();
/**
- * Get the internal name of the type
- *
+ * Get the internal name of the type (e.g., {@code java.lang.Object})
+ * <p>
+ * This is only meaningful for reference types. For primitive types, the descriptor string
+ * is returned as-is.
+ *
* @return the internal name
*/
default String internalName() {
- return type().getInternalName();
+ String d = classDesc().descriptorString();
+ if (d.startsWith("L") && d.endsWith(";")) {
+ return d.substring(1, d.length() - 1);
+ }
+ return d;
}
}
@@ -207,12 +247,12 @@ public interface Types {
* The primitive types that may be ascribed to local variables in JVM bytecode
* <p>
* This includes only {@code int}, {@code float}, {@code long}, and {@code double}.
- *
+ *
* @param <A> the array type for which this primitive is the element type
*/
public interface BPrim<A> extends BNonVoid, SPrim<A> {
@Override
- int t();
+ TypeKind typeKind();
}
/**
@@ -223,8 +263,8 @@ public interface Types {
INSTANCE;
@Override
- public Type type() {
- return Type.VOID_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_void;
}
@Override
@@ -247,19 +287,19 @@ public interface Types {
/**
* Reference types
- *
+ *
* @param <T> the type
* @param cls the class for the type. For generated types, this may be a super type.
- * @param type the ASM type
+ * @param classDesc the class descriptor
*/
- public record TRef<T>(Class<? super T> cls, Type type) implements TCat1 {
+ public record TRef<T>(Class<? super T> cls, ClassDesc classDesc) implements TCat1 {
static <T> TRef<T> of(Class<T> cls) {
- return new TRef<>(cls, Type.getType(cls));
+ return new TRef<>(cls, cls.describeConstable().orElseThrow());
}
static <ST, T extends ST> TRef<T> ofExtends(Class<ST> cls, String desc) {
- return new TRef<T>(cls, Type.getType(desc));
+ return new TRef<T>(cls, ClassDesc.ofDescriptor(desc));
}
}
@@ -271,13 +311,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_BOOLEAN;
+ public TypeKind typeKind() {
+ return TypeKind.BOOLEAN;
}
@Override
- public Type type() {
- return Type.BOOLEAN_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_boolean;
}
@Override
@@ -294,13 +334,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_BYTE;
+ public TypeKind typeKind() {
+ return TypeKind.BYTE;
}
@Override
- public Type type() {
- return Type.BYTE_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_byte;
}
@Override
@@ -317,13 +357,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_CHAR;
+ public TypeKind typeKind() {
+ return TypeKind.CHAR;
}
@Override
- public Type type() {
- return Type.CHAR_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_char;
}
@Override
@@ -340,13 +380,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_SHORT;
+ public TypeKind typeKind() {
+ return TypeKind.SHORT;
}
@Override
- public Type type() {
- return Type.SHORT_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_short;
}
@Override
@@ -363,13 +403,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_INT;
+ public TypeKind typeKind() {
+ return TypeKind.INT;
}
@Override
- public Type type() {
- return Type.INT_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_int;
}
@Override
@@ -386,13 +426,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_FLOAT;
+ public TypeKind typeKind() {
+ return TypeKind.FLOAT;
}
@Override
- public Type type() {
- return Type.FLOAT_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_float;
}
@Override
@@ -421,13 +461,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_LONG;
+ public TypeKind typeKind() {
+ return TypeKind.LONG;
}
@Override
- public Type type() {
- return Type.LONG_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_long;
}
@Override
@@ -444,13 +484,13 @@ public interface Types {
INSTANCE;
@Override
- public int t() {
- return Opcodes.T_DOUBLE;
+ public TypeKind typeKind() {
+ return TypeKind.DOUBLE;
}
@Override
- public Type type() {
- return Type.DOUBLE_TYPE;
+ public ClassDesc classDesc() {
+ return ConstantDescs.CD_double;
}
@Override
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/ConstValGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/ConstValGen.java
index fc41a44f3e..a7e4c5fe92 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/ConstValGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/ConstValGen.java
@@ -15,10 +15,9 @@
*/
package ghidra.pcode.emu.jit.gen.var;
+import java.lang.classfile.CodeBuilder;
import java.math.BigInteger;
-import org.objectweb.asm.Opcodes;
-
import ghidra.pcode.emu.jit.analysis.JitType.*;
import ghidra.pcode.emu.jit.gen.JitCodeGenerator;
import ghidra.pcode.emu.jit.gen.opnd.Opnd;
@@ -36,7 +35,7 @@ import ghidra.pcode.emu.jit.var.JitConstVal;
*
* <p>
* This can load directly the requested constant as the required JVM type onto the JVM stack. It
- * simply emits an {@link Opcodes#LDC ldc} bytecode.
+ * simply emits an {@link CodeBuilder#ldc ldc} bytecode.
*/
public enum ConstValGen implements ValGen<JitConstVal> {
/** Singleton */
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/LocalVarGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/LocalVarGen.java
index c3929ec76c..7a221dfad5 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/LocalVarGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/LocalVarGen.java
@@ -15,7 +15,7 @@
*/
package ghidra.pcode.emu.jit.gen.var;
-import org.objectweb.asm.Opcodes;
+import java.lang.classfile.CodeBuilder;
import ghidra.pcode.emu.jit.alloc.VarHandler;
import ghidra.pcode.emu.jit.analysis.JitType.MpIntJitType;
@@ -35,8 +35,8 @@ import ghidra.pcode.emu.jit.var.JitVarnodeVar;
*
* <p>
* These variables are presumed to be allocated as JVM locals. The generator emits
- * {@link Opcodes#ILOAD iload} and {@link Opcodes#ISTORE istore} and or depending on the assigned
- * type.
+ * {@link CodeBuilder#iload iload} and {@link CodeBuilder#istore istore} and or depending on the
+ * assigned type.
*
* @param <V> the class of p-code variable node in the use-def graph
*/
diff --git a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/MissingVarGen.java b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/MissingVarGen.java
index 539dc9f545..d65088ad5f 100644
--- a/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/MissingVarGen.java
+++ b/Ghidra/Framework/Emulation/src/main/java/ghidra/pcode/emu/jit/gen/var/MissingVarGen.java
@@ -18,7 +18,7 @@ package ghidra.pcode.emu.jit.gen.var;
import static ghidra.pcode.emu.jit.gen.GenConsts.MDESC_ASSERTION_ERROR__$INIT;
import static ghidra.pcode.emu.jit.gen.GenConsts.T_ASSERTION_ERROR;
-import org.objectweb.asm.Opcodes;
+import java.lang.classfile.CodeBuilder;
import ghidra.pcode.emu.jit.analysis.JitType.MpIntJitType;
import ghidra.pcode.emu.jit.analysis.JitType.SimpleJitType;
@@ -53,8 +53,8 @@ import ghidra.pcode.emu.jit.var.JitMissingVar;
* <p>
* 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
- * {@link Opcodes#NOP nop} and/or {@link Opcodes#ATHROW 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
+ * {@link CodeBuilder#nop nop} and/or {@link CodeBuilder#athrow 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 {@link AssertionError}.
*/
public enum MissingVarGen implements VarGen<JitMissingVar> {
diff --git a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitJvmTypeUtilsTest.java b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitJvmTypeUtilsTest.java
index 3f1826f066..7f9e1265ed 100644
--- a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitJvmTypeUtilsTest.java
+++ b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitJvmTypeUtilsTest.java
@@ -15,15 +15,15 @@
*/
package ghidra.pcode.emu.jit;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.io.InputStream;
+import java.lang.classfile.*;
import java.util.*;
import org.apache.commons.lang3.reflect.TypeLiteral;
import org.junit.Ignore;
import org.junit.Test;
-import org.objectweb.asm.*;
import ghidra.pcode.emu.jit.JitPassage.AddrCtx;
@@ -40,20 +40,19 @@ public class JitJvmTypeUtilsTest {
@Test
public void testTypeToSignature() throws Exception {
Map<String, String> signatures = new HashMap<>();
- String filename = Type.getInternalName(HasFieldTypeSignatures.class) + ".class";
- try (InputStream is = getClass().getClassLoader().getResourceAsStream(filename)) {
- ClassReader cr = new ClassReader(is);
- //ClassNode cn = new ClassNode(Opcodes.ASM9);
- //ClassVisitor trace = new TraceClassVisitor(cn, new PrintWriter(System.out));
- ClassVisitor trace = null;
- cr.accept(new ClassVisitor(Opcodes.ASM9, trace) {
- @Override
- public FieldVisitor visitField(int access, String name, String descriptor,
- String signature, Object value) {
- signatures.put(name, signature);
- return super.visitField(access, filename, descriptor, signature, value);
- }
- }, 0);
+ String internalName =
+ HasFieldTypeSignatures.class.getName().replace('.', '/') + ".class";
+ byte[] bytes;
+ try (InputStream is = getClass().getClassLoader().getResourceAsStream(internalName)) {
+ bytes = is.readAllBytes();
+ }
+ ClassModel cm = ClassFile.of().parse(bytes);
+ for (FieldModel fm : cm.fields()) {
+ String signature = fm.findAttribute(
+ Attributes.signature())
+ .map(sa -> sa.signature().stringValue())
+ .orElse(null);
+ signatures.put(fm.fieldName().stringValue(), signature);
}
assertEquals(signatures.get("RECS"), JitJvmTypeUtils
diff --git a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitMpIntPerformanceExperiment.java b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitMpIntPerformanceExperiment.java
index e160837001..b6ea74b19a 100644
--- a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitMpIntPerformanceExperiment.java
+++ b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/JitMpIntPerformanceExperiment.java
@@ -29,6 +29,7 @@ import ghidra.framework.Application;
import ghidra.framework.ApplicationConfiguration;
import ghidra.pcode.emu.PcodeEmulator;
import ghidra.pcode.emu.PcodeThread;
+import ghidra.pcode.emu.jit.JitConfiguration.Opt;
import ghidra.pcode.exec.DecodePcodeExecutionException;
import ghidra.pcode.exec.PcodeArithmetic.Purpose;
import ghidra.pcode.exec.PcodeExecutorStatePiece.Reason;
@@ -295,8 +296,51 @@ public class JitMpIntPerformanceExperiment {
goto 0xdeadbeef;
""".formatted(N);
- JitPcodeEmulator emu =
- new JitPcodeEmulator(toy, new JitConfiguration(), MethodHandles.lookup());
+ JitPcodeEmulator emu = new JitPcodeEmulator(toy,
+ new JitConfiguration(), MethodHandles.lookup());
+ JitPcodeThread thread = emu.newThread();
+
+ Address address = toy.getDefaultSpace().getAddress(0x00400000);
+ thread.inject(address, sleigh);
+ thread.overrideCounter(address);
+ thread.reInitialize();
+
+ try {
+ thread.run();
+ }
+ catch (DecodePcodeExecutionException e) {
+ if (e.getProgramCounter().getOffset() != 0xdeadbeefL) {
+ throw e;
+ }
+ }
+ System.out.println("fib(%d) = %016x%016x".formatted(N,
+ thread.getArithmetic()
+ .toLong(thread.getState().getVar(toy.getRegister("r1"), Reason.INSPECT),
+ Purpose.INSPECT),
+ thread.getArithmetic()
+ .toLong(thread.getState().getVar(toy.getRegister("r0"), Reason.INSPECT),
+ Purpose.INSPECT)));
+ }
+
+ @Test
+ public void testSpeedJitEmuNoCount() {
+ String sleigh = """
+ counter:4 = 0;
+ prev:16 = 0;
+ curr:16 = 1;
+ <loop>
+ next:16 = prev + curr;
+ prev = curr;
+ curr = next;
+ counter = counter + 1;
+ if (counter < 0x%08x) goto <loop>;
+ r0 = curr(0);
+ r1 = curr(8);
+ goto 0xdeadbeef;
+ """.formatted(N);
+
+ JitPcodeEmulator emu = new JitPcodeEmulator(toy,
+ new JitConfiguration().disable(Opt.EMIT_COUNTERS), MethodHandles.lookup());
JitPcodeThread thread = emu.newThread();
Address address = toy.getDefaultSpace().getAddress(0x00400000);
diff --git a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/EmitterTest.java b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/EmitterTest.java
index 8eefea4188..be56b62137 100644
--- a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/EmitterTest.java
+++ b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/EmitterTest.java
@@ -15,11 +15,13 @@
*/
package ghidra.pcode.emu.jit.gen.util;
+import static java.lang.classfile.ClassFile.ACC_PUBLIC;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.io.PrintStream;
-import java.lang.invoke.*;
+import java.lang.classfile.ClassFile;
+import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.net.URI;
import java.util.ArrayList;
@@ -30,8 +32,6 @@ import javax.tools.Diagnostic.Kind;
import javax.tools.JavaCompiler.CompilationTask;
import org.junit.Test;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
import generic.Unique;
import ghidra.pcode.emu.jit.gen.util.Emitter.*;
@@ -64,48 +64,47 @@ public class EmitterTest<THIS extends Generated> {
}
public void generateAndRun(RunGenerator<THIS, TVoid> gen) throws Throwable {
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
- cw.visit(Opcodes.V21, Opcodes.ACC_PUBLIC, typeThis.internalName(), null,
- T_OBJECT.internalName(), new String[] { T_GENERATED.internalName() });
-
- var paramsInit = new Object() {
- Local<TRef<THIS>> this_;
- };
- var retInit = Emitter.start(typeThis, cw, Opcodes.ACC_PUBLIC, "<init>", MDESC_CONS)
- .param(Def::done, typeThis, l -> paramsInit.this_ = l);
- retInit.em()
- .emit(Op::aload, paramsInit.this_)
- .emit(Op::invokespecial, T_OBJECT, "<init>", MDESC_CONS, false)
- .step(Inv::takeObjRef)
- .step(Inv::retVoid)
- .emit(Op::return_, retInit.ret())
- .emit(Misc::finish);
-
- var paramsRun = new Object() {
- Local<TRef<THIS>> this_;
- };
- var retRun = Emitter.start(typeThis, cw, Opcodes.ACC_PUBLIC, "run", MDESC_RUN)
- .param(Def::done, typeThis, l -> paramsRun.this_ = l);
- retRun.em()
- .emit(gen::gen, paramsRun.this_, retRun.ret())
- .emit(Misc::finish);
-
- cw.visitEnd();
- byte[] classfile = cw.toByteArray();
+ byte[] classfile = ClassFile.of().build(typeThis.classDesc(), clb -> {
+ clb.withFlags(ACC_PUBLIC);
+ clb.withSuperclass(T_OBJECT.classDesc());
+ clb.withInterfaceSymbols(T_GENERATED.classDesc());
+
+ Emitter.instanceWithBody(clb, typeThis, "<init>", MDESC_CONS, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ };
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(Op::aload, p.this_)
+ .emit(Op::invokespecial, T_OBJECT, "<init>", MDESC_CONS, false)
+ .step(Inv::takeObjRef)
+ .step(Inv::retVoid)
+ .emit(Op::return_, spec.ret());
+ });
+
+ Emitter.instanceWithBody(clb, typeThis, "run", MDESC_RUN, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ };
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(gen::gen, p.this_, spec.ret());
+ });
+ });
Lookup lookup = MethodHandles.lookup();
Lookup defLookup = lookup.defineHiddenClass(classfile, true);
@SuppressWarnings("unchecked")
Class<? extends Generated> cls = (Class<? extends Generated>) defLookup.lookupClass();
- MethodHandle constructor =
- defLookup.findConstructor(cls, MethodType.methodType(void.class));
- Generated hw = (Generated) constructor.invoke();
- hw.run();
+ Generated instance = cls.getConstructor().newInstance();
+ instance.run();
}
@Test
public void testHelloWorld() throws Throwable {
- generateAndRun((em, localThis, ret) -> em
+ generateAndRun((em, _, ret) -> em
.emit(Op::getstatic, T_SYSTEM, "out", T_PRINT_STREAM)
.emit(Op::ldc__a, "Hello, World")
.emit(Op::invokevirtual, T_PRINT_STREAM, "println", MDESC_PRINTLN, false)
@@ -117,7 +116,7 @@ public class EmitterTest<THIS extends Generated> {
@Test
public void testArrayLengthPrim() throws Throwable {
- generateAndRun((em, localThis, ret) -> em
+ generateAndRun((em, _, ret) -> em
.emit(Op::ldc__i, 6)
.emit(Op::newarray, Types.T_INT)
.emit(Op::arraylength__prim, Types.T_INT)
@@ -127,7 +126,7 @@ public class EmitterTest<THIS extends Generated> {
@Test
public void testArrayLengthRef() throws Throwable {
- generateAndRun((em, localThis, ret) -> em
+ generateAndRun((em, _, ret) -> em
.emit(Op::ldc__i, 6)
.emit(Op::anewarray, Types.refOf(String.class))
.emit(Op::arraylength__ref)
@@ -160,7 +159,7 @@ public class EmitterTest<THIS extends Generated> {
// @Test // Because it won't actually run. Just a syntax check.
public void syntaxTestAreturn() throws Throwable {
RetReq<TRef<Object>> ret = null;
- generateAndRun((em, localThis, ignore) -> em
+ generateAndRun((em, _, _) -> em
.emit(Op::new_, Types.refOf(String.class))
.emit(Op::areturn, ret));
}
diff --git a/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/MyMethodExample.java b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/MyMethodExample.java
new file mode 100644
index 0000000000..5560037041
--- /dev/null
+++ b/Ghidra/Framework/Emulation/src/test/java/ghidra/pcode/emu/jit/gen/util/MyMethodExample.java
@@ -0,0 +1,104 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.pcode.emu.jit.gen.util;
+
+import static java.lang.classfile.ClassFile.ACC_PUBLIC;
+import static org.junit.Assert.assertEquals;
+
+import java.lang.classfile.ClassFile;
+import java.lang.constant.ClassDesc;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodHandles.Lookup;
+import java.lang.reflect.InvocationTargetException;
+
+import org.junit.Test;
+
+import ghidra.pcode.emu.jit.gen.util.Methods.*;
+import ghidra.pcode.emu.jit.gen.util.Types.TInt;
+import ghidra.pcode.emu.jit.gen.util.Types.TRef;
+
+public class MyMethodExample {
+ interface MyIf { // @start region="MyIf"
+ int myMethod(int a, String b);
+ } // @end region="MyIf"
+
+ @Test
+ public void testExample() {
+ generateClass();
+ }
+
+ <THIS extends MyIf> void generateClass() {
+ TRef<Object> typeObject = Types.refOf(Object.class); // @start region="gen"
+ Lookup lookup = MethodHandles.lookup();
+ String myPackage = lookup.lookupClass().getPackageName();
+ TRef<MyIf> typeMyIf = Types.refOf(MyIf.class);
+ TRef<THIS> typeThis = Types.refExtends(typeMyIf, ClassDesc.of(myPackage, "GeneratedMyIf"));
+ byte[] classbytes = ClassFile.of().build(typeThis.classDesc(), clb -> {
+ clb.withFlags(ACC_PUBLIC);
+ clb.withSuperclass(typeObject.classDesc());
+ clb.withInterfaceSymbols(typeMyIf.classDesc());
+
+ var mdescInit = MthDesc.returns(Types.T_VOID).build();
+ Emitter.instanceWithBody(clb, typeThis, "<init>", mdescInit, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ };
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(Op::aload, p.this_)
+ .emit(Op::invokespecial, typeObject, "<init>", mdescInit, false)
+ .step(Inv::takeObjRef)
+ .step(Inv::retVoid)
+ .emit(Op::return_, spec.ret());
+ });
+
+ var mdescMyMethod = MthDesc.deriveInst(MyIf::myMethod)
+ .check(MthDesc::returns, Types.T_INT)
+ .check(MthDesc::param, Types.T_INT)
+ .check(MthDesc::param, Types.refOf(String.class))
+ .check(MthDesc::build);
+ Emitter.instanceWithBody(clb, typeThis, "myMethod", mdescMyMethod, ACC_PUBLIC, mb -> {
+ var p = new Object() {
+ Local<TRef<THIS>> this_;
+ Local<TInt> a;
+ Local<TRef<String>> b;
+ };
+ var spec = mb.startSpec()
+ .param(Def::param, Types.refOf(String.class), "b", b -> p.b = b)
+ .param(Def::param, Types.T_INT, "a", a -> p.a = a)
+ .param(Def::done, typeThis, t -> p.this_ = t);
+ return spec.em()
+ .emit(Op::iload, p.a)
+ .emit(Op::ldc__i, 10)
+ .emit(Op::imul)
+ .emit(Op::ireturn, spec.ret());
+ });
+ }); // @end region=gen
+ try {
+ Lookup clsLookup = MethodHandles.lookup().defineHiddenClass(classbytes, true);
+ @SuppressWarnings("unchecked")
+ var cls = (Class<? extends MyIf>) clsLookup.lookupClass();
+ MyIf generated = cls.getConstructor().newInstance();
+
+ assertEquals(50, generated.myMethod(5, "Hello"));
+ }
+ catch (IllegalAccessException | InstantiationException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException e) {
+ throw new AssertionError(e);
+ }
+ }
+}
diff --git a/Ghidra/RuntimeScripts/server/server.conf b/Ghidra/RuntimeScripts/server/server.conf
index 924f8a45c3..101b840755 100644
--- a/Ghidra/RuntimeScripts/server/server.conf
+++ b/Ghidra/RuntimeScripts/server/server.conf
@@ -117,6 +117,9 @@ wrapper.java.additional.11=-Ddb.buffers.DataBuffer.compressedOutput=true
# The below line will prevent a warning from being displayed.
wrapper.java.additional.20=--enable-native-access=ALL-UNNAMED
+# Enable compact object headers (JEP 519) to reduce memory footprint
+wrapper.java.additional.21=-XX:+UseCompactObjectHeaders
+
# YAJSW will by default assume a POSIX spawn for Linux and Mac OS X systems, unfortunately it has
# not yet been implemented for Mac OS X. The default process support within YAJSW for Mac OS X is
# broken so we must force the use of BSD process support which appears to work properly. To enable
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/analysis/JitAllocationModelTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/analysis/JitAllocationModelTest.java
index c3f8f20940..1f0b128a27 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/analysis/JitAllocationModelTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/analysis/JitAllocationModelTest.java
@@ -17,12 +17,13 @@ package ghidra.pcode.emu.jit.analysis;
import static org.junit.Assert.assertEquals;
+import java.lang.classfile.ClassFile;
+import java.lang.constant.ClassDesc;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
-import org.objectweb.asm.ClassWriter;
import generic.Unique;
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
@@ -30,7 +31,13 @@ import ghidra.app.plugin.processors.sleigh.SleighLanguageHelper;
import ghidra.pcode.emu.jit.AbstractJitTest;
import ghidra.pcode.emu.jit.alloc.AlignedMpIntHandler;
import ghidra.pcode.emu.jit.analysis.JitType.DoubleJitType;
-import ghidra.pcode.emu.jit.gen.util.Emitter;
+import ghidra.pcode.emu.jit.gen.tgt.JitCompiledPassage;
+import ghidra.pcode.emu.jit.gen.util.*;
+import ghidra.pcode.emu.jit.gen.util.Emitter.Bot;
+import ghidra.pcode.emu.jit.gen.util.Methods.Def;
+import ghidra.pcode.emu.jit.gen.util.Methods.MthDesc;
+import ghidra.pcode.emu.jit.gen.util.Types.TRef;
+import ghidra.pcode.emu.jit.gen.util.Types.TVoid;
import ghidra.pcode.emu.jit.var.JitVar;
import ghidra.pcode.emu.jit.var.JitVarnodeVar;
import ghidra.pcode.exec.*;
@@ -71,57 +78,68 @@ public class JitAllocationModelTest extends AbstractJitTest {
}
@Test
- public void testMultiPrecisionInt() throws Exception {
+ public <THIS extends JitCompiledPassage> void testMultiPrecisionInt() throws Exception {
SleighLanguage language = SleighLanguageHelper.getMockBE64Language();
-
PcodeProgram program = SleighProgramCompiler.compileProgram(language, "test", """
temp:32 = zext(0x1234:2);
goto 0x1234;
""", PcodeUseropLibrary.NIL);
-
JitAnalysisContext context = makeContext(program);
Models m = new Models(context);
-
JitVarnodeVar tempVar = Unique.assertOne(varnodeVars(m.dfm)
.filter(v -> v.varnode().isUnique()));
- ClassWriter cw = new ClassWriter(0);
- Emitter<?> em = Emitter.start(cw.visitMethod(0, "none", "()V", null, null));
- m.am.allocate(em.rootScope());
+ TRef<THIS> typeThis =
+ Types.refExtends(Types.refOf(JitCompiledPassage.class), JitCompiledPassage.class);
+ ClassFile.of().build(ClassDesc.of("Test"), clb -> {
+ MthDesc<TVoid, Bot> mdescVoid = MthDesc.returns(Types.T_VOID).build();
+ Emitter.instanceWithBody(clb, typeThis, "none", mdescVoid, 0, mb -> {
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, Def::ignore);
+ m.am.allocate(spec.em().rootScope());
+ return spec.em()
+ .emit(Op::return_, spec.ret());
+ });
+ });
if (!(m.am.getHandler(tempVar) instanceof AlignedMpIntHandler handler)) {
throw new AssertionFailedError();
}
-
/**
- * TODO: Might like to assert more details, but this mp-int aspect of the JIT-based emulator
- * is still a work in progress.
+ * LATER: Might like to assert more details, but this mp-int aspect of the JIT-based
+ * emulator is still a work in progress.
*/
assertEquals(8, handler.legs().size());
}
@Test
- public void testVarnodeReuse() throws Exception {
+ public <THIS extends JitCompiledPassage> void testVarnodeReuse() throws Exception {
SleighLanguage language = SleighLanguageHelper.getMockBE64Language();
-
PcodeProgram program = SleighProgramCompiler.compileProgram(language, "test", """
r0 = r1 + r2;
r0 = r0 f+ r2;
r0 = r0 f+ r2;
goto 0x1234;
""", PcodeUseropLibrary.NIL);
-
JitAnalysisContext context = makeContext(program);
Models m = new Models(context);
-
List<JitVarnodeVar> r0Vars = varnodeVars(m.dfm)
.filter(v -> v.varnode().toString(language).equals("r0"))
.sorted(Comparator.comparing(JitVar::id))
.toList();
- ClassWriter cw = new ClassWriter(0);
- Emitter<?> em = Emitter.start(cw.visitMethod(0, "none", "()V", null, null));
- m.am.allocate(em.rootScope());
+ TRef<THIS> typeThis =
+ Types.refExtends(Types.refOf(JitCompiledPassage.class), JitCompiledPassage.class);
+ ClassFile.of().build(ClassDesc.of("Test"), clb -> {
+ MthDesc<TVoid, Bot> mdescVoid = MthDesc.returns(Types.T_VOID).build();
+ Emitter.instanceWithBody(clb, typeThis, "none", mdescVoid, 0, mb -> {
+ var spec = mb.startSpec()
+ .param(Def::done, typeThis, Def::ignore);
+ m.am.allocate(spec.em().rootScope());
+ return spec.em()
+ .emit(Op::return_, spec.ret());
+ });
+ });
/**
* NOTE: Variables are coalesced by varnode, so all of these will receive the same handler,
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/gen/AbstractToyJitCodeGeneratorTest.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/gen/AbstractToyJitCodeGeneratorTest.java
index 771bac745a..c134be055b 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/gen/AbstractToyJitCodeGeneratorTest.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/pcode/emu/jit/gen/AbstractToyJitCodeGeneratorTest.java
@@ -15,7 +15,7 @@
*/
package ghidra.pcode.emu.jit.gen;
-import static ghidra.lifecycle.Unfinished.TODO;
+import static ghidra.lifecycle.Unfinished.*;
import static org.junit.Assert.*;
import java.util.List;
diff --git a/build.gradle b/build.gradle
index 706d97f3e4..0bac820bc9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -96,10 +96,10 @@ if (flatRepo.isDirectory()) {
}
}
}
-else {
+else {
File f = file("ghidra.repos.config")
if (!f.exists()) {
- throw new GradleException("\n\n\n\tUnable to find the local maven repo." +
+ throw new GradleException("\n\n\n\tUnable to find the local maven repo." +
" Ensure you have created the ${flatRepo.getName()} directory or ${f.getName()} file.\n\n\n");
}
}
diff --git a/gradle.properties b/gradle.properties
index 506214ca9e..a0d74ce264 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,6 +1,6 @@
# Increase maximum Gradle heap size (default is 1G)
# And fix build in locales with non-default capitalizations (e.g. tr_TR)
-org.gradle.jvmargs=-Xmx2G -Duser.language=en -Duser.country=US
+org.gradle.jvmargs=-Xmx2G -XX:+UseCompactObjectHeaders -Duser.language=en -Duser.country=US
# Preserve file system permissions in archives (Gradle 9 uses fixed permissions by default)
org.gradle.archives.use-file-system-permissions=true
diff --git a/gradle/javadoc.gradle b/gradle/javadoc.gradle
index 8c5ca6c93c..ef3ff4bc5e 100644
--- a/gradle/javadoc.gradle
+++ b/gradle/javadoc.gradle
@@ -25,6 +25,10 @@ rootProject.createJavadocs {
source sourceSets.main.allJava
}
+rootProject.configureJavadocs {
+ snippets.addAll(sourceSets.test.java.srcDirs)
+}
+
rootProject.createJsondocs {
source sourceSets.main.allJava
}
diff --git a/gradle/root/distribution.gradle b/gradle/root/distribution.gradle
index 19fc78a075..b816420510 100644
--- a/gradle/root/distribution.gradle
+++ b/gradle/root/distribution.gradle
@@ -103,9 +103,16 @@ def getGitRev(repoPath) {
* completion of the build.
*
*********************************************************************************/
+tasks.register("configureJavadocs") {
+ ext.snippets = []
+ doLast {
+ tasks.createJavadocs.options.addStringOption "-snippet-path", snippets.join(File.pathSeparator)
+ }
+}
task createJavadocs(type: Javadoc, description: 'Generate javadocs for all projects', group: 'Documentation') {
destinationDir = file(rootProject.projectDir.toString() + "/build/tmp/javadoc")
+ dependsOn configureJavadocs
failOnError = false
@@ -141,7 +148,6 @@ task createJavadocs(type: Javadoc, description: 'Generate javadocs for all proje
]
}
-
/*********************************************************************************
* JSONDOCS - RAW
*