mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-25 09:54:24 +00:00
Merge remote-tracking branch 'fix/lvtgen', closes #42
This commit is contained in:
commit
f759953651
4 files changed
+91
-13
No files matched your search
@@ -60,7 +60,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.3.3";
|
||||
public static final String VERSION = "0.3.4";
|
||||
|
||||
/**
|
||||
* Blackboard key where the subsystem version will be stored to indicate
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -35,9 +36,11 @@ import java.util.Set;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.FrameNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.Member.Type;
|
||||
@@ -51,7 +54,7 @@ import com.google.common.collect.ImmutableSet;
|
||||
* information needed to support more complex mixin behaviour such as detached
|
||||
* superclass and mixin inheritance.
|
||||
*/
|
||||
class ClassInfo extends TreeInfo {
|
||||
public class ClassInfo extends TreeInfo {
|
||||
|
||||
/**
|
||||
* <p>To all intents and purposes, the "real" class hierarchy and the mixin
|
||||
@@ -68,7 +71,7 @@ class ClassInfo extends TreeInfo {
|
||||
* immediate match falls through to {@link #NONE} on the next step, which
|
||||
* prevents further traversals from occurring in the lookup.</p>
|
||||
*/
|
||||
static enum Traversal {
|
||||
public static enum Traversal {
|
||||
|
||||
/**
|
||||
* No traversals are allowed.
|
||||
@@ -109,6 +112,40 @@ class ClassInfo extends TreeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about frames in a method
|
||||
*/
|
||||
public static class FrameData {
|
||||
|
||||
private static final String[] FRAMETYPES = { "NEW", "FULL", "APPEND", "CHOP", "SAME", "SAME1" };
|
||||
|
||||
public final int index;
|
||||
|
||||
public final int type;
|
||||
|
||||
public final int locals;
|
||||
|
||||
FrameData(int index, int type, int locals) {
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
this.locals = locals;
|
||||
}
|
||||
|
||||
FrameData(int index, FrameNode frameNode) {
|
||||
this.index = index;
|
||||
this.type = frameNode.type;
|
||||
this.locals = frameNode.local != null ? frameNode.local.size() : 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("FrameData[index=%d, type=%s, locals=%d]", this.index, FrameData.FRAMETYPES[this.type + 1], this.locals);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about a member in this class
|
||||
*/
|
||||
@@ -236,10 +273,13 @@ class ClassInfo extends TreeInfo {
|
||||
/**
|
||||
* A method
|
||||
*/
|
||||
class Method extends Member {
|
||||
public class Method extends Member {
|
||||
|
||||
private final List<FrameData> frames;
|
||||
|
||||
public Method(Member member) {
|
||||
super(member);
|
||||
this.frames = member instanceof Method ? ((Method)member).frames : null;
|
||||
}
|
||||
|
||||
public Method(MethodNode method) {
|
||||
@@ -248,20 +288,39 @@ class ClassInfo extends TreeInfo {
|
||||
|
||||
public Method(MethodNode method, boolean injected) {
|
||||
super(Type.METHOD, method.name, method.desc, method.access, injected);
|
||||
this.frames = this.gatherFrames(method);
|
||||
}
|
||||
|
||||
public Method(String name, String desc) {
|
||||
super(Type.METHOD, name, desc, Opcodes.ACC_PUBLIC, false);
|
||||
this.frames = null;
|
||||
}
|
||||
|
||||
public Method(String name, String desc, int access) {
|
||||
super(Type.METHOD, name, desc, access, false);
|
||||
this.frames = null;
|
||||
}
|
||||
|
||||
public Method(String name, String desc, int access, boolean injected) {
|
||||
super(Type.METHOD, name, desc, access, injected);
|
||||
this.frames = null;
|
||||
}
|
||||
|
||||
private List<FrameData> gatherFrames(MethodNode method) {
|
||||
List<FrameData> frames = new ArrayList<FrameData>();
|
||||
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
|
||||
AbstractInsnNode insn = iter.next();
|
||||
if (insn instanceof FrameNode) {
|
||||
frames.add(new FrameData(method.instructions.indexOf(insn), (FrameNode)insn));
|
||||
}
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
|
||||
public List<FrameData> getFrames() {
|
||||
return this.frames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassInfo getOwner() {
|
||||
return ClassInfo.this;
|
||||
@@ -629,7 +688,7 @@ class ClassInfo extends TreeInfo {
|
||||
/**
|
||||
* Class targets
|
||||
*/
|
||||
protected List<ClassInfo> getTargets() {
|
||||
List<ClassInfo> getTargets() {
|
||||
if (this.mixin != null) {
|
||||
List<ClassInfo> targets = new ArrayList<ClassInfo>();
|
||||
targets.add(this);
|
||||
@@ -1269,7 +1328,7 @@ class ClassInfo extends TreeInfo {
|
||||
* @param classNode
|
||||
* @return
|
||||
*/
|
||||
public static ClassInfo fromClassNode(ClassNode classNode) {
|
||||
static ClassInfo fromClassNode(ClassNode classNode) {
|
||||
ClassInfo info = ClassInfo.cache.get(classNode.name);
|
||||
if (info == null) {
|
||||
info = new ClassInfo(classNode);
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.objectweb.asm.tree.analysis.Analyzer;
|
||||
import org.objectweb.asm.tree.analysis.AnalyzerException;
|
||||
import org.objectweb.asm.tree.analysis.BasicValue;
|
||||
import org.objectweb.asm.tree.analysis.Frame;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo;
|
||||
import org.spongepowered.asm.mixin.transformer.ClassInfo.FrameData;
|
||||
import org.spongepowered.asm.mixin.transformer.MixinVerifier;
|
||||
|
||||
|
||||
@@ -118,6 +120,8 @@ public class Locals {
|
||||
* specified location
|
||||
*/
|
||||
public static LocalVariableNode[] getLocalsAt(ClassNode classNode, MethodNode method, AbstractInsnNode node) {
|
||||
List<FrameData> frames = ClassInfo.forName(classNode.name).findMethod(method).getFrames();
|
||||
|
||||
LocalVariableNode[] frame = new LocalVariableNode[method.maxLocals];
|
||||
int local = 0, index = 0;
|
||||
|
||||
@@ -131,11 +135,18 @@ public class Locals {
|
||||
frame[local] = new LocalVariableNode("arg" + index++, argType.toString(), null, null, null, local);
|
||||
local += argType.getSize();
|
||||
}
|
||||
|
||||
int initialFrameSize = local;
|
||||
int frameIndex = -1, locals = 0;
|
||||
|
||||
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
|
||||
AbstractInsnNode insn = iter.next();
|
||||
if (insn instanceof FrameNode) {
|
||||
FrameNode frameNode = (FrameNode) insn;
|
||||
frameIndex++;
|
||||
FrameNode frameNode = (FrameNode)insn;
|
||||
FrameData frameData = frameIndex < frames.size() ? frames.get(frameIndex) : null;
|
||||
|
||||
locals = frameData != null && frameData.type == Opcodes.F_FULL ? Math.max(locals, frameNode.local.size()) : frameNode.local.size();
|
||||
|
||||
// localPos tracks the location in the frame node's locals list, which doesn't leave space for TOP entries
|
||||
for (int localPos = 0, framePos = 0; framePos < frame.length; framePos++, localPos++) {
|
||||
@@ -145,10 +156,12 @@ public class Locals {
|
||||
if (localType instanceof String) { // String refers to a reference type
|
||||
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
|
||||
} else if (localType instanceof Integer) { // Integer refers to a primitive type or other marker
|
||||
boolean isMarkerType = localType == Opcodes.UNINITIALIZED_THIS || localType == Opcodes.TOP || localType == Opcodes.NULL;
|
||||
boolean isMarkerType = localType == Opcodes.UNINITIALIZED_THIS || localType == Opcodes.NULL;
|
||||
boolean is32bitValue = localType == Opcodes.INTEGER || localType == Opcodes.FLOAT;
|
||||
boolean is64bitValue = localType == Opcodes.DOUBLE || localType == Opcodes.LONG;
|
||||
if (isMarkerType) {
|
||||
if (localType == Opcodes.TOP) {
|
||||
// Do nothing, explicit TOP entries are pretty much always bogus, and real ones are handled below
|
||||
} else if (isMarkerType) {
|
||||
frame[framePos] = null;
|
||||
} else if (is32bitValue || is64bitValue) {
|
||||
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
|
||||
@@ -162,7 +175,9 @@ public class Locals {
|
||||
+ " in " + classNode.name + "." + method.name + method.desc);
|
||||
}
|
||||
} else if (localType == null) {
|
||||
frame[framePos] = null;
|
||||
if (framePos >= initialFrameSize && framePos >= locals && locals > 0) {
|
||||
frame[framePos] = null;
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Invalid value " + localType + " in locals array at position " + localPos
|
||||
+ " in " + classNode.name + "." + method.name + method.desc);
|
||||
@@ -282,7 +297,8 @@ public class Locals {
|
||||
LocalVariableNode[] localNodes = new LocalVariableNode[method.maxLocals]; // LocalVariableNodes for current frame
|
||||
BasicValue[] locals = new BasicValue[method.maxLocals]; // locals in previous frame, used to work out what changes between frames
|
||||
LabelNode[] labels = new LabelNode[methodSize]; // Labels to add to the method, for the markers
|
||||
|
||||
String[] lastKnownType = new String[method.maxLocals];
|
||||
|
||||
// Traverse the frames and work out when locals begin and end
|
||||
for (int i = 0; i < methodSize; i++) {
|
||||
Frame<BasicValue> f = frames[i];
|
||||
@@ -316,8 +332,11 @@ public class Locals {
|
||||
localNodes[j] = null;
|
||||
}
|
||||
|
||||
String desc = (local.getType() != null) ? local.getType().getDescriptor() : null;
|
||||
String desc = (local.getType() != null) ? local.getType().getDescriptor() : lastKnownType[j];
|
||||
localNodes[j] = new LocalVariableNode("var" + j, desc, null, label, null, j);
|
||||
if (desc != null) {
|
||||
lastKnownType[j] = desc;
|
||||
}
|
||||
}
|
||||
|
||||
locals[j] = local;
|
||||
|
||||
Reference in new issue
Block a user