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());
125 if (currmd.getReturnType().isPtr()) {
127 } else if (currmd.getReturnType().isByte()) {
129 } else if (currmd.getReturnType().isShort()) {
130 o=new Short((short)0);
131 } else if (currmd.getReturnType().isChar()) {
132 o=new Character('\0');
133 } else if (currmd.getReturnType().isInt()) {
135 } else if (currmd.getReturnType().isLong()) {
137 } else if (currmd.getReturnType().isBoolean()) {
138 o=new Boolean(false);
139 } else if (currmd.getReturnType().isFloat()) {
141 } else if (currmd.getReturnType().isDouble()) {
146 FlatLiteralNode fln=new FlatLiteralNode(currmd.getReturnType(),o,tmp);
147 rnflat=new FlatReturnNode(tmp);
154 private void flattenClass(ClassDescriptor cn) {
155 Iterator methodit=cn.getMethods();
156 while(methodit.hasNext()) {
157 currmd=(MethodDescriptor)methodit.next();
159 // if MLP is on, splice a special SESE in to
160 // enclose the main method, and a special SESE
161 // in around every other method that statically
162 // represents the SESE instance that will call
163 // that method at runtime
164 FlatSESEEnterNode spliceSESE = null;
165 FlatSESEExitNode spliceExit = null;
166 if( state.MLP || state.OOOJAVA ) {
167 if( currmd.equals( typeutil.getMain() ) ) {
168 SESENode mainTree = new SESENode( "main" );
169 spliceSESE = new FlatSESEEnterNode( mainTree );
170 spliceExit = new FlatSESEExitNode ( mainTree );
171 spliceSESE.setFlatExit ( spliceExit );
172 spliceExit.setFlatEnter( spliceSESE );
174 SESENode callerSESETree = new SESENode( "caller SESE placeholder" );
175 spliceSESE = new FlatSESEEnterNode( callerSESETree );
176 spliceSESE.setCallerSESEplaceholder();
177 spliceExit = new FlatSESEExitNode ( callerSESETree );
178 spliceSESE.setFlatExit ( spliceExit );
179 spliceExit.setFlatEnter( spliceSESE );
185 BlockNode bn=state.getMethodBody(currmd);
187 if (state.DSM&&currmd.getModifiers().isAtomic()) {
188 curran=new FlatAtomicEnterNode();
191 NodePair np=flattenBlockNode(bn);
192 FlatNode fn=np.getBegin();
193 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
194 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
195 TempDescriptor thistd=getTempforVar(currmd.getThis());
196 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
199 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
200 MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
201 FlatCall fcunlock=new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
202 np.getEnd().addNext(fcunlock);
203 FlatNode rnflat=spliceReturn(fcunlock);
206 } else if (state.DSM&&currmd.getModifiers().isAtomic()) {
209 if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
210 FlatAtomicExitNode aen=new FlatAtomicExitNode(curran);
211 np.getEnd().addNext(aen);
212 FlatNode rnflat=spliceReturn(aen);
216 } else if (np.getEnd()!=null&&np.getEnd().kind()!=FKind.FlatReturnNode) {
217 FlatNode rnflat=null;
218 // splice implicit SESE exit after method body
219 if( state.MLP || state.OOOJAVA ) {
220 np.getEnd().addNext(spliceExit);
221 rnflat=spliceReturn(spliceExit);
223 rnflat=spliceReturn(np.getEnd());
226 } else if (np.getEnd()!=null) {
227 // splice implicit SESE exit after method body
228 if( state.MLP || state.OOOJAVA ) {
229 FlatReturnNode rnflat=(FlatReturnNode)np.getEnd();
230 np.getEnd().addNext(spliceExit);
231 spliceExit.addNext(fe);
235 // splice an implicit SESE enter before method body
236 if( state.MLP || state.OOOJAVA ) {
237 spliceSESE.addNext(fn);
241 FlatMethod fm=new FlatMethod(currmd, fe);
243 if (!currmd.isStatic())
244 fm.addParameterTemp(getTempforParam(currmd.getThis()));
245 for(int i=0; i<currmd.numParameters(); i++) {
246 fm.addParameterTemp(getTempforParam(currmd.getParameter(i)));
249 state.addFlatCode(currmd,fm);
253 private NodePair flattenBlockNode(BlockNode bn) {
256 for(int i=0; i<bn.size(); i++) {
257 NodePair np=flattenBlockStatementNode(bn.get(i));
258 FlatNode np_begin=np.getBegin();
259 FlatNode np_end=np.getEnd();
266 end.addNext(np_begin);
268 return new NodePair(begin, null);
274 end=begin=new FlatNop();
276 return new NodePair(begin,end);
279 private NodePair flattenBlockExpressionNode(BlockExpressionNode en) {
280 //System.out.println("DEBUG -> inside flattenBlockExpressionNode\n");
281 TempDescriptor tmp=TempDescriptor.tempFactory("neverused",en.getExpression().getType());
282 return flattenExpressionNode(en.getExpression(),tmp);
285 private NodePair flattenCastNode(CastNode cn,TempDescriptor out_temp) {
286 TempDescriptor tmp=TempDescriptor.tempFactory("tocast",cn.getExpression().getType());
287 NodePair np=flattenExpressionNode(cn.getExpression(), tmp);
288 FlatCastNode fcn=new FlatCastNode(cn.getType(), tmp, out_temp);
289 np.getEnd().addNext(fcn);
290 return new NodePair(np.getBegin(),fcn);
293 private NodePair flattenLiteralNode(LiteralNode ln,TempDescriptor out_temp) {
294 FlatLiteralNode fln=new FlatLiteralNode(ln.getType(), ln.getValue(), out_temp);
295 return new NodePair(fln,fln);
298 private NodePair flattenOffsetNode(OffsetNode ofn, TempDescriptor out_temp) {
299 FlatOffsetNode fln = new FlatOffsetNode(ofn.getClassType(), ofn.getField(), out_temp);
300 return new NodePair(fln, fln);
303 private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) {
304 TypeDescriptor td=con.getType();
306 FlatNode fn=new FlatNew(td, out_temp, con.isGlobal(), con.getDisjointId());
308 //handle wrapper fields
309 ClassDescriptor cd=td.getClassDesc();
310 for(Iterator fieldit=cd.getFields();fieldit.hasNext();) {
311 FieldDescriptor fd=(FieldDescriptor)fieldit.next();
312 if (fd.getType().iswrapper()) {
313 TempDescriptor wrap_tmp=TempDescriptor.tempFactory("wrapper_obj",fd.getType());
314 FlatNode fnwrapper=new FlatNew(fd.getType(), wrap_tmp, con.isGlobal());
315 FlatSetFieldNode fsfn=new FlatSetFieldNode(out_temp, fd, wrap_tmp);
316 last.addNext(fnwrapper);
317 fnwrapper.addNext(fsfn);
322 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
325 for(int i=0; i<con.numArgs(); i++) {
326 ExpressionNode en=con.getArg(i);
327 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
329 NodePair np=flattenExpressionNode(en, tmp);
330 last.addNext(np.getBegin());
333 MethodDescriptor md=con.getConstructor();
334 //Call to constructor
335 FlatCall fc=new FlatCall(md, null, out_temp, temps);
338 if (td.getClassDesc().hasFlags()) {
339 // if (con.getFlagEffects()!=null) {
340 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.NEWOBJECT);
341 FlagEffects fes=con.getFlagEffects();
342 TempDescriptor flagtemp=out_temp;
344 for(int j=0; j<fes.numEffects(); j++) {
345 FlagEffect fe=fes.getEffect(j);
346 ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
348 for(int j=0; j<fes.numTagEffects(); j++) {
349 TagEffect te=fes.getTagEffect(j);
350 TempDescriptor tagtemp=getTempforVar(te.getTag());
352 ffan.addTagAction(flagtemp, te.getTag().getTag(), tagtemp, te.getStatus());
355 ffan.addFlagAction(flagtemp, null, false);
360 return new NodePair(fn,last);
364 TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
365 for (int i=0; i<con.numArgs(); i++) {
366 ExpressionNode en=con.getArg(i);
367 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
369 NodePair np=flattenExpressionNode(en, tmp);
373 last.addNext(np.getBegin());
376 TempDescriptor tmp2=(i==0) ?
378 TempDescriptor.tempFactory("arg",en.getType());
380 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
382 if (temps.length>1) {
383 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
384 fn.addNext(np.getBegin());
385 return new NodePair(first,np.getEnd());
386 } else if (td.isArray()&&td.dereference().iswrapper()) {
387 NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
388 fn.addNext(np.getBegin());
389 return new NodePair(first,np.getEnd());
391 return new NodePair(first, fn);
395 private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i, boolean isglobal) {
396 TempDescriptor index=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
397 TempDescriptor tmpone=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT));
398 FlatNop fnop=new FlatNop(); //last node
401 FlatLiteralNode fln=new FlatLiteralNode(index.getType(),new Integer(0),index);
403 FlatLiteralNode fln2=new FlatLiteralNode(tmpone.getType(),new Integer(1),tmpone);
405 TempDescriptor tmpbool=TempDescriptor.tempFactory("comp",new TypeDescriptor(TypeDescriptor.BOOLEAN));
407 FlatOpNode fcomp=new FlatOpNode(tmpbool,index,temparray[i],new Operation(Operation.LT));
408 FlatCondBranch fcb=new FlatCondBranch(tmpbool);
409 fcb.setTrueProb(State.TRUEPROB);
412 TempDescriptor new_tmp=TempDescriptor.tempFactory("tmp",td);
413 FlatNew fn=td.iswrapper()?new FlatNew(td, new_tmp, isglobal):new FlatNew(td, new_tmp, temparray[i+1], isglobal);
414 FlatSetElementNode fsen=new FlatSetElementNode(tmp,index,new_tmp);
416 FlatOpNode fon=new FlatOpNode(index,index,tmpone,new Operation(Operation.ADD));
422 fcb.addFalseNext(fnop);
424 //Recursive call here
425 if ((i+2)<temparray.length) {
426 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
427 fsen.addNext(np2.getBegin());
428 np2.getEnd().addNext(fon);
429 } else if (td.isArray()&&td.dereference().iswrapper()) {
430 NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
431 fsen.addNext(np2.getBegin());
432 np2.getEnd().addNext(fon);
437 return new NodePair(fln, fnop);
440 private NodePair flattenMethodInvokeNode(MethodInvokeNode min,TempDescriptor out_temp) {
441 TempDescriptor[] temps=new TempDescriptor[min.numArgs()];
444 TempDescriptor thisarg=null;
446 if (min.getExpression()!=null) {
447 thisarg=TempDescriptor.tempFactory("thisarg",min.getExpression().getType());
448 NodePair np=flattenExpressionNode(min.getExpression(),thisarg);
454 for(int i=0; i<min.numArgs(); i++) {
455 ExpressionNode en=min.getArg(i);
456 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
458 NodePair np=flattenExpressionNode(en, td);
462 last.addNext(np.getBegin());
466 MethodDescriptor md=min.getMethod();
468 //Call to constructor
471 if(md.getReturnType()==null||md.getReturnType().isVoid())
472 fc=new FlatCall(md, null, thisarg, temps);
474 fc=new FlatCall(md, out_temp, thisarg, temps);
479 return new NodePair(first,fc);
482 private NodePair flattenFieldAccessNode(FieldAccessNode fan,TempDescriptor out_temp) {
483 TempDescriptor tmp=TempDescriptor.tempFactory("temp",fan.getExpression().getType());
484 NodePair npe=flattenExpressionNode(fan.getExpression(),tmp);
485 FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
486 npe.getEnd().addNext(fn);
487 return new NodePair(npe.getBegin(),fn);
490 private NodePair flattenArrayAccessNode(ArrayAccessNode aan,TempDescriptor out_temp) {
491 TempDescriptor tmp=TempDescriptor.tempFactory("temp",aan.getExpression().getType());
492 TempDescriptor tmpindex=TempDescriptor.tempFactory("temp",aan.getIndex().getType());
493 NodePair npe=flattenExpressionNode(aan.getExpression(),tmp);
494 NodePair npi=flattenExpressionNode(aan.getIndex(),tmpindex);
495 TempDescriptor arraytmp=out_temp;
496 if (aan.iswrapper()) {
498 arraytmp=TempDescriptor.tempFactory("temp", aan.getExpression().getType().dereference());
500 FlatNode fn=new FlatElementNode(tmp,tmpindex,arraytmp);
501 npe.getEnd().addNext(npi.getBegin());
502 npi.getEnd().addNext(fn);
503 if (aan.iswrapper()) {
504 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)aan.getExpression().getType().dereference().getClassDesc().getFieldTable().get("value") ,arraytmp,out_temp);
508 return new NodePair(npe.getBegin(),fn);
511 private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
513 // left side is variable
514 // left side is field
515 // left side is array
517 Operation base=an.getOperation().getBaseOp();
518 boolean pre=base==null||(base.getOp()!=Operation.POSTINC&&base.getOp()!=Operation.POSTDEC);
521 //rewrite the base operation
522 base=base.getOp()==Operation.POSTINC ? new Operation(Operation.ADD) : new Operation(Operation.SUB);
526 TempDescriptor src_tmp = src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
529 if (an.getSrc()!=null) {
530 NodePair np_src=flattenExpressionNode(an.getSrc(),src_tmp);
531 first=np_src.getBegin();
532 last=np_src.getEnd();
534 FlatLiteralNode fln=new FlatLiteralNode(new TypeDescriptor(TypeDescriptor.INT),new Integer(1),src_tmp);
539 if (an.getDest().kind()==Kind.FieldAccessNode) {
540 //We are assigning an object field
542 FieldAccessNode fan=(FieldAccessNode)an.getDest();
543 ExpressionNode en=fan.getExpression();
544 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
545 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
547 first=np_baseexp.getBegin();
549 last.addNext(np_baseexp.getBegin());
550 last=np_baseexp.getEnd();
552 //See if we need to perform an operation
554 //If it is a preinc we need to store the initial value
555 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
556 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
557 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
561 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
562 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
563 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
564 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
569 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
576 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
580 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
584 return new NodePair(first, last);
585 } else if (an.getDest().kind()==Kind.ArrayAccessNode) {
586 //We are assigning an array element
588 ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
589 ExpressionNode en=aan.getExpression();
590 ExpressionNode enindex=aan.getIndex();
591 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
592 TempDescriptor index_tmp=TempDescriptor.tempFactory("index",enindex.getType());
593 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
594 NodePair np_indexexp=flattenExpressionNode(enindex, index_tmp);
596 first=np_baseexp.getBegin();
598 last.addNext(np_baseexp.getBegin());
599 np_baseexp.getEnd().addNext(np_indexexp.getBegin());
600 last=np_indexexp.getEnd();
602 //See if we need to perform an operation
604 //If it is a preinc we need to store the initial value
605 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
606 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
608 if (aan.iswrapper()) {
609 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
610 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
611 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
612 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp3,src_tmp2);
617 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
621 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
622 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
623 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
624 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
629 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
636 if (aan.iswrapper()) {
637 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
638 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
639 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
640 FlatSetFieldNode fsfn=new FlatSetFieldNode(src_tmp3,(FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp);
645 FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
650 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
654 return new NodePair(first, last);
655 } else if (an.getDest().kind()==Kind.NameNode) {
656 //We could be assigning a field or variable
657 NameNode nn=(NameNode)an.getDest();
660 if (nn.getExpression()!=null) {
662 FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
663 ExpressionNode en=fan.getExpression();
664 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
665 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
667 first=np_baseexp.getBegin();
669 last.addNext(np_baseexp.getBegin());
670 last=np_baseexp.getEnd();
672 //See if we need to perform an operation
674 //If it is a preinc we need to store the initial value
675 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
676 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
678 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
683 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
684 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
685 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
686 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
691 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
699 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
703 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
707 return new NodePair(first, last);
709 if (nn.getField()!=null) {
713 //See if we need to perform an operation
715 //If it is a preinc we need to store the initial value
716 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
717 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
719 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), getTempforVar(nn.getVar()), src_tmp2);
728 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
729 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
730 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
731 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
736 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
743 FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
751 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
755 return new NodePair(first, last);
758 //See if we need to perform an operation
761 //If it is a preinc we need to store the initial value
762 TempDescriptor src_tmp2=getTempforVar(nn.getVar());
763 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
765 FlatOpNode fon=new FlatOpNode(out_temp, src_tmp2, null, new Operation(Operation.ASSIGN));
774 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
775 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
776 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
777 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
785 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
795 FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
800 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
804 return new NodePair(first, last);
812 private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
813 if (nn.getExpression()!=null) {
814 /* Hack - use subtree instead */
815 return flattenExpressionNode(nn.getExpression(),out_temp);
816 } else if (nn.getField()!=null) {
817 TempDescriptor tmp=getTempforVar(nn.getVar());
818 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
819 return new NodePair(ffn,ffn);
821 TempDescriptor tmp=getTempforVar(nn.isTag() ? nn.getTagVar() : nn.getVar());
824 out_temp.setTag(tmp.getTag());
826 FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
827 return new NodePair(fon,fon);
831 private NodePair flattenOpNode(OpNode on,TempDescriptor out_temp) {
832 TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
833 TempDescriptor temp_right=null;
835 Operation op=on.getOp();
837 NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
839 if (on.getRight()!=null) {
840 temp_right=TempDescriptor.tempFactory("rightop",on.getRight().getType());
841 right=flattenExpressionNode(on.getRight(),temp_right);
843 FlatNop nop=new FlatNop();
844 right=new NodePair(nop,nop);
847 if (op.getOp()==Operation.LOGIC_OR) {
848 /* Need to do shortcircuiting */
849 FlatCondBranch fcb=new FlatCondBranch(temp_left);
850 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
851 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
852 FlatNop fnop=new FlatNop();
853 left.getEnd().addNext(fcb);
854 fcb.addFalseNext(right.getBegin());
855 right.getEnd().addNext(fon2);
857 fcb.addTrueNext(fon1);
859 return new NodePair(left.getBegin(), fnop);
860 } else if (op.getOp()==Operation.LOGIC_AND) {
861 /* Need to do shortcircuiting */
862 FlatCondBranch fcb=new FlatCondBranch(temp_left);
863 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
864 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
865 FlatNop fnop=new FlatNop();
866 left.getEnd().addNext(fcb);
867 fcb.addTrueNext(right.getBegin());
868 right.getEnd().addNext(fon2);
870 fcb.addFalseNext(fon1);
872 return new NodePair(left.getBegin(), fnop);
873 } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
874 //We have a string concatenate
875 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
876 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
877 FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
878 left.getEnd().addNext(right.getBegin());
879 right.getEnd().addNext(fc);
880 return new NodePair(left.getBegin(), fc);
883 FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
884 left.getEnd().addNext(right.getBegin());
885 right.getEnd().addNext(fon);
886 return new NodePair(left.getBegin(),fon);
889 private NodePair flattenExpressionNode(ExpressionNode en, TempDescriptor out_temp) {
891 case Kind.AssignmentNode:
892 return flattenAssignmentNode((AssignmentNode)en,out_temp);
895 return flattenCastNode((CastNode)en,out_temp);
897 case Kind.CreateObjectNode:
898 return flattenCreateObjectNode((CreateObjectNode)en,out_temp);
900 case Kind.FieldAccessNode:
901 return flattenFieldAccessNode((FieldAccessNode)en,out_temp);
903 case Kind.ArrayAccessNode:
904 return flattenArrayAccessNode((ArrayAccessNode)en,out_temp);
906 case Kind.LiteralNode:
907 return flattenLiteralNode((LiteralNode)en,out_temp);
909 case Kind.MethodInvokeNode:
910 return flattenMethodInvokeNode((MethodInvokeNode)en,out_temp);
913 return flattenNameNode((NameNode)en,out_temp);
916 return flattenOpNode((OpNode)en,out_temp);
918 case Kind.OffsetNode:
919 return flattenOffsetNode((OffsetNode)en,out_temp);
921 case Kind.TertiaryNode:
922 return flattenTertiaryNode((TertiaryNode)en,out_temp);
924 case Kind.InstanceOfNode:
925 return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
927 case Kind.ArrayInitializerNode:
928 return flattenArrayInitializerNode((ArrayInitializerNode)en,out_temp);
933 private NodePair flattenDeclarationNode(DeclarationNode dn) {
934 VarDescriptor vd=dn.getVarDescriptor();
935 TempDescriptor td=getTempforVar(vd);
936 if (dn.getExpression()!=null)
937 return flattenExpressionNode(dn.getExpression(),td);
939 FlatNop fn=new FlatNop();
940 return new NodePair(fn,fn);
944 private NodePair flattenTagDeclarationNode(TagDeclarationNode dn) {
945 TagVarDescriptor tvd=dn.getTagVarDescriptor();
946 TagDescriptor tag=tvd.getTag();
947 TempDescriptor tmp=getTempforVar(tvd);
948 FlatTagDeclaration ftd=new FlatTagDeclaration(tag, tmp);
949 return new NodePair(ftd,ftd);
952 private TempDescriptor getTempforParam(Descriptor d) {
953 if (temptovar.containsKey(d))
954 return (TempDescriptor)temptovar.get(d);
956 if (d instanceof VarDescriptor) {
957 VarDescriptor vd=(VarDescriptor)d;
958 TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
959 temptovar.put(vd,td);
961 } else if (d instanceof TagVarDescriptor) {
962 TagVarDescriptor tvd=(TagVarDescriptor)d;
963 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
964 TempDescriptor td=TempDescriptor.paramtempFactory(tvd.getName(), tagtype, tvd.getTag());
965 temptovar.put(tvd,td);
967 } else throw new Error("Unreconized Descriptor");
971 private TempDescriptor getTempforVar(Descriptor d) {
972 if (temptovar.containsKey(d))
973 return (TempDescriptor)temptovar.get(d);
975 if (d instanceof VarDescriptor) {
976 VarDescriptor vd=(VarDescriptor)d;
977 TempDescriptor td=TempDescriptor.tempFactory(vd.getName(), vd.getType());
978 temptovar.put(vd,td);
980 } else if (d instanceof TagVarDescriptor) {
981 TagVarDescriptor tvd=(TagVarDescriptor)d;
982 //BUGFIX TAGTYPE - add next line, modify following
983 //line to tag this new type descriptor, modify
984 //TempDescriptor constructor & factory to set type
985 //using this Type To test, use any program with tags
986 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
987 TempDescriptor td=TempDescriptor.tempFactory(tvd.getName(),tagtype, tvd.getTag());
988 temptovar.put(tvd,td);
990 } else throw new Error("Unrecognized Descriptor");
994 private NodePair flattenIfStatementNode(IfStatementNode isn) {
995 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.BOOLEAN));
996 NodePair cond=flattenExpressionNode(isn.getCondition(),cond_temp);
997 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
998 NodePair true_np=flattenBlockNode(isn.getTrueBlock());
1000 FlatNop nopend=new FlatNop();
1002 if (isn.getFalseBlock()!=null)
1003 false_np=flattenBlockNode(isn.getFalseBlock());
1005 FlatNop nop=new FlatNop();
1006 false_np=new NodePair(nop,nop);
1009 cond.getEnd().addNext(fcb);
1010 fcb.addTrueNext(true_np.getBegin());
1011 fcb.addFalseNext(false_np.getBegin());
1012 if (true_np.getEnd()!=null)
1013 true_np.getEnd().addNext(nopend);
1014 if (false_np.getEnd()!=null)
1015 false_np.getEnd().addNext(nopend);
1016 if (nopend.numPrev()==0)
1017 return new NodePair(cond.getBegin(), null);
1019 return new NodePair(cond.getBegin(), nopend);
1022 private NodePair flattenLoopNode(LoopNode ln) {
1023 HashSet oldbs=breakset;
1024 HashSet oldcs=continueset;
1025 breakset=new HashSet();
1026 continueset=new HashSet();
1028 if (ln.getType()==LoopNode.FORLOOP) {
1029 NodePair initializer=flattenBlockNode(ln.getInitializer());
1030 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1031 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1032 NodePair update=flattenBlockNode(ln.getUpdate());
1033 NodePair body=flattenBlockNode(ln.getBody());
1034 FlatNode begin=initializer.getBegin();
1035 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1036 fcb.setTrueProb(State.TRUEPROB);
1038 FlatNop nopend=new FlatNop();
1039 FlatBackEdge backedge=new FlatBackEdge();
1041 FlatNop nop2=new FlatNop();
1042 initializer.getEnd().addNext(nop2);
1043 nop2.addNext(condition.getBegin());
1044 if (body.getEnd()!=null)
1045 body.getEnd().addNext(update.getBegin());
1046 update.getEnd().addNext(backedge);
1047 backedge.addNext(condition.getBegin());
1048 condition.getEnd().addNext(fcb);
1049 fcb.addFalseNext(nopend);
1050 fcb.addTrueNext(body.getBegin());
1051 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1052 FlatNode fn=(FlatNode)contit.next();
1054 fn.addNext(update.getBegin());
1056 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1057 FlatNode fn=(FlatNode)breakit.next();
1063 return new NodePair(begin,nopend);
1064 } else if (ln.getType()==LoopNode.WHILELOOP) {
1065 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1066 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1067 NodePair body=flattenBlockNode(ln.getBody());
1068 FlatNode begin=condition.getBegin();
1069 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1070 fcb.setTrueProb(State.TRUEPROB);
1072 FlatNop nopend=new FlatNop();
1073 FlatBackEdge backedge=new FlatBackEdge();
1075 if (body.getEnd()!=null)
1076 body.getEnd().addNext(backedge);
1077 backedge.addNext(condition.getBegin());
1079 condition.getEnd().addNext(fcb);
1080 fcb.addFalseNext(nopend);
1081 fcb.addTrueNext(body.getBegin());
1083 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1084 FlatNode fn=(FlatNode)contit.next();
1086 fn.addNext(backedge);
1088 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1089 FlatNode fn=(FlatNode)breakit.next();
1095 return new NodePair(begin,nopend);
1096 } else if (ln.getType()==LoopNode.DOWHILELOOP) {
1097 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1098 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1099 NodePair body=flattenBlockNode(ln.getBody());
1100 FlatNode begin=body.getBegin();
1101 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1102 fcb.setTrueProb(State.TRUEPROB);
1104 FlatNop nopend=new FlatNop();
1105 FlatBackEdge backedge=new FlatBackEdge();
1107 if (body.getEnd()!=null)
1108 body.getEnd().addNext(condition.getBegin());
1109 condition.getEnd().addNext(fcb);
1110 fcb.addFalseNext(nopend);
1111 fcb.addTrueNext(backedge);
1112 backedge.addNext(body.getBegin());
1114 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1115 FlatNode fn=(FlatNode)contit.next();
1117 fn.addNext(condition.getBegin());
1119 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1120 FlatNode fn=(FlatNode)breakit.next();
1126 return new NodePair(begin,nopend);
1127 } else throw new Error();
1130 private NodePair flattenReturnNode(ReturnNode rntree) {
1131 TempDescriptor retval=null;
1133 if (rntree.getReturnExpression()!=null) {
1134 retval=TempDescriptor.tempFactory("ret_value", rntree.getReturnExpression().getType());
1135 cond=flattenExpressionNode(rntree.getReturnExpression(),retval);
1138 FlatReturnNode rnflat=new FlatReturnNode(retval);
1141 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
1142 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1143 TempDescriptor thistd=getTempforVar(currmd.getThis());
1144 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
1148 if (state.DSM&&currmd.getModifiers().isAtomic()) {
1149 FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
1155 cond.getEnd().addNext(ln);
1156 return new NodePair(cond.getBegin(),null);
1158 return new NodePair(ln,null);
1161 private NodePair flattenTaskExitNode(TaskExitNode ten) {
1162 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.TASKEXIT);
1163 ffan.setTaskExitIndex(ten.getTaskExitIndex());
1164 updateFlagActionNode(ffan, ten.getFlagEffects());
1165 NodePair fcn=flattenConstraintCheck(ten.getChecks());
1166 ffan.addNext(fcn.getBegin());
1167 FlatReturnNode rnflat=new FlatReturnNode(null);
1169 fcn.getEnd().addNext(rnflat);
1170 return new NodePair(ffan, null);
1173 private NodePair flattenConstraintCheck(Vector ccs) {
1174 FlatNode begin=new FlatNop();
1176 return new NodePair(begin,begin);
1177 FlatNode last=begin;
1178 for(int i=0; i<ccs.size(); i++) {
1179 ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
1180 /* Flatten the arguments */
1181 TempDescriptor[] temps=new TempDescriptor[cc.numArgs()];
1182 String[] vars=new String[cc.numArgs()];
1183 for(int j=0; j<cc.numArgs(); j++) {
1184 ExpressionNode en=cc.getArg(j);
1185 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
1187 vars[j]=cc.getVar(j);
1188 NodePair np=flattenExpressionNode(en, td);
1189 last.addNext(np.getBegin());
1193 FlatCheckNode fcn=new FlatCheckNode(cc.getSpec(), vars, temps);
1197 return new NodePair(begin,last);
1200 private NodePair flattenSubBlockNode(SubBlockNode sbn) {
1201 return flattenBlockNode(sbn.getBlockNode());
1204 private NodePair flattenSynchronizedNode(SynchronizedNode sbn) {
1205 TempDescriptor montmp=TempDescriptor.tempFactory("monitor",sbn.getExpr().getType());
1206 NodePair npexp=flattenExpressionNode(sbn.getExpr(), montmp);
1207 NodePair npblock=flattenBlockNode(sbn.getBlockNode());
1209 MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
1210 FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
1212 MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1213 FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
1215 npexp.getEnd().addNext(fcen);
1216 fcen.addNext(npblock.getBegin());
1217 npblock.getEnd().addNext(fcex);
1218 return new NodePair(npexp.getBegin(), fcex);
1221 private NodePair flattenAtomicNode(AtomicNode sbn) {
1222 NodePair np=flattenBlockNode(sbn.getBlockNode());
1223 FlatAtomicEnterNode faen=new FlatAtomicEnterNode();
1224 FlatAtomicExitNode faexn=new FlatAtomicExitNode(faen);
1225 faen.addNext(np.getBegin());
1226 np.getEnd().addNext(faexn);
1227 return new NodePair(faen, faexn);
1230 private NodePair flattenGenReachNode( GenReachNode grn ) {
1231 FlatGenReachNode fgrn = new FlatGenReachNode( grn.getGraphName() );
1232 return new NodePair( fgrn, fgrn );
1235 private NodePair flattenSESENode(SESENode sn) {
1236 if( sn.isStart() ) {
1237 FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn);
1238 sn.setFlatEnter(fsen);
1239 return new NodePair(fsen, fsen);
1242 FlatSESEExitNode fsexn=new FlatSESEExitNode(sn);
1243 sn.setFlatExit(fsexn);
1244 FlatSESEEnterNode fsen=sn.getStart().getFlatEnter();
1245 fsexn.setFlatEnter(fsen);
1246 sn.getStart().getFlatEnter().setFlatExit( fsexn );
1248 return new NodePair(fsexn, fsexn);
1251 private NodePair flattenContinueBreakNode(ContinueBreakNode cbn) {
1252 FlatNop fn=new FlatNop();
1256 continueset.add(fn);
1257 return new NodePair(fn,null);
1260 private NodePair flattenInstanceOfNode(InstanceOfNode tn, TempDescriptor out_temp) {
1261 TempDescriptor expr_temp=TempDescriptor.tempFactory("expr",tn.getExpr().getType());
1262 NodePair cond=flattenExpressionNode(tn.getExpr(), expr_temp);
1263 FlatInstanceOfNode fion=new FlatInstanceOfNode(tn.getExprType(), expr_temp, out_temp);
1264 cond.getEnd().addNext(fion);
1265 return new NodePair(cond.getBegin(),fion);
1268 private NodePair flattenArrayInitializerNode(ArrayInitializerNode ain, TempDescriptor out_temp) {
1270 TempDescriptor expr_temp=TempDescriptor.tempFactory("arry_init",ain.getType());
1272 // create a new array of size equal to the array initializer
1273 //FlatNode first=null;
1274 //FlatNode last=null;
1275 TempDescriptor[] temps=new TempDescriptor[ain.numVarInitializers()];
1277 for (int i=0; i<con.numArgs(); i++) {
1278 ExpressionNode en=con.getArg(i);
1279 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
1281 NodePair np=flattenExpressionNode(en, tmp);
1283 first=np.getBegin();
1285 last.addNext(np.getBegin());
1288 TempDescriptor tmp2=(i==0) ?
1290 TempDescriptor.tempFactory("arg",en.getType());
1292 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
1296 // assign each element of the new array to the flattened expression
1299 FlatOpNode fonAssignArray=new FlatOpNode(out_temp, newarry_temp, null, new Operation(Operation.ASSIGN));
1301 //return new NodePair( , fonAssignArray );
1303 System.out.println( "Array initializers not implemented yet." );
1308 private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
1309 TempDescriptor cond_temp=TempDescriptor.tempFactory("tert_cond",new TypeDescriptor(TypeDescriptor.BOOLEAN));
1310 TempDescriptor true_temp=TempDescriptor.tempFactory("tert_true",tn.getTrueExpr().getType());
1311 TempDescriptor fals_temp=TempDescriptor.tempFactory("tert_fals",tn.getFalseExpr().getType());
1313 NodePair cond=flattenExpressionNode(tn.getCond(),cond_temp);
1314 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1316 NodePair trueExpr=flattenExpressionNode(tn.getTrueExpr(),true_temp);
1317 FlatOpNode fonT=new FlatOpNode(out_temp, true_temp, null, new Operation(Operation.ASSIGN));
1319 NodePair falseExpr=flattenExpressionNode(tn.getFalseExpr(),fals_temp);
1320 FlatOpNode fonF=new FlatOpNode(out_temp, fals_temp, null, new Operation(Operation.ASSIGN));
1322 FlatNop nopend=new FlatNop();
1324 cond.getEnd().addNext(fcb);
1326 fcb.addTrueNext(trueExpr.getBegin());
1327 fcb.addFalseNext(falseExpr.getBegin());
1329 trueExpr.getEnd().addNext(fonT);
1330 fonT.addNext(nopend);
1332 falseExpr.getEnd().addNext(fonF);
1333 fonF.addNext(nopend);
1335 return new NodePair(cond.getBegin(), nopend);
1338 private NodePair flattenBlockStatementNode(BlockStatementNode bsn) {
1339 switch(bsn.kind()) {
1340 case Kind.BlockExpressionNode:
1341 return flattenBlockExpressionNode((BlockExpressionNode)bsn);
1343 case Kind.DeclarationNode:
1344 return flattenDeclarationNode((DeclarationNode)bsn);
1346 case Kind.TagDeclarationNode:
1347 return flattenTagDeclarationNode((TagDeclarationNode)bsn);
1349 case Kind.IfStatementNode:
1350 return flattenIfStatementNode((IfStatementNode)bsn);
1353 return flattenLoopNode((LoopNode)bsn);
1355 case Kind.ReturnNode:
1356 return flattenReturnNode((IR.Tree.ReturnNode)bsn);
1358 case Kind.TaskExitNode:
1359 return flattenTaskExitNode((IR.Tree.TaskExitNode)bsn);
1361 case Kind.SubBlockNode:
1362 return flattenSubBlockNode((SubBlockNode)bsn);
1364 case Kind.AtomicNode:
1365 return flattenAtomicNode((AtomicNode)bsn);
1367 case Kind.SynchronizedNode:
1368 return flattenSynchronizedNode((SynchronizedNode)bsn);
1371 return flattenSESENode((SESENode)bsn);
1373 case Kind.GenReachNode:
1374 return flattenGenReachNode((GenReachNode)bsn);
1376 case Kind.ContinueBreakNode:
1377 return flattenContinueBreakNode((ContinueBreakNode)bsn);