From 6b2db3e1906c5f9c8e072ddb81a21aa28ec3c7c8 Mon Sep 17 00:00:00 2001 From: Julian Dolby Date: Tue, 8 May 2018 08:01:35 -0400 Subject: [PATCH] more-detailed source mapping information --- .../cast/ir/translator/AstTranslator.java | 150 +++++++++++++----- .../com/ibm/wala/cast/loader/AstMethod.java | 2 + 2 files changed, 116 insertions(+), 36 deletions(-) diff --git a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java index 69742609d..28cc829a0 100644 --- a/com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java +++ b/com.ibm.wala.cast/source/java/com/ibm/wala/cast/ir/translator/AstTranslator.java @@ -500,11 +500,15 @@ public abstract class AstTranslator extends CAstVisitor operand) { + return operandPositions[instructionOffset][operand]; + } else { + return null; + } + } + @Override public String[][] getSourceNamesForValues() { return valueNumberNames; @@ -837,6 +850,8 @@ public abstract class AstTranslator extends CAstVisitor,TypeReference[]> catchTypes = functionContext.getCatchTypes(); AstCFG cfg = new AstCFG(n, functionContext.cfg(), symtab, insts); Position[] line = functionContext.cfg().getLinePositionMap(); + Position[][] operand = functionContext.cfg().getOperandPositionMap(); boolean katch = functionContext.cfg().hasCatchBlock(); boolean monitor = functionContext.cfg().hasMonitorOp(); String[] nms = makeNameMap(n, functionContext.entityScopes(), cfg.getInstructions()); @@ -3328,7 +3359,7 @@ public abstract class AstTranslator extends CAstVisitor visitor) { WalkContext context = c; int result = c.getValue(n); - int arrayValue = c.getValue(n.getChild(0)); - context.cfg().addInstruction(insts.ArrayLengthInstruction(context.cfg().currentInstruction, result, arrayValue)); + CAstNode arrayExpr = n.getChild(0); + int arrayValue = c.getValue(arrayExpr); + int currentInstruction = context.cfg().currentInstruction; + context.cfg().addInstruction(insts.ArrayLengthInstruction(currentInstruction, result, arrayValue)); + context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(arrayExpr)); } @Override @@ -3760,10 +3798,13 @@ public abstract class AstTranslator extends CAstVisitor visitor) { WalkContext context = c; + int currentInstruction = context.cfg().currentInstruction; if (n.getChildCount() > 0) { - context.cfg().addInstruction(insts.ReturnInstruction(context.cfg().currentInstruction, c.getValue(n.getChild(0)), false)); + CAstNode returnExpr = n.getChild(0); + context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction, c.getValue(returnExpr), false)); + context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(returnExpr)); } else { - context.cfg().addInstruction(insts.ReturnInstruction(context.cfg().currentInstruction)); + context.cfg().addInstruction(insts.ReturnInstruction(currentInstruction)); } context.cfg().addPreNode(n, context.getUnwindState()); @@ -3779,14 +3820,21 @@ public abstract class AstTranslator extends CAstVisitor visitor) { WalkContext context = c; + int currentInstruction = context.cfg().currentInstruction; if (n.getChildCount() == 1) { + CAstNode arg = n.getChild(0); context.cfg().addInstruction( - insts.ConditionalBranchInstruction(context.cfg().currentInstruction, translateConditionOpcode(CAstOperator.OP_NE), null, c.getValue(n.getChild(0)), context + insts.ConditionalBranchInstruction(currentInstruction, translateConditionOpcode(CAstOperator.OP_NE), null, c.getValue(arg), context .currentScope().getConstantValue(new Integer(0)), -1)); + context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(arg)); } else if (n.getChildCount() == 3) { + CAstNode op = n.getChild(0); + CAstNode leftExpr = n.getChild(1); + CAstNode rightExpr = n.getChild(2); context.cfg().addInstruction( - insts.ConditionalBranchInstruction(context.cfg().currentInstruction, translateConditionOpcode(n.getChild(0)), null, c.getValue(n.getChild(1)), - c.getValue(n.getChild(2)), -1)); + insts.ConditionalBranchInstruction(currentInstruction, translateConditionOpcode(op), null, c.getValue(leftExpr), + c.getValue(rightExpr), -1)); + context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(leftExpr), context.getSourceMap().getPosition(rightExpr)); } else { Assertions.UNREACHABLE(); } @@ -3838,16 +3886,21 @@ public abstract class AstTranslator extends CAstVisitor visitor) { WalkContext context = c; boolean fromSpec = true; - int result = c.getValue(n.getChild(0)); + CAstNode assertion = n.getChild(0); + int result = c.getValue(assertion); if (n.getChildCount() == 2) { assert n.getChild(1).getKind() == CAstNode.CONSTANT; assert n.getChild(1).getValue() instanceof Boolean; fromSpec = n.getChild(1).getValue().equals(Boolean.TRUE); } - context.cfg().addInstruction(new AstAssertInstruction(context.cfg().currentInstruction, result, fromSpec)); + int currentInstruction = context.cfg().currentInstruction; + context.cfg().addInstruction(new AstAssertInstruction(currentInstruction, result, fromSpec)); + context.cfg().noteOperands(currentInstruction, context.getSourceMap().getPosition(assertion)); } @Override @@ -4519,7 +4586,9 @@ public abstract class AstTranslator extends CAstVisitor visitor) { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); - c.cfg().addInstruction(new EachElementGetInstruction(c.cfg().currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); + int currentInstruction = c.cfg().getCurrentInstruction(); + c.cfg().addInstruction(new EachElementGetInstruction(currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); + c.cfg().noteOperands(currentInstruction, c.getSourceMap().getPosition(n.getChild(0)), c.getSourceMap().getPosition(n.getChild(1))); } @Override @@ -4531,7 +4600,9 @@ public abstract class AstTranslator extends CAstVisitor visitor) { int result = c.currentScope().allocateTempValue(); c.setValue(n, result); - c.cfg().addInstruction(new EachElementHasNextInstruction(c.cfg().currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); + int currentInstruction = c.cfg().getCurrentInstruction(); + c.cfg().addInstruction(new EachElementHasNextInstruction(currentInstruction, result, c.getValue(n.getChild(0)), c.getValue(n.getChild(1)))); + c.cfg().noteOperands(currentInstruction, c.getSourceMap().getPosition(n.getChild(0)), c.getSourceMap().getPosition(n.getChild(1))); } @Override @@ -4561,11 +4632,14 @@ public abstract class AstTranslator extends CAstVisitor visitor) { WalkContext wc = c; - int ref = c.getValue(n.getChild(0)); + CAstNode refExpr = n.getChild(0); + int ref = c.getValue(refExpr); int result = wc.currentScope().allocateTempValue(); c.setValue(n, result); if (n.getChildCount() == 1) { - wc.cfg().addInstruction(new AstIsDefinedInstruction(wc.cfg().currentInstruction, result, ref)); + int currentInstruction = wc.cfg().getCurrentInstruction(); + wc.cfg().addInstruction(new AstIsDefinedInstruction(currentInstruction, result, ref)); + wc.cfg().noteOperands(currentInstruction, wc.getSourceMap().getPosition(refExpr)); } else { doIsFieldDefined(wc, result, ref, n.getChild(1)); } @@ -4581,11 +4655,15 @@ public abstract class AstTranslator extends CAstVisitor