X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FIR%2FFlat%2FBuildFlat.java;h=fb3b75d1d7cf8126054e4d920189ba538ec096ef;hp=7cbb6100565099c9869a5da1a8df9735e2cfe840;hb=91e8f9756319ae384957f592684b7a76016a9f23;hpb=b1d7ca35bb16de7b7ae53ee00d30618380c91cc0 diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index 7cbb6100..fb3b75d1 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -14,12 +14,21 @@ public class BuildFlat { HashSet continueset; FlatExit fe; + // for synchronized blocks + Stack lockStack; + + // maps tree node to the set of flat node that is translated from the tree node + // WARNING: ONLY DID FOR NAMENODE NOW! + Hashtable> mapNode2FlatNodeSet; + public BuildFlat(State st, TypeUtil typeutil) { state=st; temptovar=new Hashtable(); this.typeutil=typeutil; this.breakset=new HashSet(); this.continueset=new HashSet(); + this.lockStack = new Stack(); + this.mapNode2FlatNodeSet=new Hashtable>(); } public Hashtable getMap() { @@ -54,6 +63,7 @@ public class BuildFlat { } FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.PRE); + ffan.setNumLine(bn.getNumLine()); ffan.addNext(fn); FlatMethod fm=new FlatMethod(td, fe); @@ -67,19 +77,19 @@ public class BuildFlat { TagExpressionList tel=td.getTag(paramvd); //BUG added next line to fix...to test feed in any task program if (tel!=null) - for(int j=0; j1) { - NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); - fn.addNext(np.getBegin()); - return new NodePair(first,np.getEnd()); - } else if (td.isArray()&&td.dereference().iswrapper()) { - NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); - fn.addNext(np.getBegin()); - return new NodePair(first,np.getEnd()); - } else - return new NodePair(first, fn); - } else if(state.MGC) { - // array creation with initializers + FlatNode first=null; + FlatNode last=null; + TempDescriptor[] temps=new TempDescriptor[con.numArgs()]; + for (int i=0; i1) { + NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); + fn.addNext(np.getBegin()); + return new NodePair(first,np.getEnd()); + } else if (td.isArray()&&td.dereference().iswrapper()) { + NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); + fn.addNext(np.getBegin()); + return new NodePair(first,np.getEnd()); + } else + return new NodePair(first, fn); + } else { + // array creation with initializers return flattenArrayInitializerNode(con.getArrayInitializer(), out_temp); } - return null; } } @@ -435,7 +493,7 @@ public class BuildFlat { } else if (td.isArray()&&td.dereference().iswrapper()) { NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal); fsen.addNext(np2.getBegin()); - np2.getEnd().addNext(fon); + np2.getEnd().addNext(fon); } else { fsen.addNext(fon); } @@ -450,7 +508,11 @@ public class BuildFlat { TempDescriptor thisarg=null; if (min.getExpression()!=null) { - thisarg=TempDescriptor.tempFactory("thisarg",min.getExpression().getType()); + TypeDescriptor mtd = min.getExpression().getType(); + if(mtd.isClass() && mtd.getClassDesc().isEnum()) { + mtd = new TypeDescriptor(TypeDescriptor.INT); + } + thisarg=TempDescriptor.tempFactory("thisarg", mtd); NodePair np=flattenExpressionNode(min.getExpression(),thisarg); first=np.getBegin(); last=np.getEnd(); @@ -459,13 +521,17 @@ public class BuildFlat { //Build arguments for(int i=0; i slnv = sbn.getSwitchConditions(); FlatNode cond_begin = null; @@ -1105,9 +1278,11 @@ public class BuildFlat { Operation op=new Operation(Operation.EQUAL); left=flattenExpressionNode(sln.getCondition(), temp_left); FlatOpNode fon=new FlatOpNode(cond_tmp, temp_left, cond_temp, op); + fon.setNumLine(sln.getNumLine()); left.getEnd().addNext(fon); FlatCondBranch fcb=new FlatCondBranch(cond_tmp); + fcb.setNumLine(bn.getNumLine()); fcb.setTrueProb(State.TRUEPROB); FlatNop nop=new FlatNop(); @@ -1121,7 +1296,7 @@ public class BuildFlat { prev_fnp.getEnd().addNext(left.getBegin()); } prev_fnp = false_np; - + if (begin==null) { begin = left.getBegin(); } @@ -1137,31 +1312,38 @@ public class BuildFlat { prev_true_branch.getEnd().addNext(body.getBegin()); } prev_true_branch = body; - for(Iterator breakit=breakset.iterator();breakit.hasNext();) { + for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) { FlatNode fn=(FlatNode)breakit.next(); breakit.remove(); - fn.addNext(endnode); + if (end==null) + end=new FlatNop(); + fn.addNext(end); } breakset=oldbs; } if((prev_true_branch != null) && (prev_true_branch.getEnd() != null)) { - prev_true_branch.getEnd().addNext(endnode); + if (end==null) + end=new FlatNop(); + prev_true_branch.getEnd().addNext(end); } if((prev_false_branch != null) && (prev_false_branch.getEnd() != null)) { - prev_false_branch.getEnd().addNext(endnode); + if (end==null) + end=new FlatNop(); + prev_false_branch.getEnd().addNext(end); } if(begin == null) { end=begin=new FlatNop(); } return new NodePair(begin,end); } - + private NodePair flattenLoopNode(LoopNode ln) { + HashSet oldbs=breakset; HashSet oldcs=continueset; breakset=new HashSet(); continueset=new HashSet(); - + if (ln.getType()==LoopNode.FORLOOP) { NodePair initializer=flattenBlockNode(ln.getInitializer()); TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN)); @@ -1170,6 +1352,7 @@ public class BuildFlat { NodePair body=flattenBlockNode(ln.getBody()); FlatNode begin=initializer.getBegin(); FlatCondBranch fcb=new FlatCondBranch(cond_temp); + fcb.setNumLine(ln.getNumLine()); fcb.setTrueProb(State.TRUEPROB); fcb.setLoop(); FlatNop nopend=new FlatNop(); @@ -1179,24 +1362,27 @@ public class BuildFlat { initializer.getEnd().addNext(nop2); nop2.addNext(condition.getBegin()); if (body.getEnd()!=null) - body.getEnd().addNext(update.getBegin()); + body.getEnd().addNext(update.getBegin()); update.getEnd().addNext(backedge); backedge.addNext(condition.getBegin()); condition.getEnd().addNext(fcb); fcb.addFalseNext(nopend); fcb.addTrueNext(body.getBegin()); - for(Iterator contit=continueset.iterator();contit.hasNext();) { - FlatNode fn=(FlatNode)contit.next(); - contit.remove(); - fn.addNext(update.getBegin()); + for(Iterator contit=continueset.iterator(); contit.hasNext(); ) { + FlatNode fn=(FlatNode)contit.next(); + contit.remove(); + fn.addNext(update.getBegin()); } - for(Iterator breakit=breakset.iterator();breakit.hasNext();) { - FlatNode fn=(FlatNode)breakit.next(); - breakit.remove(); - fn.addNext(nopend); + for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) { + FlatNode fn=(FlatNode)breakit.next(); + breakit.remove(); + fn.addNext(nopend); } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(condition.getBegin(), ln.getLabel()); + } return new NodePair(begin,nopend); } else if (ln.getType()==LoopNode.WHILELOOP) { TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN)); @@ -1204,31 +1390,35 @@ public class BuildFlat { NodePair body=flattenBlockNode(ln.getBody()); FlatNode begin=condition.getBegin(); FlatCondBranch fcb=new FlatCondBranch(cond_temp); + fcb.setNumLine(ln.getNumLine()); fcb.setTrueProb(State.TRUEPROB); fcb.setLoop(); FlatNop nopend=new FlatNop(); FlatBackEdge backedge=new FlatBackEdge(); if (body.getEnd()!=null) - body.getEnd().addNext(backedge); + body.getEnd().addNext(backedge); backedge.addNext(condition.getBegin()); condition.getEnd().addNext(fcb); fcb.addFalseNext(nopend); fcb.addTrueNext(body.getBegin()); - for(Iterator contit=continueset.iterator();contit.hasNext();) { - FlatNode fn=(FlatNode)contit.next(); - contit.remove(); - fn.addNext(backedge); + for(Iterator contit=continueset.iterator(); contit.hasNext(); ) { + FlatNode fn=(FlatNode)contit.next(); + contit.remove(); + fn.addNext(backedge); } - for(Iterator breakit=breakset.iterator();breakit.hasNext();) { - FlatNode fn=(FlatNode)breakit.next(); - breakit.remove(); - fn.addNext(nopend); + for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) { + FlatNode fn=(FlatNode)breakit.next(); + breakit.remove(); + fn.addNext(nopend); } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(begin, ln.getLabel()); + } return new NodePair(begin,nopend); } else if (ln.getType()==LoopNode.DOWHILELOOP) { TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN)); @@ -1236,30 +1426,34 @@ public class BuildFlat { NodePair body=flattenBlockNode(ln.getBody()); FlatNode begin=body.getBegin(); FlatCondBranch fcb=new FlatCondBranch(cond_temp); + fcb.setNumLine(ln.getNumLine()); fcb.setTrueProb(State.TRUEPROB); fcb.setLoop(); FlatNop nopend=new FlatNop(); FlatBackEdge backedge=new FlatBackEdge(); if (body.getEnd()!=null) - body.getEnd().addNext(condition.getBegin()); + body.getEnd().addNext(condition.getBegin()); condition.getEnd().addNext(fcb); fcb.addFalseNext(nopend); fcb.addTrueNext(backedge); backedge.addNext(body.getBegin()); - for(Iterator contit=continueset.iterator();contit.hasNext();) { - FlatNode fn=(FlatNode)contit.next(); - contit.remove(); - fn.addNext(condition.getBegin()); + for(Iterator contit=continueset.iterator(); contit.hasNext(); ) { + FlatNode fn=(FlatNode)contit.next(); + contit.remove(); + fn.addNext(condition.getBegin()); } - for(Iterator breakit=breakset.iterator();breakit.hasNext();) { - FlatNode fn=(FlatNode)breakit.next(); - breakit.remove(); - fn.addNext(nopend); + for(Iterator breakit=breakset.iterator(); breakit.hasNext(); ) { + FlatNode fn=(FlatNode)breakit.next(); + breakit.remove(); + fn.addNext(nopend); } breakset=oldbs; continueset=oldcs; + if(ln.getLabel()!=null){ + state.fn2labelMap.put(begin, ln.getLabel()); + } return new NodePair(begin,nopend); } else throw new Error(); } @@ -1273,21 +1467,27 @@ public class BuildFlat { } FlatReturnNode rnflat=new FlatReturnNode(retval); + rnflat.setNumLine(rntree.getNumLine()); rnflat.addNext(fe); FlatNode ln=rnflat; - if ((state.THREAD||state.MGC)&&currmd.getModifiers().isSynchronized()) { - MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit"); - TempDescriptor thistd=null; - if(currmd.getModifiers().isStatic()) { - // need to lock the Class object - thistd=new TempDescriptor("classobj", currmd.getClassDesc()); + if ((state.THREAD||state.MGC)&&!this.lockStack.isEmpty()) { + if (state.JNI) { + //XXXXXXXXX: FIX THIS } else { - // lock this object - thistd=getTempforVar(currmd.getThis()); + FlatNode end = null; + MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit"); + for(int j = this.lockStack.size(); j > 0; j--) { + TempDescriptor thistd = this.lockStack.elementAt(j-1); + FlatCall fcunlock = new FlatCall(memdex, null, thistd, new TempDescriptor[0]); + fcunlock.setNumLine(rntree.getNumLine()); + if(end != null) { + end.addNext(fcunlock); + } + end = fcunlock; + } + end.addNext(ln); + ln=end; } - FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]); - fc.addNext(ln); - ln=fc; } if (state.DSM&&currmd.getModifiers().isAtomic()) { FlatAtomicExitNode faen=new FlatAtomicExitNode(curran); @@ -1309,6 +1509,7 @@ public class BuildFlat { NodePair fcn=flattenConstraintCheck(ten.getChecks()); ffan.addNext(fcn.getBegin()); FlatReturnNode rnflat=new FlatReturnNode(null); + rnflat.setNumLine(ten.getNumLine()); rnflat.addNext(fe); fcn.getEnd().addNext(rnflat); return new NodePair(ffan, null); @@ -1325,13 +1526,13 @@ public class BuildFlat { TempDescriptor[] temps=new TempDescriptor[cc.numArgs()]; String[] vars=new String[cc.numArgs()]; for(int j=0; j fnSet=mapNode2FlatNodeSet.get(tn); + if(fnSet==null){ + fnSet=new HashSet(); + mapNode2FlatNodeSet.put(tn, fnSet); + } + fnSet.add(fn); + } + + public Set getFlatNodeSet(TreeNode tn){ + // WARNING: ONLY DID FOR NAMENODE NOW! + assert(tn instanceof NameNode); + return mapNode2FlatNodeSet.get(tn); + } + }