JS: fix deobfuscated parameter names. Generate less local variables

This commit is contained in:
Alexey Andreev 2019-04-02 19:15:48 +03:00
parent e6bb91bfb0
commit 91cf9917c7
2 changed files with 25 additions and 3 deletions

View File

@ -792,6 +792,7 @@ public class Renderer implements RenderingManager {
private void renderBody(PreparedMethod method) throws IOException {
StatementRenderer statementRenderer = new StatementRenderer(context, writer);
statementRenderer.setCurrentMethod(method.node);
MethodReference ref = method.reference;
debugEmitter.emitMethod(ref.getDescriptor());
@ -812,7 +813,6 @@ public class Renderer implements RenderingManager {
writer.append(")").ws().append("{").softNewLine().indent();
MethodBodyRenderer renderer = new MethodBodyRenderer(statementRenderer);
statementRenderer.setCurrentMethod(method.node);
if (method.node != null) {
method.node.acceptVisitor(renderer);
} else {

View File

@ -33,9 +33,14 @@ import org.teavm.model.ProgramReader;
import org.teavm.model.Variable;
import org.teavm.model.instructions.AssignInstruction;
import org.teavm.model.instructions.JumpInstruction;
import org.teavm.model.text.ListingBuilder;
public class RegisterAllocator {
public void allocateRegisters(MethodReference method, Program program, boolean debuggerFriendly) {
if (method.getName().equals("importFromJs")) {
System.out.println(new ListingBuilder().buildListing(program, ""));
}
insertPhiArgumentsCopies(program);
InterferenceGraphBuilder interferenceBuilder = new InterferenceGraphBuilder();
LivenessAnalyzer liveness = new LivenessAnalyzer();
@ -93,12 +98,29 @@ public class RegisterAllocator {
inferer.inferTypes(program, method);
int[] categories = new int[program.variableCount()];
for (int i = 0; i < program.variableCount(); ++i) {
VariableType type = inferer.typeOf(i);
categories[i] = type != null ? type.ordinal() : 255;
categories[i] = getCategory(inferer.typeOf(i));
}
return categories;
}
private int getCategory(VariableType type) {
if (type == null) {
return 255;
}
switch (type) {
case INT:
return 0;
case LONG:
return 1;
case FLOAT:
return 2;
case DOUBLE:
return 2;
default:
return 3;
}
}
private String[] getVariableNames(ProgramReader program, boolean debuggerFriendly) {
String[] names = new String[program.variableCount()];
for (int i = 0; i < names.length; ++i) {