From 8d0432dd5e21f74b6560c8015dbab444fe9da953 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Wed, 6 Aug 2014 20:56:33 +0400 Subject: [PATCH] First correct local variable mapping --- .../src/main/java/org/teavm/model/Variable.java | 13 +++++++++++++ .../org/teavm/model/util/RegisterAllocator.java | 9 +++++++++ .../teavm/optimization/GlobalValueNumbering.java | 3 +++ .../main/java/org/teavm/parsing/SSATransformer.java | 4 +++- .../main/resources/org/teavm/javascript/runtime.js | 10 ++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/teavm-core/src/main/java/org/teavm/model/Variable.java b/teavm-core/src/main/java/org/teavm/model/Variable.java index 2708f68a0..7f837516f 100644 --- a/teavm-core/src/main/java/org/teavm/model/Variable.java +++ b/teavm-core/src/main/java/org/teavm/model/Variable.java @@ -65,4 +65,17 @@ public class Variable implements VariableReader { public void setDebugName(String debugName) { this.debugName = debugName; } + + public void mergeDebugName(String otherDebugName) { + if (otherDebugName == null) { + return; + } + String[] parts = debugName != null ? debugName.split("\\|") : new String[0]; + for (String part : parts) { + if (otherDebugName.equals(part)) { + return; + } + } + debugName = debugName != null ? debugName + "|" + otherDebugName : otherDebugName; + } } diff --git a/teavm-core/src/main/java/org/teavm/model/util/RegisterAllocator.java b/teavm-core/src/main/java/org/teavm/model/util/RegisterAllocator.java index 5d74f3c5a..34550c8c2 100644 --- a/teavm-core/src/main/java/org/teavm/model/util/RegisterAllocator.java +++ b/teavm-core/src/main/java/org/teavm/model/util/RegisterAllocator.java @@ -214,6 +214,15 @@ public class RegisterAllocator { varMap[tryCatch.getExceptionVariable().getIndex()])); } } + String[] originalNames = new String[program.variableCount()]; + for (int i = 0; i < program.variableCount(); ++i) { + Variable var = program.variableAt(i); + originalNames[i] = var.getDebugName(); + var.setDebugName(null); + } + for (int i = 0; i < program.variableCount(); ++i) { + program.variableAt(varMap[i]).mergeDebugName(originalNames[i]); + } } private void renameInterferenceGraph(List graph, DisjointSet classes, final int[] varMap) { diff --git a/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java b/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java index 550734318..429e52fb6 100644 --- a/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java +++ b/teavm-core/src/main/java/org/teavm/optimization/GlobalValueNumbering.java @@ -112,6 +112,9 @@ public class GlobalValueNumbering implements MethodOptimization { for (int i = 0; i < map.length; ++i) { if (map[i] != i) { + Variable var = program.variableAt(i); + Variable mapVar = program.variableAt(map[i]); + mapVar.mergeDebugName(var.getDebugName()); program.deleteVariable(i); } } diff --git a/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java b/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java index 453168a39..d713630b9 100644 --- a/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java +++ b/teavm-core/src/main/java/org/teavm/parsing/SSATransformer.java @@ -175,12 +175,14 @@ public class SSATransformer { int[] phiIndexes = phiIndexMap[successor]; List phis = program.basicBlockAt(successor).getPhis(); for (int j = 0; j < phis.size(); ++j) { + Phi phi = phis.get(j); Variable var = variableMap[phiIndexes[j]]; if (var != null) { Incoming incoming = new Incoming(); incoming.setSource(currentBlock); incoming.setValue(var); - phis.get(j).getIncomings().add(incoming); + phi.getIncomings().add(incoming); + phi.getReceiver().mergeDebugName(var.getDebugName()); } } } diff --git a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js index 29db04f2b..831bd1377 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -391,6 +391,16 @@ function $rt_s(index) { return $rt_stringPool_instance[index]; } +function $dbg_repr(obj) { + return obj.toString(); +} +function $dbg_class(obj) { + if (obj instanceof Long) { + return "long"; + } + return obj.constructor.$meta.name; +} + Long = function(lo, hi) { this.lo = lo | 0; this.hi = hi | 0;