6 public class BuildFlat {
9 MethodDescriptor currmd;
16 public BuildFlat(State st, TypeUtil typeutil) {
18 temptovar=new Hashtable();
19 this.typeutil=typeutil;
20 this.breakset=new HashSet();
21 this.continueset=new HashSet();
24 public Hashtable getMap() {
28 public void buildFlat() {
29 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
31 ClassDescriptor cn=(ClassDescriptor)it.next();
35 Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator();
36 while(task_it.hasNext()) {
37 TaskDescriptor td=(TaskDescriptor)task_it.next();
42 private void flattenTask(TaskDescriptor td) {
43 BlockNode bn=state.getMethodBody(td);
44 NodePair np=flattenBlockNode(bn);
45 FlatNode fn=np.getBegin();
47 FlatNode fn2=np.getEnd();
49 if (fn2!=null&& fn2.kind()!=FKind.FlatReturnNode) {
50 FlatReturnNode rnflat=new FlatReturnNode(null);
55 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.PRE);
58 FlatMethod fm=new FlatMethod(td, fe);
61 Hashtable visitedset=new Hashtable();
63 for(int i=0; i<td.numParameters(); i++) {
64 VarDescriptor paramvd=td.getParameter(i);
65 fm.addParameterTemp(getTempforVar(paramvd));
66 TagExpressionList tel=td.getTag(paramvd);
67 //BUG added next line to fix...to test feed in any task program
69 for(int j=0; j<tel.numTags(); j++) {
70 TagVarDescriptor tvd=(TagVarDescriptor) td.getParameterTable().getFromSameScope(tel.getName(j));
71 TempDescriptor tagtmp=getTempforVar(tvd);
72 if (!visitedset.containsKey(tvd.getName())) {
73 visitedset.put(tvd.getName(),tvd.getTag());
74 fm.addTagTemp(tagtmp);
76 TagDescriptor tmptd=(TagDescriptor) visitedset.get(tvd.getName());
77 if (!tmptd.equals(tvd.getTag()))
78 throw new Error("Two different tag types with same name as parameters to:"+td);
80 tel.setTemp(j, tagtmp);
84 /* Flatten Vector of Flag Effects */
85 Vector flags=td.getFlagEffects();
86 updateFlagActionNode(ffan,flags);
88 state.addFlatCode(td,fm);
92 /* This method transforms a vector of FlagEffects into the FlatFlagActionNode */
93 private void updateFlagActionNode(FlatFlagActionNode ffan, Vector flags) {
94 if (flags==null) // Do nothing if the flag effects vector is empty
97 for(int i=0; i<flags.size(); i++) {
98 FlagEffects fes=(FlagEffects)flags.get(i);
99 TempDescriptor flagtemp=getTempforVar(fes.getVar());
101 for(int j=0; j<fes.numEffects(); j++) {
102 FlagEffect fe=fes.getEffect(j);
103 ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
106 for(int j=0; j<fes.numTagEffects(); j++) {
107 TagEffect te=fes.getTagEffect(j);
108 TempDescriptor tagtemp=getTempforVar(te.getTag());
110 ffan.addTagAction(flagtemp, te.getTag().getTag(), tagtemp, te.getStatus());
115 FlatAtomicEnterNode curran=null;
117 private FlatNode spliceReturn(FlatNode fn) {
118 FlatReturnNode rnflat=null;
119 if (currmd.getReturnType()==null||currmd.getReturnType().isVoid()) {
120 rnflat=new FlatReturnNode(null);
123 TempDescriptor tmp=TempDescriptor.tempFactory("rettmp",currmd.getReturnType());
124 Object o=currmd.getReturnType().isPtr()?null:new Integer(1);
125 FlatLiteralNode fln=new FlatLiteralNode(currmd.getReturnType(),o,tmp);
126 rnflat=new FlatReturnNode(tmp);
133 private void flattenClass(ClassDescriptor cn) {
134 Iterator methodit=cn.getMethods();
135 while(methodit.hasNext()) {
136 currmd=(MethodDescriptor)methodit.next();
138 // if MLP is on, splice a special SESE in to
139 // enclose the main method, and a special SESE
140 // in around every other method that statically
141 // represents the SESE instance that will call
142 // that method at runtime
143 FlatSESEEnterNode spliceSESE = null;
144 FlatSESEExitNode spliceExit = null;
146 if( currmd.equals( typeutil.getMain() ) ) {
147 SESENode mainTree = new SESENode( "main" );
148 spliceSESE = new FlatSESEEnterNode( mainTree );
149 spliceExit = new FlatSESEExitNode ( mainTree );
150 spliceSESE.setFlatExit ( spliceExit );
151 spliceExit.setFlatEnter( spliceSESE );
153 SESENode callerSESETree = new SESENode( "caller SESE placeholder" );
154 spliceSESE = new FlatSESEEnterNode( callerSESETree );
155 spliceSESE.setCallerSESEplaceholder();
156 spliceExit = new FlatSESEExitNode ( callerSESETree );
157 spliceSESE.setFlatExit ( spliceExit );
158 spliceExit.setFlatEnter( spliceSESE );
164 BlockNode bn=state.getMethodBody(currmd);
166 if (state.DSM&&currmd.getModifiers().isAtomic()) {
167 curran=new FlatAtomicEnterNode();
170 NodePair np=flattenBlockNode(bn);
171 FlatNode fn=np.getBegin();
172 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
173 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
174 TempDescriptor thistd=getTempforVar(currmd.getThis());
175 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
178 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
179 MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
180 FlatCall fcunlock=new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
181 np.getEnd().addNext(fcunlock);
182 FlatNode rnflat=spliceReturn(fcunlock);
185 } else if (state.DSM&&currmd.getModifiers().isAtomic()) {
188 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
189 FlatAtomicExitNode aen=new FlatAtomicExitNode(curran);
190 np.getEnd().addNext(aen);
191 FlatNode rnflat=spliceReturn(aen);
195 } else if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
196 FlatNode rnflat=null;
197 // splice implicit SESE exit after method body
199 np.getEnd().addNext(spliceExit);
200 rnflat=spliceReturn(spliceExit);
202 rnflat=spliceReturn(np.getEnd());
205 } else if (np.getEnd()!=null) {
206 // splice implicit SESE exit after method body
208 FlatReturnNode rnflat=(FlatReturnNode)np.getEnd();
209 np.getEnd().addNext(spliceExit);
210 spliceExit.addNext(fe);
214 // splice an implicit SESE enter before method body
216 spliceSESE.addNext(fn);
220 FlatMethod fm=new FlatMethod(currmd, fe);
222 if (!currmd.isStatic())
223 fm.addParameterTemp(getTempforParam(currmd.getThis()));
224 for(int i=0; i<currmd.numParameters(); i++) {
225 fm.addParameterTemp(getTempforParam(currmd.getParameter(i)));
228 state.addFlatCode(currmd,fm);
232 private NodePair flattenBlockNode(BlockNode bn) {
235 for(int i=0; i<bn.size(); i++) {
236 NodePair np=flattenBlockStatementNode(bn.get(i));
237 FlatNode np_begin=np.getBegin();
238 FlatNode np_end=np.getEnd();
245 end.addNext(np_begin);
247 return new NodePair(begin, null);
253 end=begin=new FlatNop();
255 return new NodePair(begin,end);
258 private NodePair flattenBlockExpressionNode(BlockExpressionNode en) {
259 //System.out.println("DEBUG -> inside flattenBlockExpressionNode\n");
260 TempDescriptor tmp=TempDescriptor.tempFactory("neverused",en.getExpression().getType());
261 return flattenExpressionNode(en.getExpression(),tmp);
264 private NodePair flattenCastNode(CastNode cn,TempDescriptor out_temp) {
265 TempDescriptor tmp=TempDescriptor.tempFactory("tocast",cn.getExpression().getType());
266 NodePair np=flattenExpressionNode(cn.getExpression(), tmp);
267 FlatCastNode fcn=new FlatCastNode(cn.getType(), tmp, out_temp);
268 np.getEnd().addNext(fcn);
269 return new NodePair(np.getBegin(),fcn);
272 private NodePair flattenLiteralNode(LiteralNode ln,TempDescriptor out_temp) {
273 FlatLiteralNode fln=new FlatLiteralNode(ln.getType(), ln.getValue(), out_temp);
274 return new NodePair(fln,fln);
277 private NodePair flattenOffsetNode(OffsetNode ofn, TempDescriptor out_temp) {
278 FlatOffsetNode fln = new FlatOffsetNode(ofn.getClassType(), ofn.getField(), out_temp);
279 return new NodePair(fln, fln);
282 private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) {
283 TypeDescriptor td=con.getType();
285 FlatNode fn=new FlatNew(td, out_temp, con.isGlobal(), con.getDisjointId());
287 //handle wrapper fields
288 ClassDescriptor cd=td.getClassDesc();
289 for(Iterator fieldit=cd.getFields();fieldit.hasNext();) {
290 FieldDescriptor fd=(FieldDescriptor)fieldit.next();
291 if (fd.getType().iswrapper()) {
292 TempDescriptor wrap_tmp=TempDescriptor.tempFactory("wrapper_obj",fd.getType());
293 FlatNode fnwrapper=new FlatNew(fd.getType(), wrap_tmp, con.isGlobal());
294 FlatSetFieldNode fsfn=new FlatSetFieldNode(out_temp, fd, wrap_tmp);
295 last.addNext(fnwrapper);
296 fnwrapper.addNext(fsfn);
301 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
304 for(int i=0; i<con.numArgs(); i++) {
305 ExpressionNode en=con.getArg(i);
306 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
308 NodePair np=flattenExpressionNode(en, tmp);
309 last.addNext(np.getBegin());
312 MethodDescriptor md=con.getConstructor();
313 //Call to constructor
314 FlatCall fc=new FlatCall(md, null, out_temp, temps);
317 if (td.getClassDesc().hasFlags()) {
318 // if (con.getFlagEffects()!=null) {
319 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.NEWOBJECT);
320 FlagEffects fes=con.getFlagEffects();
321 TempDescriptor flagtemp=out_temp;
323 for(int j=0; j<fes.numEffects(); j++) {
324 FlagEffect fe=fes.getEffect(j);
325 ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
327 for(int j=0; j<fes.numTagEffects(); j++) {
328 TagEffect te=fes.getTagEffect(j);
329 TempDescriptor tagtemp=getTempforVar(te.getTag());
331 ffan.addTagAction(flagtemp, te.getTag().getTag(), tagtemp, te.getStatus());
334 ffan.addFlagAction(flagtemp, null, false);
339 return new NodePair(fn,last);
343 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
344 for (int i=0; i<con.numArgs(); i++) {
345 ExpressionNode en=con.getArg(i);
346 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
348 NodePair np=flattenExpressionNode(en, tmp);
352 last.addNext(np.getBegin());
355 TempDescriptor tmp2=(i==0) ?
357 TempDescriptor.tempFactory("arg",en.getType());
359 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
361 if (temps.length>1) {
362 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
363 fn.addNext(np.getBegin());
364 return new NodePair(first,np.getEnd());
365 } else if (td.isArray()&&td.dereference().iswrapper()) {
366 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
367 fn.addNext(np.getBegin());
368 return new NodePair(first,np.getEnd());
370 return new NodePair(first, fn);
374 private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i, boolean isglobal) {
375 TempDescriptor index=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
376 TempDescriptor tmpone=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
377 FlatNop fnop=new FlatNop(); //last node
380 FlatLiteralNode fln=new FlatLiteralNode(index.getType(),new Integer(0),index);
382 FlatLiteralNode fln2=new FlatLiteralNode(tmpone.getType(),new Integer(1),tmpone);
384 TempDescriptor tmpbool=TempDescriptor.tempFactory("comp",new TypeDescriptor(TypeDescriptor.BOOLEAN));
386 FlatOpNode fcomp=new FlatOpNode(tmpbool,index,temparray[i],new Operation(Operation.LT));
387 FlatCondBranch fcb=new FlatCondBranch(tmpbool);
388 fcb.setTrueProb(State.TRUEPROB);
391 TempDescriptor new_tmp=TempDescriptor.tempFactory("tmp",td);
392 FlatNew fn=td.iswrapper()?new FlatNew(td, new_tmp, isglobal):new FlatNew(td, new_tmp, temparray[i+1], isglobal);
393 FlatSetElementNode fsen=new FlatSetElementNode(tmp,index,new_tmp);
395 FlatOpNode fon=new FlatOpNode(index,index,tmpone,new Operation(Operation.ADD));
401 fcb.addFalseNext(fnop);
403 //Recursive call here
404 if ((i+2)<temparray.length) {
405 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
406 fsen.addNext(np2.getBegin());
407 np2.getEnd().addNext(fon);
408 } else if (td.isArray()&&td.dereference().iswrapper()) {
409 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
410 fsen.addNext(np2.getBegin());
411 np2.getEnd().addNext(fon);
416 return new NodePair(fln, fnop);
419 private NodePair flattenMethodInvokeNode(MethodInvokeNode min,TempDescriptor out_temp) {
420 TempDescriptor[] temps=new TempDescriptor[min.numArgs()];
423 TempDescriptor thisarg=null;
425 if (min.getExpression()!=null) {
426 thisarg=TempDescriptor.tempFactory("thisarg",min.getExpression().getType());
427 NodePair np=flattenExpressionNode(min.getExpression(),thisarg);
433 for(int i=0; i<min.numArgs(); i++) {
434 ExpressionNode en=min.getArg(i);
435 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
437 NodePair np=flattenExpressionNode(en, td);
441 last.addNext(np.getBegin());
445 MethodDescriptor md=min.getMethod();
447 //Call to constructor
450 if(md.getReturnType()==null||md.getReturnType().isVoid())
451 fc=new FlatCall(md, null, thisarg, temps);
453 fc=new FlatCall(md, out_temp, thisarg, temps);
458 return new NodePair(first,fc);
461 private NodePair flattenFieldAccessNode(FieldAccessNode fan,TempDescriptor out_temp) {
462 TempDescriptor tmp=TempDescriptor.tempFactory("temp",fan.getExpression().getType());
463 NodePair npe=flattenExpressionNode(fan.getExpression(),tmp);
464 FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
465 npe.getEnd().addNext(fn);
466 return new NodePair(npe.getBegin(),fn);
469 private NodePair flattenArrayAccessNode(ArrayAccessNode aan,TempDescriptor out_temp) {
470 TempDescriptor tmp=TempDescriptor.tempFactory("temp",aan.getExpression().getType());
471 TempDescriptor tmpindex=TempDescriptor.tempFactory("temp",aan.getIndex().getType());
472 NodePair npe=flattenExpressionNode(aan.getExpression(),tmp);
473 NodePair npi=flattenExpressionNode(aan.getIndex(),tmpindex);
474 TempDescriptor arraytmp=out_temp;
475 if (aan.iswrapper()) {
477 arraytmp=TempDescriptor.tempFactory("temp", aan.getExpression().getType().dereference());
479 FlatNode fn=new FlatElementNode(tmp,tmpindex,arraytmp);
480 npe.getEnd().addNext(npi.getBegin());
481 npi.getEnd().addNext(fn);
482 if (aan.iswrapper()) {
483 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)aan.getExpression().getType().dereference().getClassDesc().getFieldTable().get("value") ,arraytmp,out_temp);
487 return new NodePair(npe.getBegin(),fn);
490 private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
492 // left side is variable
493 // left side is field
494 // left side is array
496 Operation base=an.getOperation().getBaseOp();
497 boolean pre=base==null||(base.getOp()!=Operation.POSTINC&&base.getOp()!=Operation.POSTDEC);
500 //rewrite the base operation
501 base=base.getOp()==Operation.POSTINC ? new Operation(Operation.ADD) : new Operation(Operation.SUB);
505 TempDescriptor src_tmp = src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
508 if (an.getSrc()!=null) {
509 NodePair np_src=flattenExpressionNode(an.getSrc(),src_tmp);
510 first=np_src.getBegin();
511 last=np_src.getEnd();
513 FlatLiteralNode fln=new FlatLiteralNode(new TypeDescriptor(TypeDescriptor.INT),new Integer(1),src_tmp);
518 if (an.getDest().kind()==Kind.FieldAccessNode) {
519 //We are assigning an object field
521 FieldAccessNode fan=(FieldAccessNode)an.getDest();
522 ExpressionNode en=fan.getExpression();
523 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
524 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
526 first=np_baseexp.getBegin();
528 last.addNext(np_baseexp.getBegin());
529 last=np_baseexp.getEnd();
531 //See if we need to perform an operation
533 //If it is a preinc we need to store the initial value
534 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
535 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
536 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
540 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
541 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
542 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
543 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
548 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
555 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
559 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
563 return new NodePair(first, last);
564 } else if (an.getDest().kind()==Kind.ArrayAccessNode) {
565 //We are assigning an array element
567 ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
568 ExpressionNode en=aan.getExpression();
569 ExpressionNode enindex=aan.getIndex();
570 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
571 TempDescriptor index_tmp=TempDescriptor.tempFactory("index",enindex.getType());
572 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
573 NodePair np_indexexp=flattenExpressionNode(enindex, index_tmp);
575 first=np_baseexp.getBegin();
577 last.addNext(np_baseexp.getBegin());
578 np_baseexp.getEnd().addNext(np_indexexp.getBegin());
579 last=np_indexexp.getEnd();
581 //See if we need to perform an operation
583 //If it is a preinc we need to store the initial value
584 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
585 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
587 if (aan.iswrapper()) {
588 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
589 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
590 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
591 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp3,src_tmp2);
596 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
600 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
601 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
602 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
603 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
608 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
615 if (aan.iswrapper()) {
616 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
617 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
618 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
619 FlatSetFieldNode fsfn=new FlatSetFieldNode(src_tmp3,(FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp);
624 FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
629 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
633 return new NodePair(first, last);
634 } else if (an.getDest().kind()==Kind.NameNode) {
635 //We could be assigning a field or variable
636 NameNode nn=(NameNode)an.getDest();
639 if (nn.getExpression()!=null) {
641 FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
642 ExpressionNode en=fan.getExpression();
643 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
644 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
646 first=np_baseexp.getBegin();
648 last.addNext(np_baseexp.getBegin());
649 last=np_baseexp.getEnd();
651 //See if we need to perform an operation
653 //If it is a preinc we need to store the initial value
654 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
655 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
657 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
662 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
663 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
664 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
665 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
670 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
678 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
682 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
686 return new NodePair(first, last);
688 if (nn.getField()!=null) {
692 //See if we need to perform an operation
694 //If it is a preinc we need to store the initial value
695 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
696 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
698 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), getTempforVar(nn.getVar()), src_tmp2);
707 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
708 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
709 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
710 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
715 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
722 FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
730 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
734 return new NodePair(first, last);
737 //See if we need to perform an operation
740 //If it is a preinc we need to store the initial value
741 TempDescriptor src_tmp2=getTempforVar(nn.getVar());
742 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
744 FlatOpNode fon=new FlatOpNode(out_temp, src_tmp2, null, new Operation(Operation.ASSIGN));
753 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
754 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
755 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
756 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
764 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
774 FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
779 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
783 return new NodePair(first, last);
791 private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
792 if (nn.getExpression()!=null) {
793 /* Hack - use subtree instead */
794 return flattenExpressionNode(nn.getExpression(),out_temp);
795 } else if (nn.getField()!=null) {
796 TempDescriptor tmp=getTempforVar(nn.getVar());
797 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
798 return new NodePair(ffn,ffn);
800 TempDescriptor tmp=getTempforVar(nn.isTag() ? nn.getTagVar() : nn.getVar());
803 out_temp.setTag(tmp.getTag());
805 FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
806 return new NodePair(fon,fon);
810 private NodePair flattenOpNode(OpNode on,TempDescriptor out_temp) {
811 TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
812 TempDescriptor temp_right=null;
814 Operation op=on.getOp();
816 NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
818 if (on.getRight()!=null) {
819 temp_right=TempDescriptor.tempFactory("rightop",on.getRight().getType());
820 right=flattenExpressionNode(on.getRight(),temp_right);
822 FlatNop nop=new FlatNop();
823 right=new NodePair(nop,nop);
826 if (op.getOp()==Operation.LOGIC_OR) {
827 /* Need to do shortcircuiting */
828 FlatCondBranch fcb=new FlatCondBranch(temp_left);
829 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
830 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
831 FlatNop fnop=new FlatNop();
832 left.getEnd().addNext(fcb);
833 fcb.addFalseNext(right.getBegin());
834 right.getEnd().addNext(fon2);
836 fcb.addTrueNext(fon1);
838 return new NodePair(left.getBegin(), fnop);
839 } else if (op.getOp()==Operation.LOGIC_AND) {
840 /* Need to do shortcircuiting */
841 FlatCondBranch fcb=new FlatCondBranch(temp_left);
842 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
843 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
844 FlatNop fnop=new FlatNop();
845 left.getEnd().addNext(fcb);
846 fcb.addTrueNext(right.getBegin());
847 right.getEnd().addNext(fon2);
849 fcb.addFalseNext(fon1);
851 return new NodePair(left.getBegin(), fnop);
852 } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
853 //We have a string concatenate
854 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
855 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
856 FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
857 left.getEnd().addNext(right.getBegin());
858 right.getEnd().addNext(fc);
859 return new NodePair(left.getBegin(), fc);
862 FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
863 left.getEnd().addNext(right.getBegin());
864 right.getEnd().addNext(fon);
865 return new NodePair(left.getBegin(),fon);
868 private NodePair flattenExpressionNode(ExpressionNode en, TempDescriptor out_temp) {
870 case Kind.AssignmentNode:
871 return flattenAssignmentNode((AssignmentNode)en,out_temp);
874 return flattenCastNode((CastNode)en,out_temp);
876 case Kind.CreateObjectNode:
877 return flattenCreateObjectNode((CreateObjectNode)en,out_temp);
879 case Kind.FieldAccessNode:
880 return flattenFieldAccessNode((FieldAccessNode)en,out_temp);
882 case Kind.ArrayAccessNode:
883 return flattenArrayAccessNode((ArrayAccessNode)en,out_temp);
885 case Kind.LiteralNode:
886 return flattenLiteralNode((LiteralNode)en,out_temp);
888 case Kind.MethodInvokeNode:
889 return flattenMethodInvokeNode((MethodInvokeNode)en,out_temp);
892 return flattenNameNode((NameNode)en,out_temp);
895 return flattenOpNode((OpNode)en,out_temp);
897 case Kind.OffsetNode:
898 return flattenOffsetNode((OffsetNode)en,out_temp);
900 case Kind.TertiaryNode:
901 return flattenTertiaryNode((TertiaryNode)en,out_temp);
903 case Kind.InstanceOfNode:
904 return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
906 case Kind.ArrayInitializerNode:
907 return flattenArrayInitializerNode((ArrayInitializerNode)en,out_temp);
912 private NodePair flattenDeclarationNode(DeclarationNode dn) {
913 VarDescriptor vd=dn.getVarDescriptor();
914 TempDescriptor td=getTempforVar(vd);
915 if (dn.getExpression()!=null)
916 return flattenExpressionNode(dn.getExpression(),td);
918 FlatNop fn=new FlatNop();
919 return new NodePair(fn,fn);
923 private NodePair flattenTagDeclarationNode(TagDeclarationNode dn) {
924 TagVarDescriptor tvd=dn.getTagVarDescriptor();
925 TagDescriptor tag=tvd.getTag();
926 TempDescriptor tmp=getTempforVar(tvd);
927 FlatTagDeclaration ftd=new FlatTagDeclaration(tag, tmp);
928 return new NodePair(ftd,ftd);
931 private TempDescriptor getTempforParam(Descriptor d) {
932 if (temptovar.containsKey(d))
933 return (TempDescriptor)temptovar.get(d);
935 if (d instanceof VarDescriptor) {
936 VarDescriptor vd=(VarDescriptor)d;
937 TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
938 temptovar.put(vd,td);
940 } else if (d instanceof TagVarDescriptor) {
941 TagVarDescriptor tvd=(TagVarDescriptor)d;
942 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
943 TempDescriptor td=TempDescriptor.paramtempFactory(tvd.getName(), tagtype, tvd.getTag());
944 temptovar.put(tvd,td);
946 } else throw new Error("Unreconized Descriptor");
950 private TempDescriptor getTempforVar(Descriptor d) {
951 if (temptovar.containsKey(d))
952 return (TempDescriptor)temptovar.get(d);
954 if (d instanceof VarDescriptor) {
955 VarDescriptor vd=(VarDescriptor)d;
956 TempDescriptor td=TempDescriptor.tempFactory(vd.getName(), vd.getType());
957 temptovar.put(vd,td);
959 } else if (d instanceof TagVarDescriptor) {
960 TagVarDescriptor tvd=(TagVarDescriptor)d;
961 //BUGFIX TAGTYPE - add next line, modify following
962 //line to tag this new type descriptor, modify
963 //TempDescriptor constructor & factory to set type
964 //using this Type To test, use any program with tags
965 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
966 TempDescriptor td=TempDescriptor.tempFactory(tvd.getName(),tagtype, tvd.getTag());
967 temptovar.put(tvd,td);
969 } else throw new Error("Unrecognized Descriptor");
973 private NodePair flattenIfStatementNode(IfStatementNode isn) {
974 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.BOOLEAN));
975 NodePair cond=flattenExpressionNode(isn.getCondition(),cond_temp);
976 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
977 NodePair true_np=flattenBlockNode(isn.getTrueBlock());
979 FlatNop nopend=new FlatNop();
981 if (isn.getFalseBlock()!=null)
982 false_np=flattenBlockNode(isn.getFalseBlock());
984 FlatNop nop=new FlatNop();
985 false_np=new NodePair(nop,nop);
988 cond.getEnd().addNext(fcb);
989 fcb.addTrueNext(true_np.getBegin());
990 fcb.addFalseNext(false_np.getBegin());
991 if (true_np.getEnd()!=null)
992 true_np.getEnd().addNext(nopend);
993 if (false_np.getEnd()!=null)
994 false_np.getEnd().addNext(nopend);
995 if (nopend.numPrev()==0)
996 return new NodePair(cond.getBegin(), null);
998 return new NodePair(cond.getBegin(), nopend);
1001 private NodePair flattenLoopNode(LoopNode ln) {
1002 HashSet oldbs=breakset;
1003 HashSet oldcs=continueset;
1004 breakset=new HashSet();
1005 continueset=new HashSet();
1007 if (ln.getType()==LoopNode.FORLOOP) {
1008 NodePair initializer=flattenBlockNode(ln.getInitializer());
1009 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1010 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1011 NodePair update=flattenBlockNode(ln.getUpdate());
1012 NodePair body=flattenBlockNode(ln.getBody());
1013 FlatNode begin=initializer.getBegin();
1014 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1015 fcb.setTrueProb(State.TRUEPROB);
1017 FlatNop nopend=new FlatNop();
1018 FlatBackEdge backedge=new FlatBackEdge();
1020 FlatNop nop2=new FlatNop();
1021 initializer.getEnd().addNext(nop2);
1022 nop2.addNext(condition.getBegin());
1023 if (body.getEnd()!=null)
1024 body.getEnd().addNext(update.getBegin());
1025 update.getEnd().addNext(backedge);
1026 backedge.addNext(condition.getBegin());
1027 condition.getEnd().addNext(fcb);
1028 fcb.addFalseNext(nopend);
1029 fcb.addTrueNext(body.getBegin());
1030 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1031 FlatNode fn=(FlatNode)contit.next();
1033 fn.addNext(update.getBegin());
1035 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1036 FlatNode fn=(FlatNode)breakit.next();
1042 return new NodePair(begin,nopend);
1043 } else if (ln.getType()==LoopNode.WHILELOOP) {
1044 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1045 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1046 NodePair body=flattenBlockNode(ln.getBody());
1047 FlatNode begin=condition.getBegin();
1048 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1049 fcb.setTrueProb(State.TRUEPROB);
1051 FlatNop nopend=new FlatNop();
1052 FlatBackEdge backedge=new FlatBackEdge();
1054 if (body.getEnd()!=null)
1055 body.getEnd().addNext(backedge);
1056 backedge.addNext(condition.getBegin());
1058 condition.getEnd().addNext(fcb);
1059 fcb.addFalseNext(nopend);
1060 fcb.addTrueNext(body.getBegin());
1062 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1063 FlatNode fn=(FlatNode)contit.next();
1065 fn.addNext(backedge);
1067 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1068 FlatNode fn=(FlatNode)breakit.next();
1074 return new NodePair(begin,nopend);
1075 } else if (ln.getType()==LoopNode.DOWHILELOOP) {
1076 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1077 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1078 NodePair body=flattenBlockNode(ln.getBody());
1079 FlatNode begin=body.getBegin();
1080 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1081 fcb.setTrueProb(State.TRUEPROB);
1083 FlatNop nopend=new FlatNop();
1084 FlatBackEdge backedge=new FlatBackEdge();
1086 if (body.getEnd()!=null)
1087 body.getEnd().addNext(condition.getBegin());
1088 condition.getEnd().addNext(fcb);
1089 fcb.addFalseNext(nopend);
1090 fcb.addTrueNext(backedge);
1091 backedge.addNext(body.getBegin());
1093 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1094 FlatNode fn=(FlatNode)contit.next();
1096 fn.addNext(condition.getBegin());
1098 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1099 FlatNode fn=(FlatNode)breakit.next();
1105 return new NodePair(begin,nopend);
1106 } else throw new Error();
1109 private NodePair flattenReturnNode(ReturnNode rntree) {
1110 TempDescriptor retval=null;
1112 if (rntree.getReturnExpression()!=null) {
1113 retval=TempDescriptor.tempFactory("ret_value", rntree.getReturnExpression().getType());
1114 cond=flattenExpressionNode(rntree.getReturnExpression(),retval);
1117 FlatReturnNode rnflat=new FlatReturnNode(retval);
1120 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
1121 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1122 TempDescriptor thistd=getTempforVar(currmd.getThis());
1123 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
1127 if (state.DSM&&currmd.getModifiers().isAtomic()) {
1128 FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
1134 cond.getEnd().addNext(ln);
1135 return new NodePair(cond.getBegin(),null);
1137 return new NodePair(ln,null);
1140 private NodePair flattenTaskExitNode(TaskExitNode ten) {
1141 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.TASKEXIT);
1142 ffan.setTaskExitIndex(ten.getTaskExitIndex());
1143 updateFlagActionNode(ffan, ten.getFlagEffects());
1144 NodePair fcn=flattenConstraintCheck(ten.getChecks());
1145 ffan.addNext(fcn.getBegin());
1146 FlatReturnNode rnflat=new FlatReturnNode(null);
1148 fcn.getEnd().addNext(rnflat);
1149 return new NodePair(ffan, null);
1152 private NodePair flattenConstraintCheck(Vector ccs) {
1153 FlatNode begin=new FlatNop();
1155 return new NodePair(begin,begin);
1156 FlatNode last=begin;
1157 for(int i=0; i<ccs.size(); i++) {
1158 ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
1159 /* Flatten the arguments */
1160 TempDescriptor[] temps=new TempDescriptor[cc.numArgs()];
1161 String[] vars=new String[cc.numArgs()];
1162 for(int j=0; j<cc.numArgs(); j++) {
1163 ExpressionNode en=cc.getArg(j);
1164 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
1166 vars[j]=cc.getVar(j);
1167 NodePair np=flattenExpressionNode(en, td);
1168 last.addNext(np.getBegin());
1172 FlatCheckNode fcn=new FlatCheckNode(cc.getSpec(), vars, temps);
1176 return new NodePair(begin,last);
1179 private NodePair flattenSubBlockNode(SubBlockNode sbn) {
1180 return flattenBlockNode(sbn.getBlockNode());
1183 private NodePair flattenSynchronizedNode(SynchronizedNode sbn) {
1184 TempDescriptor montmp=TempDescriptor.tempFactory("monitor",sbn.getExpr().getType());
1185 NodePair npexp=flattenExpressionNode(sbn.getExpr(), montmp);
1186 NodePair npblock=flattenBlockNode(sbn.getBlockNode());
1188 MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
1189 FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
1191 MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1192 FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
1194 npexp.getEnd().addNext(fcen);
1195 fcen.addNext(npblock.getBegin());
1196 npblock.getEnd().addNext(fcex);
1197 return new NodePair(npexp.getBegin(), fcex);
1200 private NodePair flattenAtomicNode(AtomicNode sbn) {
1201 NodePair np=flattenBlockNode(sbn.getBlockNode());
1202 FlatAtomicEnterNode faen=new FlatAtomicEnterNode();
1203 FlatAtomicExitNode faexn=new FlatAtomicExitNode(faen);
1204 faen.addNext(np.getBegin());
1205 np.getEnd().addNext(faexn);
1206 return new NodePair(faen, faexn);
1209 private NodePair flattenSESENode(SESENode sn) {
1210 if( sn.isStart() ) {
1211 FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn);
1212 sn.setFlatEnter(fsen);
1213 return new NodePair(fsen, fsen);
1216 FlatSESEExitNode fsexn=new FlatSESEExitNode(sn);
1217 sn.setFlatExit(fsexn);
1218 FlatSESEEnterNode fsen=sn.getStart().getFlatEnter();
1219 fsexn.setFlatEnter(fsen);
1220 sn.getStart().getFlatEnter().setFlatExit( fsexn );
1222 return new NodePair(fsexn, fsexn);
1225 private NodePair flattenContinueBreakNode(ContinueBreakNode cbn) {
1226 FlatNop fn=new FlatNop();
1230 continueset.add(fn);
1231 return new NodePair(fn,null);
1234 private NodePair flattenInstanceOfNode(InstanceOfNode tn, TempDescriptor out_temp) {
1235 TempDescriptor expr_temp=TempDescriptor.tempFactory("expr",tn.getExpr().getType());
1236 NodePair cond=flattenExpressionNode(tn.getExpr(), expr_temp);
1237 FlatInstanceOfNode fion=new FlatInstanceOfNode(tn.getExprType(), expr_temp, out_temp);
1238 cond.getEnd().addNext(fion);
1239 return new NodePair(cond.getBegin(),fion);
1242 private NodePair flattenArrayInitializerNode(ArrayInitializerNode ain, TempDescriptor out_temp) {
1244 TempDescriptor expr_temp=TempDescriptor.tempFactory("arry_init",ain.getType());
1246 // create a new array of size equal to the array initializer
1247 //FlatNode first=null;
1248 //FlatNode last=null;
1249 TempDescriptor[] temps=new TempDescriptor[ain.numVarInitializers()];
1251 for (int i=0; i<con.numArgs(); i++) {
1252 ExpressionNode en=con.getArg(i);
1253 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
1255 NodePair np=flattenExpressionNode(en, tmp);
1257 first=np.getBegin();
1259 last.addNext(np.getBegin());
1262 TempDescriptor tmp2=(i==0) ?
1264 TempDescriptor.tempFactory("arg",en.getType());
1266 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
1270 // assign each element of the new array to the flattened expression
1273 FlatOpNode fonAssignArray=new FlatOpNode(out_temp, newarry_temp, null, new Operation(Operation.ASSIGN));
1275 //return new NodePair( , fonAssignArray );
1277 System.out.println( "Array initializers not implemented yet." );
1282 private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
1283 TempDescriptor cond_temp=TempDescriptor.tempFactory("tert_cond",new TypeDescriptor(TypeDescriptor.BOOLEAN));
1284 TempDescriptor true_temp=TempDescriptor.tempFactory("tert_true",tn.getTrueExpr().getType());
1285 TempDescriptor fals_temp=TempDescriptor.tempFactory("tert_fals",tn.getFalseExpr().getType());
1287 NodePair cond=flattenExpressionNode(tn.getCond(),cond_temp);
1288 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1290 NodePair trueExpr=flattenExpressionNode(tn.getTrueExpr(),true_temp);
1291 FlatOpNode fonT=new FlatOpNode(out_temp, true_temp, null, new Operation(Operation.ASSIGN));
1293 NodePair falseExpr=flattenExpressionNode(tn.getFalseExpr(),fals_temp);
1294 FlatOpNode fonF=new FlatOpNode(out_temp, fals_temp, null, new Operation(Operation.ASSIGN));
1296 FlatNop nopend=new FlatNop();
1298 cond.getEnd().addNext(fcb);
1300 fcb.addTrueNext(trueExpr.getBegin());
1301 fcb.addFalseNext(falseExpr.getBegin());
1303 trueExpr.getEnd().addNext(fonT);
1304 fonT.addNext(nopend);
1306 falseExpr.getEnd().addNext(fonF);
1307 fonF.addNext(nopend);
1309 return new NodePair(cond.getBegin(), nopend);
1312 private NodePair flattenBlockStatementNode(BlockStatementNode bsn) {
1313 switch(bsn.kind()) {
1314 case Kind.BlockExpressionNode:
1315 return flattenBlockExpressionNode((BlockExpressionNode)bsn);
1317 case Kind.DeclarationNode:
1318 return flattenDeclarationNode((DeclarationNode)bsn);
1320 case Kind.TagDeclarationNode:
1321 return flattenTagDeclarationNode((TagDeclarationNode)bsn);
1323 case Kind.IfStatementNode:
1324 return flattenIfStatementNode((IfStatementNode)bsn);
1327 return flattenLoopNode((LoopNode)bsn);
1329 case Kind.ReturnNode:
1330 return flattenReturnNode((IR.Tree.ReturnNode)bsn);
1332 case Kind.TaskExitNode:
1333 return flattenTaskExitNode((IR.Tree.TaskExitNode)bsn);
1335 case Kind.SubBlockNode:
1336 return flattenSubBlockNode((SubBlockNode)bsn);
1338 case Kind.AtomicNode:
1339 return flattenAtomicNode((AtomicNode)bsn);
1341 case Kind.SynchronizedNode:
1342 return flattenSynchronizedNode((SynchronizedNode)bsn);
1345 return flattenSESENode((SESENode)bsn);
1347 case Kind.ContinueBreakNode:
1348 return flattenContinueBreakNode((ContinueBreakNode)bsn);