mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-23 00:24:11 -08:00
Makes more accurate callsite generation
This commit is contained in:
parent
86003b45ca
commit
5b0506d158
|
@ -178,24 +178,6 @@ public class DebugInformation {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GeneratedLocation getNearestCallSite(GeneratedLocation location) {
|
|
||||||
int keyIndex = indexByKey(callSiteMapping, location);
|
|
||||||
if (keyIndex < 0) {
|
|
||||||
keyIndex = 0;
|
|
||||||
}
|
|
||||||
while (keyIndex < callSiteMapping.values.length) {
|
|
||||||
int valueIndex = callSiteMapping.values[keyIndex];
|
|
||||||
if (valueIndex >= 0) {
|
|
||||||
MethodReference method = getExactMethod(valueIndex);
|
|
||||||
if (method != null) {
|
|
||||||
return new GeneratedLocation(callSiteMapping.lines[keyIndex], callSiteMapping.columns[keyIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++keyIndex;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MethodReference getCallSite(GeneratedLocation location) {
|
public MethodReference getCallSite(GeneratedLocation location) {
|
||||||
int keyIndex = indexByKey(callSiteMapping, location);
|
int keyIndex = indexByKey(callSiteMapping, location);
|
||||||
if (keyIndex < 0) {
|
if (keyIndex < 0) {
|
||||||
|
|
|
@ -103,11 +103,7 @@ public class Debugger {
|
||||||
DebugInformation debugInfo = debugInformationMap.get(script);
|
DebugInformation debugInfo = debugInformationMap.get(script);
|
||||||
if (frame.getLocation() != null && debugInfo != null) {
|
if (frame.getLocation() != null && debugInfo != null) {
|
||||||
exits = false;
|
exits = false;
|
||||||
MethodReference callMethod = null;
|
MethodReference callMethod = debugInfo.getCallSite(genLoc);
|
||||||
GeneratedLocation callSiteLoc = debugInfo.getNearestCallSite(genLoc);
|
|
||||||
if (callSiteLoc != null) {
|
|
||||||
callMethod = debugInfo.getCallSite(callSiteLoc);
|
|
||||||
}
|
|
||||||
exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet<SourceLocation>(),
|
exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet<SourceLocation>(),
|
||||||
successors);
|
successors);
|
||||||
if (enterMethod && callMethod != null) {
|
if (enterMethod && callMethod != null) {
|
||||||
|
|
|
@ -52,6 +52,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
private DebugInformationEmitter debugEmitter = new DummyDebugInformationEmitter();
|
private DebugInformationEmitter debugEmitter = new DummyDebugInformationEmitter();
|
||||||
private Deque<NodeLocation> locationStack = new ArrayDeque<>();
|
private Deque<NodeLocation> locationStack = new ArrayDeque<>();
|
||||||
private DeferredCallSite lastCallSite;
|
private DeferredCallSite lastCallSite;
|
||||||
|
private DeferredCallSite prevCallSite;
|
||||||
|
|
||||||
private static class InjectorHolder {
|
private static class InjectorHolder {
|
||||||
public final Injector injector;
|
public final Injector injector;
|
||||||
|
@ -601,11 +602,13 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
if (statement.getLocation() != null) {
|
if (statement.getLocation() != null) {
|
||||||
pushLocation(statement.getLocation());
|
pushLocation(statement.getLocation());
|
||||||
}
|
}
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
if (statement.getLeftValue() != null) {
|
if (statement.getLeftValue() != null) {
|
||||||
statement.getLeftValue().acceptVisitor(this);
|
statement.getLeftValue().acceptVisitor(this);
|
||||||
writer.ws().append("=").ws();
|
writer.ws().append("=").ws();
|
||||||
}
|
}
|
||||||
statement.getRightValue().acceptVisitor(this);
|
statement.getRightValue().acceptVisitor(this);
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
writer.append(";").softNewLine();
|
writer.append(";").softNewLine();
|
||||||
if (statement.getLocation() != null) {
|
if (statement.getLocation() != null) {
|
||||||
popLocation();
|
popLocation();
|
||||||
|
@ -634,8 +637,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
if (statement.getCondition().getLocation() != null) {
|
if (statement.getCondition().getLocation() != null) {
|
||||||
pushLocation(statement.getCondition().getLocation());
|
pushLocation(statement.getCondition().getLocation());
|
||||||
}
|
}
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
writer.append("if").ws().append("(");
|
writer.append("if").ws().append("(");
|
||||||
statement.getCondition().acceptVisitor(this);
|
statement.getCondition().acceptVisitor(this);
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
writer.append(")").ws().append("{").softNewLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
if (statement.getCondition().getLocation() != null) {
|
if (statement.getCondition().getLocation() != null) {
|
||||||
popLocation();
|
popLocation();
|
||||||
|
@ -670,8 +675,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
if (statement.getId() != null) {
|
if (statement.getId() != null) {
|
||||||
writer.append(statement.getId()).append(": ");
|
writer.append(statement.getId()).append(": ");
|
||||||
}
|
}
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
writer.append("switch").ws().append("(");
|
writer.append("switch").ws().append("(");
|
||||||
statement.getValue().acceptVisitor(this);
|
statement.getValue().acceptVisitor(this);
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
writer.append(")").ws().append("{").softNewLine().indent();
|
writer.append(")").ws().append("{").softNewLine().indent();
|
||||||
for (SwitchClause clause : statement.getClauses()) {
|
for (SwitchClause clause : statement.getClauses()) {
|
||||||
for (int condition : clause.getConditions()) {
|
for (int condition : clause.getConditions()) {
|
||||||
|
@ -704,7 +711,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
}
|
}
|
||||||
writer.append("while").ws().append("(");
|
writer.append("while").ws().append("(");
|
||||||
if (statement.getCondition() != null) {
|
if (statement.getCondition() != null) {
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
statement.getCondition().acceptVisitor(this);
|
statement.getCondition().acceptVisitor(this);
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
} else {
|
} else {
|
||||||
writer.append("true");
|
writer.append("true");
|
||||||
}
|
}
|
||||||
|
@ -783,7 +792,9 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
writer.append("return");
|
writer.append("return");
|
||||||
if (statement.getResult() != null) {
|
if (statement.getResult() != null) {
|
||||||
writer.append(' ');
|
writer.append(' ');
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
statement.getResult().acceptVisitor(this);
|
statement.getResult().acceptVisitor(this);
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
}
|
}
|
||||||
writer.append(";").softNewLine();
|
writer.append(";").softNewLine();
|
||||||
if (statement.getLocation() != null) {
|
if (statement.getLocation() != null) {
|
||||||
|
@ -801,8 +812,10 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
pushLocation(statement.getLocation());
|
pushLocation(statement.getLocation());
|
||||||
}
|
}
|
||||||
writer.append("$rt_throw(");
|
writer.append("$rt_throw(");
|
||||||
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
statement.getException().acceptVisitor(this);
|
statement.getException().acceptVisitor(this);
|
||||||
writer.append(");").softNewLine();
|
writer.append(");").softNewLine();
|
||||||
|
debugEmitter.emitEmptyCallSite();
|
||||||
if (statement.getLocation() != null) {
|
if (statement.getLocation() != null) {
|
||||||
popLocation();
|
popLocation();
|
||||||
}
|
}
|
||||||
|
@ -1299,16 +1312,15 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
String className = naming.getNameFor(expr.getMethod().getClassName());
|
String className = naming.getNameFor(expr.getMethod().getClassName());
|
||||||
String name = naming.getNameFor(expr.getMethod());
|
String name = naming.getNameFor(expr.getMethod());
|
||||||
String fullName = naming.getFullNameFor(expr.getMethod());
|
String fullName = naming.getFullNameFor(expr.getMethod());
|
||||||
DeferredCallSite callSite = null;
|
DeferredCallSite callSite = prevCallSite;
|
||||||
boolean shouldEraseCallSite = lastCallSite == null;
|
boolean shouldEraseCallSite = lastCallSite == null;
|
||||||
switch (expr.getType()) {
|
|
||||||
case STATIC:
|
|
||||||
callSite = debugEmitter.emitCallSite();
|
|
||||||
if (lastCallSite == null) {
|
if (lastCallSite == null) {
|
||||||
lastCallSite = callSite;
|
lastCallSite = callSite;
|
||||||
}
|
}
|
||||||
|
switch (expr.getType()) {
|
||||||
|
case STATIC:
|
||||||
writer.append(fullName).append("(");
|
writer.append(fullName).append("(");
|
||||||
debugEmitter.emitEmptyCallSite();
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
writer.append(",").ws();
|
writer.append(",").ws();
|
||||||
|
@ -1318,12 +1330,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
break;
|
break;
|
||||||
case SPECIAL:
|
case SPECIAL:
|
||||||
callSite = debugEmitter.emitCallSite();
|
|
||||||
if (lastCallSite == null) {
|
|
||||||
lastCallSite = callSite;
|
|
||||||
}
|
|
||||||
writer.append(fullName).append("(");
|
writer.append(fullName).append("(");
|
||||||
debugEmitter.emitEmptyCallSite();
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
expr.getArguments().get(0).acceptVisitor(this);
|
expr.getArguments().get(0).acceptVisitor(this);
|
||||||
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
||||||
writer.append(",").ws();
|
writer.append(",").ws();
|
||||||
|
@ -1333,12 +1341,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
break;
|
break;
|
||||||
case DYNAMIC:
|
case DYNAMIC:
|
||||||
expr.getArguments().get(0).acceptVisitor(this);
|
expr.getArguments().get(0).acceptVisitor(this);
|
||||||
callSite = debugEmitter.emitCallSite();
|
|
||||||
if (lastCallSite == null) {
|
|
||||||
lastCallSite = callSite;
|
|
||||||
}
|
|
||||||
writer.append(".").append(name).append("(");
|
writer.append(".").append(name).append("(");
|
||||||
debugEmitter.emitEmptyCallSite();
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
for (int i = 1; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 1) {
|
if (i > 1) {
|
||||||
writer.append(",").ws();
|
writer.append(",").ws();
|
||||||
|
@ -1348,12 +1352,8 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
writer.append(')');
|
writer.append(')');
|
||||||
break;
|
break;
|
||||||
case CONSTRUCTOR:
|
case CONSTRUCTOR:
|
||||||
callSite = debugEmitter.emitCallSite();
|
|
||||||
if (lastCallSite == null) {
|
|
||||||
lastCallSite = callSite;
|
|
||||||
}
|
|
||||||
writer.append(className).append(".").append(name).append("(");
|
writer.append(className).append(".").append(name).append("(");
|
||||||
debugEmitter.emitEmptyCallSite();
|
prevCallSite = debugEmitter.emitCallSite();
|
||||||
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
for (int i = 0; i < expr.getArguments().size(); ++i) {
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
writer.append(",").ws();
|
writer.append(",").ws();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user