mirror of
https://github.com/GTNewHorizons/ForgeMultipart.git
synced 2026-11-21 12:42:51 +00:00
refactor: port StackAnalyser control flow to Java
This commit is contained in:
1 parent
a6aca65dac
commit
3b5256aedd
4 files changed
+417
-184
No files matched your search
@@ -1378,3 +1378,30 @@ generated-trait compatibility work. Scala-runtime removal remains a later projec
|
||||
Formatting/checkstyle/build and the Forge suite pass; all 39 generated dump hashes and the dev config are unchanged.
|
||||
No production ABI, source counts or next target changed. `multipart/asm/StackAnalyser.scala` remains next, using
|
||||
explicit migration-test authorization and separate characterization and refactor commits.
|
||||
- Characterized `StackAnalyser` against untouched Scala in 15 plain-JVM tests, committed separately as `a6aca65`.
|
||||
The baseline build passed 320 JVM tests and the Forge suite passed 122. The new tests exercise receiver/parameter
|
||||
initialization, narrow/wide slot aliases, partial failures, every duplication opcode, typed constants, case-class
|
||||
equality/copy/products, instruction provenance, loads/stores/increments, arithmetic/casts, arrays, fields, calls,
|
||||
branches/switches/returns, handler precedence, unsupported-node behavior and overridable default-argument dispatch.
|
||||
- Extracted analyser control flow (`setL`, `pop`, `insert`, `popArgs`, `visitInsn`) into package-private Java
|
||||
`StackAnalyserLogic`. The Scala shell retains construction/state, default-argument bridges, simple accessors and
|
||||
the complete nested model. An isolated Scala 2.11.5 probe rejects a Java class alongside its same-name Scala
|
||||
companion; completing the model requires a coordinated class/companion conversion rather than replacing the class
|
||||
independently. The retained `ScalaSignature` model and its primitive/erased bridges are untouched.
|
||||
- Preserved current opcode behavior, including wide `DUP2` expansion, int-conversion/comparison/`INSTANCEOF` result
|
||||
types, reference-array descriptor construction, reversed multidimensional size capture and `NEWARRAY`'s existing
|
||||
`MatchError`. Virtual calls still use the Scala default-argument getters. No compiler algorithm, optimization or
|
||||
unrelated bug fix is included.
|
||||
- Saved the pre-port dev jar, Scala source, test reports and generated dumps under ignored
|
||||
`run/migration-stack-analyser-reference/`. All 40 named analyser surfaces match by member name, descriptor,
|
||||
modifiers, generic declarations and private fields; the other 39 named model/companion classfiles are byte-identical,
|
||||
preserving their serialized and Scala-facing behavior. All 199 retained ASM/generator disassemblies and all 39
|
||||
generated dump names/hashes match. An additional one-off comparison of 8,960 opcode/node/stack combinations matches
|
||||
expression trees, types, aliases, instruction bindings, locals, exceptions and partial mutation.
|
||||
- Formatting/checkstyle/build and Forge pass, including a clean build after stopping Gradle: 320 JVM / 122 Forge
|
||||
tests, zero failures/errors/skips. All characterization tests remain unchanged after the port. The forced Scala
|
||||
compilation version guard is retained, and all five `@Mod` version annotations match both clean packaged jars.
|
||||
Two unreferenced traversal closures become one Java helper (452 to 451 packaged classes); sources now total 207
|
||||
Java files and 9 Scala files / 1,726 nonblank Scala lines. No new compatibility divergence is introduced. Next is
|
||||
`ASMMixinCompiler.scala`, bounded to `ClassInfo`/`MethodInfo` metadata lookup and traversal, with fresh characterization
|
||||
before touching its Forge-initialized state and no trait-rewriting algorithm changes.
|
||||
@@ -12,8 +12,8 @@ what breaks, and what is left. The other documents hold the reasoning.
|
||||
| `JAVA_MIGRATION_MANUAL_CHECKS.md` | What no automated test can cover, and must be checked by hand in a client |
|
||||
| `JAVA_MIGRATION_PROFILE.md` | The focused baseline, first measured result, findings, and exact rerun command |
|
||||
|
||||
Branch: `algent/java`. Base: `master`. 172 commits including the API-cleanup plan, divergence-log cleanup, ports
|
||||
through the `ScalaSignature` parser extraction, and its characterization backfill and review fixes.
|
||||
Branch: `algent/java`. Base: `master`. 174 commits including the API-cleanup plan, divergence-log cleanup, ports
|
||||
through the `StackAnalyser` control-flow extraction, and the ASM characterization backfill and review fixes.
|
||||
|
||||
## The one rule that matters
|
||||
|
||||
@@ -74,7 +74,7 @@ awk -F'"' '/<testsuite /{t+=$4;f+=$8;e+=$10} END{print "tests="t" failures="f" e
|
||||
grep -o 'tests="[0-9]*" skipped="[0-9]*" failures="[0-9]*" errors="[0-9]*"' run/server/junit-out/TEST-*.xml
|
||||
```
|
||||
|
||||
Current baseline: **305 plain-JVM tests and 122 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
Current baseline: **320 plain-JVM tests and 122 Java 8 Forge dedicated-server tests passing.** The ignored local server
|
||||
EULA is accepted in this checkout. GitHub Actions runs the same self-validating Forge suite in a dependent job after
|
||||
the shared GTNH build; keep both jobs required.
|
||||
|
||||
@@ -280,7 +280,7 @@ across the port. It is also where the two shim constraints in the gotchas list w
|
||||
`rayTraceAll`'s index production is now characterized, closing the gap the read-path cleanup left: the index written
|
||||
into `ExtendedMOP.data` is what `reduceMOP` hands back to every click, activate, harvest and pick block.
|
||||
|
||||
206 Java files, 9 Scala files, 1,883 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
207 Java files, 9 Scala files, 1,726 Scala lines left (non-blank; that is the metric this figure has always used).
|
||||
|
||||
## What is left, and in what order
|
||||
|
||||
@@ -632,11 +632,33 @@ is `MultipartMixinFactory`'s facade method set, which is the ledger's four addit
|
||||
were relaxed to hold on both trees: the facade private constructors Scala never emitted, and `DebugPrinter$`'s
|
||||
directory cleanup, which Scala emitted as a separate closure class.
|
||||
|
||||
**Next: `multipart/asm/StackAnalyser.scala`.** Treat its analyser control flow and nested model separately if the same
|
||||
Java-source limitations appear. Preserve every nested binary name, constructor, outer/implicit instruction binding,
|
||||
case-class surface, mutable Scala collection descriptor and the current opcode behavior (including its existing
|
||||
primitive-cast and `NEWARRAY` limitations). Keep `ASMMixinCompiler` algorithms unchanged and compare all generated
|
||||
dumps against a saved reference.
|
||||
`StackAnalyser` control flow is now implemented in package-private Java `StackAnalyserLogic`. Fifteen plain-JVM
|
||||
characterization tests passed on untouched Scala and were committed separately as `a6aca65`. They freeze slot/local
|
||||
aliasing and partial mutation, expression trees, instruction identity, case-class equality/copy/product behavior,
|
||||
argument/dimension order, handlers, unsupported opcodes and virtual/default-argument dispatch. The same tests pass
|
||||
unchanged after extraction; no new Forge-specific fixture is needed for this isolated logic.
|
||||
|
||||
The Scala shell retains construction, fields/accessors, default arguments, width helpers and all nested model types.
|
||||
A Scala 2.11.5 compiler probe rejects a Java class alongside its same-name Scala object, so replacing the shell alone
|
||||
would break the retained companion/model boundary. A future full source port needs a coordinated class/companion/model
|
||||
conversion, including case-class and serialization surfaces; this is separate from the `ScalaSignature` primitive
|
||||
bridge limitation. All 40 named analyser APIs (including private fields, flags and generic signatures) match, and all
|
||||
39 model/companion classfiles are byte-identical. The original cast, comparison, `INSTANCEOF`, wide-duplication,
|
||||
reference-array descriptor and primitive `NEWARRAY` quirks remain; compiler fixes are separate work.
|
||||
|
||||
The reference jar, source, 39 generated dumps, test reports, clean logs and comparison scripts are saved locally under
|
||||
ignored `run/migration-stack-analyser-reference/` (outside `build`, so `clean` preserves them). Clean build and Forge
|
||||
verification pass at 320 JVM / 122 Forge, with no skips. All 39 dump names/hashes match; 199 retained ASM/generator
|
||||
disassemblies are unchanged; 8,960 additional paired instruction cases match. Two private traversal closures are
|
||||
replaced by the Java helper, taking the packaged inventory from 452 to 451. The forced Scala compilation guard is
|
||||
unchanged; both clean jars have all five `@Mod` annotations matching their packaged version. No new divergence entry
|
||||
is needed.
|
||||
|
||||
**Next: `multipart/asm/ASMMixinCompiler.scala`, bounded to `ClassInfo`/`MethodInfo` metadata lookup and traversal.**
|
||||
Characterize hierarchy order, lazy traversal, public implementation selection and lookup/cache behavior first, using
|
||||
Forge where the compiler's `LaunchClassLoader` initialization requires it. Keep trait registration/rewriting algorithms,
|
||||
external Scala-trait support, retained `StackAnalyser` model and `ScalaSignature` primitive/erased bridges unchanged.
|
||||
Save a fresh reference and compare generated dumps again before expanding the compiler scope.
|
||||
The remaining generated microblock traits still need the Phase 7 abstract-Java-mixin and side-only-member support
|
||||
before their Java mixin inputs are safe; do not bypass those prerequisites by flattening their inheritance.
|
||||
|
||||
|
||||
@@ -132,189 +132,23 @@ class StackAnalyser(val owner: Type, val m: MethodNode) {
|
||||
|
||||
def pushL(entry: LocalEntry) = setL(locals.size, entry)
|
||||
|
||||
def setL(i: Int, entry: LocalEntry) = {
|
||||
while (i + entry.getType.getSize > locals.size) locals += null
|
||||
locals(i) = entry
|
||||
if (entry.getType.getSize == 2)
|
||||
locals(i + 1) = entry
|
||||
}
|
||||
def setL(i: Int, entry: LocalEntry): Unit =
|
||||
StackAnalyserLogic.setL(this, i, entry)
|
||||
|
||||
def push(entry: StackEntry) = insert(0, entry)
|
||||
|
||||
def _pop(i: Int = 0) = stack.remove(stack.size - i - 1)
|
||||
|
||||
def pop(i: Int = 0) = {
|
||||
val e = _pop(i)
|
||||
if (e.getType.getSize == 2) {
|
||||
if (peek(i) != e)
|
||||
throw new IllegalStateException(
|
||||
"Wide stack entry elems don't match (" + e + "," + peek(i)
|
||||
)
|
||||
_pop(i)
|
||||
}
|
||||
e
|
||||
}
|
||||
def pop(i: Int = 0): StackEntry = StackAnalyserLogic.pop(this, i)
|
||||
|
||||
def peek(i: Int = 0) = stack(stack.size - i - 1)
|
||||
|
||||
def insert(i: Int, entry: StackEntry) {
|
||||
if (entry.getType.getSize == 0)
|
||||
return
|
||||
stack.insert(stack.size - i, entry)
|
||||
if (entry.getType.getSize == 2)
|
||||
stack.insert(stack.size - i, entry)
|
||||
}
|
||||
def insert(i: Int, entry: StackEntry): Unit =
|
||||
StackAnalyserLogic.insert(this, i, entry)
|
||||
|
||||
def popArgs(desc: String) = {
|
||||
val t = getType(desc)
|
||||
val args = new Array[StackEntry](t.getArgumentTypes.length)
|
||||
for (i <- 0 until args.length)
|
||||
args(args.length - i - 1) = pop()
|
||||
args
|
||||
}
|
||||
def popArgs(desc: String): Array[StackEntry] =
|
||||
StackAnalyserLogic.popArgs(this, desc)
|
||||
|
||||
def visitInsn(ainsn: AbstractInsnNode) {
|
||||
implicit val thisInsn = ainsn // passes to any StackEntry we create
|
||||
ainsn match {
|
||||
case insn: InsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case ACONST_NULL => push(Const(null))
|
||||
case ICONST_M1 => push(Const(-1))
|
||||
case ICONST_0 => push(Const(0))
|
||||
case ICONST_1 => push(Const(1))
|
||||
case ICONST_2 => push(Const(2))
|
||||
case ICONST_3 => push(Const(3))
|
||||
case ICONST_4 => push(Const(4))
|
||||
case ICONST_5 => push(Const(5))
|
||||
case LCONST_0 => push(Const(0L))
|
||||
case LCONST_1 => push(Const(1L))
|
||||
case FCONST_0 => push(Const(0f))
|
||||
case FCONST_1 => push(Const(1f))
|
||||
case FCONST_2 => push(Const(2f))
|
||||
case DCONST_0 => push(Const(0d))
|
||||
case DCONST_1 => push(Const(1d))
|
||||
|
||||
case i if i >= IALOAD && i <= SALOAD =>
|
||||
push(ArrayLoad(pop(), pop()))
|
||||
case i if i >= IASTORE && i <= SASTORE =>
|
||||
pop(); pop(); pop()
|
||||
|
||||
case POP => _pop()
|
||||
case POP2 => _pop(); _pop()
|
||||
case DUP => push(peek())
|
||||
case DUP_X1 => insert(2, peek())
|
||||
case DUP_X2 => insert(3, peek())
|
||||
case DUP2 => push(peek(1)); push(peek(1))
|
||||
case DUP2_X1 => insert(3, peek(1)); insert(3, peek())
|
||||
case DUP2_X2 => insert(4, peek(1)); insert(4, peek())
|
||||
case SWAP => push(pop(1))
|
||||
|
||||
case i if i >= IADD && i <= DREM =>
|
||||
push(BinaryOp(i, pop(), pop()))
|
||||
case i if i >= INEG && i <= DNEG =>
|
||||
push(UnaryOp(i, pop()))
|
||||
case i if i >= ISHL && i <= LXOR =>
|
||||
push(BinaryOp(i, pop(), pop()))
|
||||
|
||||
case L2I | F2I | D2I => push(PrimitiveCast(pop(), DOUBLE_TYPE))
|
||||
case I2L | F2L | D2L => push(PrimitiveCast(pop(), LONG_TYPE))
|
||||
case I2F | L2F | D2F => push(PrimitiveCast(pop(), FLOAT_TYPE))
|
||||
case I2D | L2D | F2D => push(PrimitiveCast(pop(), DOUBLE_TYPE))
|
||||
case I2B => push(PrimitiveCast(pop(), BYTE_TYPE))
|
||||
case I2C => push(PrimitiveCast(pop(), CHAR_TYPE))
|
||||
case I2S => push(PrimitiveCast(pop(), SHORT_TYPE))
|
||||
|
||||
case i if i >= LCMP && i <= DCMPG =>
|
||||
push(BinaryOp(i, pop(), pop()))
|
||||
|
||||
case i if i >= IRETURN && i <= ARETURN => pop()
|
||||
|
||||
case ARRAYLENGTH => push(ArrayLength(pop()))
|
||||
case ATHROW => pop()
|
||||
case MONITORENTER | MONITOREXIT => pop()
|
||||
|
||||
case _ =>
|
||||
|
||||
}
|
||||
case iinsn: IntInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case BIPUSH => push(Const(iinsn.operand.toByte))
|
||||
case SIPUSH => push(Const(iinsn.operand.toShort))
|
||||
}
|
||||
case ldcinsn: LdcInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case LDC => push(Const(ldcinsn.cst))
|
||||
}
|
||||
case vinsn: VarInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case i if i >= ILOAD && i <= ALOAD =>
|
||||
push(Load(locals(vinsn.`var`)))
|
||||
case i if i >= ISTORE && i <= ASTORE =>
|
||||
setL(vinsn.`var`, Store(pop()))
|
||||
}
|
||||
case incinsn: IincInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case IINC =>
|
||||
setL(
|
||||
incinsn.`var`,
|
||||
Store(
|
||||
BinaryOp(IINC, Const(incinsn.incr), Load(locals(incinsn.`var`)))
|
||||
)
|
||||
)
|
||||
}
|
||||
case jinsn: JumpInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case i if i >= IFEQ && i <= IFLE => pop()
|
||||
case i if i >= IF_ICMPEQ && i <= IF_ACMPNE => pop(); pop()
|
||||
case JSR => push(ReturnAddress())
|
||||
case IFNULL | IFNONNULL => pop()
|
||||
case GOTO =>
|
||||
}
|
||||
case sinsn: TableSwitchInsnNode => pop()
|
||||
case linsn: LookupSwitchInsnNode => pop()
|
||||
case finsn: FieldInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case GETSTATIC => push(GetField(null, finsn))
|
||||
case PUTSTATIC => pop()
|
||||
case GETFIELD => push(GetField(pop(), finsn))
|
||||
case PUTFIELD => pop(); pop()
|
||||
}
|
||||
case minsn: MethodInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case INVOKEVIRTUAL | INVOKESPECIAL | INVOKEINTERFACE =>
|
||||
push(Invoke(ainsn.getOpcode, popArgs(minsn.desc), pop(), minsn))
|
||||
case INVOKESTATIC =>
|
||||
push(Invoke(ainsn.getOpcode, popArgs(minsn.desc), null, minsn))
|
||||
}
|
||||
case tinsn: TypeInsnNode =>
|
||||
ainsn.getOpcode match {
|
||||
case NEW => push(New(getObjectType(tinsn.desc)))
|
||||
case NEWARRAY => push(NewArray(pop(), getObjectType(tinsn.desc)))
|
||||
case ANEWARRAY =>
|
||||
push(NewArray(pop(), getObjectType("[" + tinsn.desc)))
|
||||
case CHECKCAST => push(Cast(pop(), getObjectType(tinsn.desc)))
|
||||
case INSTANCEOF => push(UnaryOp(INSTANCEOF, pop()))
|
||||
}
|
||||
case mainsn: MultiANewArrayInsnNode =>
|
||||
val sizes = new Array[StackEntry](mainsn.dims)
|
||||
for (i <- 0 until sizes.length)
|
||||
sizes(i) = pop()
|
||||
push(NewMultiArray(sizes, getType(mainsn.desc)))
|
||||
/*case fnode:FrameNode => fnode.`type` match
|
||||
{
|
||||
case F_NEW|F_FULL => println("reset stacks/locals")
|
||||
case F_APPEND => println("add local")
|
||||
case F_CHOP => println("rem locals")
|
||||
case F_SAME => println("reset")
|
||||
case F_SAME1 => println("reset locals and all but bottom stack")
|
||||
}*/
|
||||
case lnode: LabelNode =>
|
||||
catchHandlers.get(lnode) match {
|
||||
case Some(tcblock) =>
|
||||
push(CaughtException(Type.getType(tcblock.`type`)))
|
||||
case None =>
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
def visitInsn(ainsn: AbstractInsnNode): Unit =
|
||||
StackAnalyserLogic.visitInsn(this, ainsn)
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
package codechicken.multipart.asm;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
import static org.objectweb.asm.Type.*;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.IincInsnNode;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.IntInsnNode;
|
||||
import org.objectweb.asm.tree.JumpInsnNode;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.LdcInsnNode;
|
||||
import org.objectweb.asm.tree.LookupSwitchInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
|
||||
import org.objectweb.asm.tree.TableSwitchInsnNode;
|
||||
import org.objectweb.asm.tree.TryCatchBlockNode;
|
||||
import org.objectweb.asm.tree.TypeInsnNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import codechicken.multipart.asm.StackAnalyser.ArrayLength;
|
||||
import codechicken.multipart.asm.StackAnalyser.ArrayLoad;
|
||||
import codechicken.multipart.asm.StackAnalyser.BinaryOp;
|
||||
import codechicken.multipart.asm.StackAnalyser.Cast;
|
||||
import codechicken.multipart.asm.StackAnalyser.CaughtException;
|
||||
import codechicken.multipart.asm.StackAnalyser.Const;
|
||||
import codechicken.multipart.asm.StackAnalyser.GetField;
|
||||
import codechicken.multipart.asm.StackAnalyser.Invoke;
|
||||
import codechicken.multipart.asm.StackAnalyser.Load;
|
||||
import codechicken.multipart.asm.StackAnalyser.LocalEntry;
|
||||
import codechicken.multipart.asm.StackAnalyser.New;
|
||||
import codechicken.multipart.asm.StackAnalyser.NewArray;
|
||||
import codechicken.multipart.asm.StackAnalyser.NewMultiArray;
|
||||
import codechicken.multipart.asm.StackAnalyser.PrimitiveCast;
|
||||
import codechicken.multipart.asm.StackAnalyser.ReturnAddress;
|
||||
import codechicken.multipart.asm.StackAnalyser.StackEntry;
|
||||
import codechicken.multipart.asm.StackAnalyser.Store;
|
||||
import codechicken.multipart.asm.StackAnalyser.UnaryOp;
|
||||
import scala.MatchError;
|
||||
import scala.None$;
|
||||
import scala.Option;
|
||||
import scala.Predef;
|
||||
import scala.Some;
|
||||
|
||||
/** Analyser control flow behind the retained Scala model and default-argument API. */
|
||||
final class StackAnalyserLogic {
|
||||
|
||||
private StackAnalyserLogic() {}
|
||||
|
||||
static void setL(StackAnalyser a, int i, LocalEntry entry) {
|
||||
while (i + entry.getType().getSize() > a.locals().size()) a.locals().$plus$eq(null);
|
||||
a.locals().update(i, entry);
|
||||
if (entry.getType().getSize() == 2) a.locals().update(i + 1, entry);
|
||||
}
|
||||
|
||||
static StackEntry pop(StackAnalyser a, int i) {
|
||||
StackEntry entry = a._pop(i);
|
||||
if (entry.getType().getSize() == 2) {
|
||||
StackEntry other = a.peek(i);
|
||||
if (!(other == null ? entry == null : other.equals(entry))) {
|
||||
throw new IllegalStateException("Wide stack entry elems don't match (" + entry + "," + a.peek(i));
|
||||
}
|
||||
a._pop(i);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
static void insert(StackAnalyser a, int i, StackEntry entry) {
|
||||
if (entry.getType().getSize() == 0) return;
|
||||
a.stack().insert(a.stack().size() - i, Predef.wrapRefArray(new StackEntry[] { entry }));
|
||||
if (entry.getType().getSize() == 2) {
|
||||
a.stack().insert(a.stack().size() - i, Predef.wrapRefArray(new StackEntry[] { entry }));
|
||||
}
|
||||
}
|
||||
|
||||
static StackEntry[] popArgs(StackAnalyser a, String desc) {
|
||||
StackEntry[] args = new StackEntry[getType(desc).getArgumentTypes().length];
|
||||
for (int i = 0; i < args.length; i++) args[args.length - i - 1] = pop(a);
|
||||
return args;
|
||||
}
|
||||
|
||||
// These calls must retain virtual dispatch through Scala's default-argument getters.
|
||||
private static StackEntry pop(StackAnalyser a) {
|
||||
return a.pop(a.pop$default$1());
|
||||
}
|
||||
|
||||
private static StackEntry peek(StackAnalyser a) {
|
||||
return a.peek(a.peek$default$1());
|
||||
}
|
||||
|
||||
private static void rawPop(StackAnalyser a) {
|
||||
a._pop(a._pop$default$1());
|
||||
}
|
||||
|
||||
static void visitInsn(StackAnalyser a, AbstractInsnNode insn) {
|
||||
if (insn instanceof InsnNode) {
|
||||
int op = insn.getOpcode();
|
||||
switch (op) {
|
||||
case ACONST_NULL:
|
||||
a.push(new Const(null, insn));
|
||||
break;
|
||||
case ICONST_M1:
|
||||
a.push(new Const(-1, insn));
|
||||
break;
|
||||
case ICONST_0:
|
||||
a.push(new Const(0, insn));
|
||||
break;
|
||||
case ICONST_1:
|
||||
a.push(new Const(1, insn));
|
||||
break;
|
||||
case ICONST_2:
|
||||
a.push(new Const(2, insn));
|
||||
break;
|
||||
case ICONST_3:
|
||||
a.push(new Const(3, insn));
|
||||
break;
|
||||
case ICONST_4:
|
||||
a.push(new Const(4, insn));
|
||||
break;
|
||||
case ICONST_5:
|
||||
a.push(new Const(5, insn));
|
||||
break;
|
||||
case LCONST_0:
|
||||
a.push(new Const(0L, insn));
|
||||
break;
|
||||
case LCONST_1:
|
||||
a.push(new Const(1L, insn));
|
||||
break;
|
||||
case FCONST_0:
|
||||
a.push(new Const(0f, insn));
|
||||
break;
|
||||
case FCONST_1:
|
||||
a.push(new Const(1f, insn));
|
||||
break;
|
||||
case FCONST_2:
|
||||
a.push(new Const(2f, insn));
|
||||
break;
|
||||
case DCONST_0:
|
||||
a.push(new Const(0d, insn));
|
||||
break;
|
||||
case DCONST_1:
|
||||
a.push(new Const(1d, insn));
|
||||
break;
|
||||
case POP:
|
||||
rawPop(a);
|
||||
break;
|
||||
case POP2:
|
||||
rawPop(a);
|
||||
rawPop(a);
|
||||
break;
|
||||
case DUP:
|
||||
a.push(peek(a));
|
||||
break;
|
||||
case DUP_X1:
|
||||
a.insert(2, peek(a));
|
||||
break;
|
||||
case DUP_X2:
|
||||
a.insert(3, peek(a));
|
||||
break;
|
||||
case DUP2:
|
||||
a.push(a.peek(1));
|
||||
a.push(a.peek(1));
|
||||
break;
|
||||
case DUP2_X1:
|
||||
a.insert(3, a.peek(1));
|
||||
a.insert(3, peek(a));
|
||||
break;
|
||||
case DUP2_X2:
|
||||
a.insert(4, a.peek(1));
|
||||
a.insert(4, peek(a));
|
||||
break;
|
||||
case SWAP:
|
||||
a.push(a.pop(1));
|
||||
break;
|
||||
// Preserve the reference's inferred types, including conversions to int reporting double.
|
||||
case L2I:
|
||||
case F2I:
|
||||
case D2I:
|
||||
a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
|
||||
break;
|
||||
case I2L:
|
||||
case F2L:
|
||||
case D2L:
|
||||
a.push(new PrimitiveCast(pop(a), LONG_TYPE, insn));
|
||||
break;
|
||||
case I2F:
|
||||
case L2F:
|
||||
case D2F:
|
||||
a.push(new PrimitiveCast(pop(a), FLOAT_TYPE, insn));
|
||||
break;
|
||||
case I2D:
|
||||
case L2D:
|
||||
case F2D:
|
||||
a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
|
||||
break;
|
||||
case I2B:
|
||||
a.push(new PrimitiveCast(pop(a), BYTE_TYPE, insn));
|
||||
break;
|
||||
case I2C:
|
||||
a.push(new PrimitiveCast(pop(a), CHAR_TYPE, insn));
|
||||
break;
|
||||
case I2S:
|
||||
a.push(new PrimitiveCast(pop(a), SHORT_TYPE, insn));
|
||||
break;
|
||||
case ARRAYLENGTH:
|
||||
a.push(new ArrayLength(pop(a), insn));
|
||||
break;
|
||||
case ATHROW:
|
||||
case MONITORENTER:
|
||||
case MONITOREXIT:
|
||||
pop(a);
|
||||
break;
|
||||
default:
|
||||
if (op >= IALOAD && op <= SALOAD) {
|
||||
a.push(new ArrayLoad(pop(a), pop(a), insn));
|
||||
} else if (op >= IASTORE && op <= SASTORE) {
|
||||
pop(a);
|
||||
pop(a);
|
||||
pop(a);
|
||||
} else if (op >= IADD && op <= DREM || op >= ISHL && op <= LXOR || op >= LCMP && op <= DCMPG) {
|
||||
a.push(new BinaryOp(op, pop(a), pop(a), insn));
|
||||
} else if (op >= INEG && op <= DNEG) {
|
||||
a.push(new UnaryOp(op, pop(a), insn));
|
||||
} else if (op >= IRETURN && op <= ARETURN) {
|
||||
pop(a);
|
||||
}
|
||||
}
|
||||
} else if (insn instanceof IntInsnNode) {
|
||||
IntInsnNode intInsn = (IntInsnNode) insn;
|
||||
switch (insn.getOpcode()) {
|
||||
case BIPUSH:
|
||||
a.push(new Const((byte) intInsn.operand, insn));
|
||||
break;
|
||||
case SIPUSH:
|
||||
a.push(new Const((short) intInsn.operand, insn));
|
||||
break;
|
||||
default:
|
||||
throw new MatchError(insn.getOpcode());
|
||||
}
|
||||
} else if (insn instanceof LdcInsnNode) {
|
||||
if (insn.getOpcode() != LDC) throw new MatchError(insn.getOpcode());
|
||||
a.push(new Const(((LdcInsnNode) insn).cst, insn));
|
||||
} else if (insn instanceof VarInsnNode) {
|
||||
VarInsnNode varInsn = (VarInsnNode) insn;
|
||||
int op = insn.getOpcode();
|
||||
if (op >= ILOAD && op <= ALOAD) {
|
||||
a.push(new Load(a.locals().apply(varInsn.var), insn));
|
||||
} else if (op >= ISTORE && op <= ASTORE) {
|
||||
a.setL(varInsn.var, new Store(pop(a), insn));
|
||||
} else {
|
||||
throw new MatchError(op);
|
||||
}
|
||||
} else if (insn instanceof IincInsnNode) {
|
||||
IincInsnNode incInsn = (IincInsnNode) insn;
|
||||
if (insn.getOpcode() != IINC) throw new MatchError(insn.getOpcode());
|
||||
a.setL(
|
||||
incInsn.var,
|
||||
new Store(
|
||||
new BinaryOp(
|
||||
IINC,
|
||||
new Const(incInsn.incr, insn),
|
||||
new Load(a.locals().apply(incInsn.var), insn),
|
||||
insn),
|
||||
insn));
|
||||
} else if (insn instanceof JumpInsnNode) {
|
||||
int op = insn.getOpcode();
|
||||
if (op >= IFEQ && op <= IFLE || op == IFNULL || op == IFNONNULL) {
|
||||
pop(a);
|
||||
} else if (op >= IF_ICMPEQ && op <= IF_ACMPNE) {
|
||||
pop(a);
|
||||
pop(a);
|
||||
} else if (op == JSR) {
|
||||
a.push(new ReturnAddress(insn));
|
||||
} else if (op != GOTO) {
|
||||
throw new MatchError(op);
|
||||
}
|
||||
} else if (insn instanceof TableSwitchInsnNode || insn instanceof LookupSwitchInsnNode) {
|
||||
pop(a);
|
||||
} else if (insn instanceof FieldInsnNode) {
|
||||
FieldInsnNode field = (FieldInsnNode) insn;
|
||||
switch (insn.getOpcode()) {
|
||||
case GETSTATIC:
|
||||
a.push(new GetField(null, field, insn));
|
||||
break;
|
||||
case PUTSTATIC:
|
||||
pop(a);
|
||||
break;
|
||||
case GETFIELD:
|
||||
a.push(new GetField(pop(a), field, insn));
|
||||
break;
|
||||
case PUTFIELD:
|
||||
pop(a);
|
||||
pop(a);
|
||||
break;
|
||||
default:
|
||||
throw new MatchError(insn.getOpcode());
|
||||
}
|
||||
} else if (insn instanceof MethodInsnNode) {
|
||||
MethodInsnNode method = (MethodInsnNode) insn;
|
||||
switch (insn.getOpcode()) {
|
||||
case INVOKEVIRTUAL:
|
||||
case INVOKESPECIAL:
|
||||
case INVOKEINTERFACE:
|
||||
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), pop(a), method, insn));
|
||||
break;
|
||||
case INVOKESTATIC:
|
||||
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), null, method, insn));
|
||||
break;
|
||||
default:
|
||||
throw new MatchError(insn.getOpcode());
|
||||
}
|
||||
} else if (insn instanceof TypeInsnNode) {
|
||||
TypeInsnNode typeInsn = (TypeInsnNode) insn;
|
||||
switch (insn.getOpcode()) {
|
||||
case NEW:
|
||||
a.push(new New(getObjectType(typeInsn.desc), insn));
|
||||
break;
|
||||
case NEWARRAY:
|
||||
a.push(new NewArray(pop(a), getObjectType(typeInsn.desc), insn));
|
||||
break;
|
||||
case ANEWARRAY:
|
||||
a.push(new NewArray(pop(a), getObjectType("[" + typeInsn.desc), insn));
|
||||
break;
|
||||
case CHECKCAST:
|
||||
a.push(new Cast(pop(a), getObjectType(typeInsn.desc), insn));
|
||||
break;
|
||||
case INSTANCEOF:
|
||||
a.push(new UnaryOp(INSTANCEOF, pop(a), insn));
|
||||
break;
|
||||
default:
|
||||
throw new MatchError(insn.getOpcode());
|
||||
}
|
||||
} else if (insn instanceof MultiANewArrayInsnNode) {
|
||||
MultiANewArrayInsnNode multi = (MultiANewArrayInsnNode) insn;
|
||||
StackEntry[] sizes = new StackEntry[multi.dims];
|
||||
for (int i = 0; i < sizes.length; i++) sizes[i] = pop(a);
|
||||
a.push(new NewMultiArray(sizes, getType(multi.desc), insn));
|
||||
} else if (insn instanceof LabelNode) {
|
||||
Option<TryCatchBlockNode> handler = a.codechicken$multipart$asm$StackAnalyser$$catchHandlers()
|
||||
.get((LabelNode) insn);
|
||||
if (handler instanceof Some) {
|
||||
a.push(new CaughtException(Type.getType(((Some<TryCatchBlockNode>) handler).x().type), insn));
|
||||
} else if (!None$.MODULE$.equals(handler)) {
|
||||
throw new MatchError(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user