private void addToTrace(ErrorTraceInstr inst, InstrLocation loc, ref ErrorTraceBlock curr, ErrorTrace trace) { if (curr == null) { curr = new ErrorTraceBlock(loc.blockName); Debug.Assert(loc.num == 0); curr.addInstr(inst); return; } // curr != null. We need to see if inst should be put inside curr or start a new block? if (loc.num == curr.Cmds.Count && loc.blockName == curr.blockName) { curr.addInstr(inst); } else { // start a new block Debug.Assert(loc.num == 0); trace.addBlock(curr); curr = new ErrorTraceBlock(loc.blockName); curr.addInstr(inst); } }
// We added instructions at the beginning of this block. Update the affected // tranformations (by updating the instruction locations accordingly) public void addedInstrToBeg(string blockName, int delta) { var updates = new Dictionary <InstrLocation, InstrLocation>(new InstrLocationComparer()); var rmv = new List <InstrLocation>(); foreach (var kv in toFromMap) { if (kv.Key.blockName == blockName) { rmv.Add(kv.Key); var newloc = new InstrLocation(blockName, kv.Key.num + delta, kv.Key.type); updates.Add(newloc, kv.Value); } } // Delete old values from the map foreach (var k in rmv) { toFromMap.Remove(k); } // Add new values foreach (var kv in updates) { toFromMap.Add(kv.Key, kv.Value); } }
private ErrorTraceInstr getCorrespondingInst(InstrLocation from, ErrorTraceInstr toInstr, InsertionTrans tinfo) { if (from.type.type == InstrTypeEnum.CALL || from.type.type == InstrTypeEnum.ASYNC) { // Get callee trace ErrorTrace calleeTrace = null; if (toInstr.isCall()) { calleeTrace = (toInstr as CallInstr).calleeTrace; } // recursively mapBack the callee trace if (calleeTrace != null) { calleeTrace = tinfo.mapBackTrace(calleeTrace); } return(new CallInstr(from.type.callee, calleeTrace, (from.type.type == InstrTypeEnum.ASYNC ? true : false), toInstr.info)); } else { return(new IntraInstr(toInstr.info)); } }
public bool Equals(InstrLocation loc) { return(blockName == loc.blockName && num == loc.num && type.type == loc.type.type && type.callee == loc.type.callee); }
public ErrorTrace mapBackTrace(ErrorTrace trace, InsertionTrans tinfo) { // Output to be constructed var ret = new ErrorTrace(tinfo.getSrcProcName(trace.procName)); // The current block being constructed ErrorTraceBlock curr = null; foreach (var blk in trace.Blocks) { if (toFromBlockMap.ContainsKey(blk.blockName)) { // This "blk" corresponds to some block in the source program, // then start a new block here. if (curr != null) { ret.addBlock(curr); } curr = new ErrorTraceBlock(toFromBlockMap[blk.blockName]); if (blk.info != null) { curr.info = blk.info.Copy(); } } for (int i = 0; i < blk.Cmds.Count; i++) { var toType = InstrTypeEnum.INTRA; string callee = null; if (blk.Cmds[i].isCall()) { var cc = (blk.Cmds[i] as CallInstr); callee = cc.callee; if (cc.asyncCall) { toType = InstrTypeEnum.ASYNC; } else { toType = InstrTypeEnum.CALL; } } var to = new InstrLocation(blk.blockName, i, new InstrType(toType, callee)); // Is there a corresponding source instruction? if (!toFromMap.ContainsKey(to)) { continue; } // This is the location of the corresponding source instruction var from = toFromMap[to]; // This is the source instruction var inst = getCorrespondingInst(from, blk.Cmds[i], tinfo); // Now we have to place "inst" in "ret" addToTrace(inst, from, ref curr, ret); } } if (curr != null) { ret.addBlock(curr); } if (trace.returns) { ret.addReturn(trace.raisesException); } return(ret); }
public void addTrans(InstrLocation from, InstrLocation to) { Debug.Assert(!toFromMap.ContainsKey(to)); toFromMap.Add(to, from); }