Skip to content

Commit 4cebd23

Browse files
committed
WIP work
1 parent 317e74b commit 4cebd23

File tree

13 files changed

+218
-1
lines changed

13 files changed

+218
-1
lines changed

plugins/unpick/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build/
2+
/out/
3+
testData/classes/java*/
4+
bin

plugins/unpick/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import org.vineflower.build.TestDataRuntimesProvider
2+
3+
archivesBaseName = 'vineflower-unpick'
4+
5+
dependencies {
6+
implementation project(":")
7+
testImplementation testFixtures(project(":"))
8+
}
9+
10+
task testDataClasses {
11+
group = 'build'
12+
}
13+
testClasses.dependsOn(testDataClasses)

plugins/unpick/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
does_shadow=false
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package org.vineflower.unpick;
2+
3+
import org.vineflower.unpick.def.UnpickTarget;
4+
5+
import java.util.*;
6+
7+
public class UnpickParser {
8+
/*
9+
unpick 1
10+
11+
const unpick_name int pkg/Destination
12+
1 = VAL_1
13+
2 = VAL_2
14+
15+
const float_pis float
16+
1.5707964 = Math.PI / 2
17+
18+
param * float_pis .*
19+
20+
param 1 unpick_name pkg/Use.method(I)V
21+
return unpick_name pkg/Use.method()I
22+
*/
23+
24+
public static void main(String[] args) {
25+
System.out.println(parse("unpick 1\n" +
26+
"\n" +
27+
"const unpick_name int pkg/Destination\n" +
28+
" VAL_1 = 1\n" +
29+
" VAL_2 = 2\n" +
30+
"\n" +
31+
"param 1 unpick_name pkg/Use.method(I)V\n" +
32+
"return unpick_name pkg/Use.method()I"));
33+
}
34+
35+
public static List<UnpickTarget> parse(String string) {
36+
System.out.println(string);
37+
38+
String[] split = string.split("\\n");
39+
if (split.length < 1) {
40+
return List.of();
41+
}
42+
43+
String first = split[0];
44+
if (!first.equals("unpick 1")) {
45+
return List.of();
46+
}
47+
48+
Map<String, List<UnpickTarget>> namedTargets = new HashMap<>();
49+
50+
String current = null;
51+
52+
for (String s : split) {
53+
if (s.indexOf('#') != -1) {
54+
s = s.substring(0, s.indexOf('#'));
55+
}
56+
57+
if (s.isBlank()) {
58+
continue;
59+
}
60+
61+
boolean leading = !s.stripLeading().equals(s);
62+
String[] components = s.stripLeading().split("\\s");
63+
if (components[0].equals("const") || components[0].equals("bits")) {
64+
parseDefinition(components);
65+
}
66+
}
67+
68+
return new ArrayList<>();
69+
}
70+
71+
private static String parseDefinition(String[] line) {
72+
String sKind = line[0];
73+
if (sKind.equals("const")) {
74+
75+
} else if (sKind.equals("bits")) {
76+
77+
}
78+
79+
String name = line[1];
80+
81+
String sType = line[2];
82+
83+
String destination = line[3];
84+
85+
return null;
86+
}
87+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.vineflower.unpick;
2+
3+
import org.jetbrains.java.decompiler.api.plugin.pass.Pass;
4+
import org.jetbrains.java.decompiler.api.plugin.pass.PassContext;
5+
6+
public class UnpickPass implements Pass {
7+
@Override
8+
public boolean run(PassContext ctx) {
9+
return false;
10+
}
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.vineflower.unpick;
2+
3+
import org.jetbrains.annotations.Nullable;
4+
import org.jetbrains.java.decompiler.api.java.JavaPassLocation;
5+
import org.jetbrains.java.decompiler.api.java.JavaPassRegistrar;
6+
import org.jetbrains.java.decompiler.api.plugin.Plugin;
7+
import org.jetbrains.java.decompiler.api.plugin.PluginOptions;
8+
import org.jetbrains.java.decompiler.api.plugin.pass.NamedPass;
9+
10+
public class UnpickPlugin implements Plugin {
11+
@Override
12+
public String id() {
13+
return "Unpick";
14+
}
15+
16+
@Override
17+
public @Nullable PluginOptions getPluginOptions() {
18+
return null;
19+
}
20+
21+
@Override
22+
public void registerJavaPasses(JavaPassRegistrar registrar) {
23+
registrar.register(JavaPassLocation.AT_END, NamedPass.of("Unpick", new UnpickPass()));
24+
}
25+
26+
@Override
27+
public String description() {
28+
return "Allows constant de-inlining in decompiled code";
29+
}
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.vineflower.unpick.def;
2+
3+
import org.jetbrains.java.decompiler.util.Either;
4+
import org.jetbrains.java.decompiler.util.Unit;
5+
6+
import java.util.List;
7+
8+
public class UnpickDefinition {
9+
private UnpickKind kind;
10+
private String target;
11+
private List<UnpickTarget> targets;
12+
// <Param, Return>
13+
private Either<Integer, Unit> location;
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.vineflower.unpick.def;
2+
3+
public enum UnpickKind {
4+
CONST,
5+
BITS
6+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.vineflower.unpick.def;
2+
3+
import org.jetbrains.java.decompiler.struct.gen.VarType;
4+
5+
public class UnpickTarget {
6+
private final String name;
7+
private final String value;
8+
9+
public UnpickTarget(String name, String value, VarType kind, String destination) {
10+
this.name = name;
11+
this.value = value;
12+
}
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public String getValue() {
19+
return value;
20+
}
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.vineflower.unpick.UnpickPlugin

0 commit comments

Comments
 (0)