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=null;
484 if(fan.getExpression().getType().isStatic()) {
485 // static field dereference with class name
486 tmp = new TempDescriptor(fan.getExpression().getType().getClassDesc().getSymbol(), fan.getExpression().getType());
487 FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
488 return new NodePair(fn,fn);
490 tmp=TempDescriptor.tempFactory("temp",fan.getExpression().getType());
491 NodePair npe=flattenExpressionNode(fan.getExpression(),tmp);
492 FlatFieldNode fn=new FlatFieldNode(fan.getField(),tmp,out_temp);
493 npe.getEnd().addNext(fn);
494 return new NodePair(npe.getBegin(),fn);
498 private NodePair flattenArrayAccessNode(ArrayAccessNode aan,TempDescriptor out_temp) {
499 TempDescriptor tmp=TempDescriptor.tempFactory("temp",aan.getExpression().getType());
500 TempDescriptor tmpindex=TempDescriptor.tempFactory("temp",aan.getIndex().getType());
501 NodePair npe=flattenExpressionNode(aan.getExpression(),tmp);
502 NodePair npi=flattenExpressionNode(aan.getIndex(),tmpindex);
503 TempDescriptor arraytmp=out_temp;
504 if (aan.iswrapper()) {
506 arraytmp=TempDescriptor.tempFactory("temp", aan.getExpression().getType().dereference());
508 FlatNode fn=new FlatElementNode(tmp,tmpindex,arraytmp);
509 npe.getEnd().addNext(npi.getBegin());
510 npi.getEnd().addNext(fn);
511 if (aan.iswrapper()) {
512 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)aan.getExpression().getType().dereference().getClassDesc().getFieldTable().get("value") ,arraytmp,out_temp);
516 return new NodePair(npe.getBegin(),fn);
519 private NodePair flattenAssignmentNode(AssignmentNode an,TempDescriptor out_temp) {
521 // left side is variable
522 // left side is field
523 // left side is array
525 Operation base=an.getOperation().getBaseOp();
526 boolean pre=base==null||(base.getOp()!=Operation.POSTINC&&base.getOp()!=Operation.POSTDEC);
529 //rewrite the base operation
530 base=base.getOp()==Operation.POSTINC ? new Operation(Operation.ADD) : new Operation(Operation.SUB);
534 TempDescriptor src_tmp = src_tmp=an.getSrc()==null ? TempDescriptor.tempFactory("srctmp",an.getDest().getType()) : TempDescriptor.tempFactory("srctmp",an.getSrc().getType());
537 if (an.getSrc()!=null) {
538 NodePair np_src=flattenExpressionNode(an.getSrc(),src_tmp);
539 first=np_src.getBegin();
540 last=np_src.getEnd();
542 FlatLiteralNode fln=new FlatLiteralNode(new TypeDescriptor(TypeDescriptor.INT),new Integer(1),src_tmp);
547 if (an.getDest().kind()==Kind.FieldAccessNode) {
548 //We are assigning an object field
550 FieldAccessNode fan=(FieldAccessNode)an.getDest();
551 ExpressionNode en=fan.getExpression();
552 TempDescriptor dst_tmp=null;
553 NodePair np_baseexp=null;
554 if(en.getType().isStatic()) {
555 // static field dereference with class name
556 dst_tmp = new TempDescriptor(en.getType().getClassDesc().getSymbol(), en.getType());
557 FlatNop nop=new FlatNop();
558 np_baseexp = new NodePair(nop,nop);
560 dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
561 np_baseexp=flattenExpressionNode(en, dst_tmp);
564 first=np_baseexp.getBegin();
566 last.addNext(np_baseexp.getBegin());
567 last=np_baseexp.getEnd();
569 //See if we need to perform an operation
571 //If it is a preinc we need to store the initial value
572 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
573 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
574 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
578 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
579 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
580 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
581 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
586 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
593 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
597 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
601 return new NodePair(first, last);
602 } else if (an.getDest().kind()==Kind.ArrayAccessNode) {
603 //We are assigning an array element
605 ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
606 ExpressionNode en=aan.getExpression();
607 ExpressionNode enindex=aan.getIndex();
608 TempDescriptor dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
609 TempDescriptor index_tmp=TempDescriptor.tempFactory("index",enindex.getType());
610 NodePair np_baseexp=flattenExpressionNode(en, dst_tmp);
611 NodePair np_indexexp=flattenExpressionNode(enindex, index_tmp);
613 first=np_baseexp.getBegin();
615 last.addNext(np_baseexp.getBegin());
616 np_baseexp.getEnd().addNext(np_indexexp.getBegin());
617 last=np_indexexp.getEnd();
619 //See if we need to perform an operation
621 //If it is a preinc we need to store the initial value
622 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
623 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
625 if (aan.iswrapper()) {
626 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
627 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
628 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
629 FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp3,src_tmp2);
634 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
638 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
639 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
640 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
641 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
646 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
653 if (aan.iswrapper()) {
654 TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
655 TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
656 FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
657 FlatSetFieldNode fsfn=new FlatSetFieldNode(src_tmp3,(FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp);
662 FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
667 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
671 return new NodePair(first, last);
672 } else if (an.getDest().kind()==Kind.NameNode) {
673 //We could be assigning a field or variable
674 NameNode nn=(NameNode)an.getDest();
677 if (nn.getExpression()!=null) {
679 FieldAccessNode fan=(FieldAccessNode)nn.getExpression();
680 ExpressionNode en=fan.getExpression();
681 TempDescriptor dst_tmp=null;
682 NodePair np_baseexp=null;
683 if(en.getType().isStatic()) {
684 // static field dereference with class name
685 dst_tmp = new TempDescriptor(en.getType().getClassDesc().getSymbol(), en.getType());
686 FlatNop nop=new FlatNop();
687 np_baseexp = new NodePair(nop,nop);
689 dst_tmp=TempDescriptor.tempFactory("dst",en.getType());
690 np_baseexp=flattenExpressionNode(en, dst_tmp);
693 first=np_baseexp.getBegin();
695 last.addNext(np_baseexp.getBegin());
696 last=np_baseexp.getEnd();
698 //See if we need to perform an operation
700 //If it is a preinc we need to store the initial value
701 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
702 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
704 FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
709 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
710 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
711 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
712 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
717 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
725 FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
729 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
733 return new NodePair(first, last);
735 if (nn.getField()!=null) {
739 //See if we need to perform an operation
741 //If it is a preinc we need to store the initial value
742 TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
743 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
745 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), getTempforVar(nn.getVar()), src_tmp2);
754 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
755 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
756 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
757 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
762 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
769 FlatSetFieldNode fsfn=null;
770 if(nn.getClassDesc()!=null) {
771 // this is a static field access inside of a static block
772 fsfn=new FlatSetFieldNode(new TempDescriptor("sfsb", nn.getClassType()), nn.getField(), src_tmp);
774 fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
783 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
787 return new NodePair(first, last);
790 //See if we need to perform an operation
793 //If it is a preinc we need to store the initial value
794 TempDescriptor src_tmp2=getTempforVar(nn.getVar());
795 TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
797 FlatOpNode fon=new FlatOpNode(out_temp, src_tmp2, null, new Operation(Operation.ASSIGN));
806 if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
807 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
808 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
809 FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
817 FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
827 FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
832 FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
836 return new NodePair(first, last);
844 private NodePair flattenNameNode(NameNode nn,TempDescriptor out_temp) {
845 if (nn.getExpression()!=null) {
846 /* Hack - use subtree instead */
847 return flattenExpressionNode(nn.getExpression(),out_temp);
848 } else if (nn.getField()!=null) {
849 TempDescriptor tmp=getTempforVar(nn.getVar());
850 FlatFieldNode ffn=new FlatFieldNode(nn.getField(), tmp, out_temp);
851 return new NodePair(ffn,ffn);
853 TempDescriptor tmp=getTempforVar(nn.isTag() ? nn.getTagVar() : nn.getVar());
856 out_temp.setTag(tmp.getTag());
858 FlatOpNode fon=new FlatOpNode(out_temp, tmp, null, new Operation(Operation.ASSIGN));
859 return new NodePair(fon,fon);
863 private NodePair flattenOpNode(OpNode on,TempDescriptor out_temp) {
864 TempDescriptor temp_left=TempDescriptor.tempFactory("leftop",on.getLeft().getType());
865 TempDescriptor temp_right=null;
867 Operation op=on.getOp();
869 NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
871 if (on.getRight()!=null) {
872 temp_right=TempDescriptor.tempFactory("rightop",on.getRight().getType());
873 right=flattenExpressionNode(on.getRight(),temp_right);
875 FlatNop nop=new FlatNop();
876 right=new NodePair(nop,nop);
879 if (op.getOp()==Operation.LOGIC_OR) {
880 /* Need to do shortcircuiting */
881 FlatCondBranch fcb=new FlatCondBranch(temp_left);
882 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
883 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
884 FlatNop fnop=new FlatNop();
885 left.getEnd().addNext(fcb);
886 fcb.addFalseNext(right.getBegin());
887 right.getEnd().addNext(fon2);
889 fcb.addTrueNext(fon1);
891 return new NodePair(left.getBegin(), fnop);
892 } else if (op.getOp()==Operation.LOGIC_AND) {
893 /* Need to do shortcircuiting */
894 FlatCondBranch fcb=new FlatCondBranch(temp_left);
895 FlatOpNode fon1=new FlatOpNode(out_temp,temp_left,null,new Operation(Operation.ASSIGN));
896 FlatOpNode fon2=new FlatOpNode(out_temp,temp_right,null,new Operation(Operation.ASSIGN));
897 FlatNop fnop=new FlatNop();
898 left.getEnd().addNext(fcb);
899 fcb.addTrueNext(right.getBegin());
900 right.getEnd().addNext(fon2);
902 fcb.addFalseNext(fon1);
904 return new NodePair(left.getBegin(), fnop);
905 } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
906 //We have a string concatenate
907 ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
908 MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
909 FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
910 left.getEnd().addNext(right.getBegin());
911 right.getEnd().addNext(fc);
912 return new NodePair(left.getBegin(), fc);
915 FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
916 left.getEnd().addNext(right.getBegin());
917 right.getEnd().addNext(fon);
918 return new NodePair(left.getBegin(),fon);
921 private NodePair flattenExpressionNode(ExpressionNode en, TempDescriptor out_temp) {
923 case Kind.AssignmentNode:
924 return flattenAssignmentNode((AssignmentNode)en,out_temp);
927 return flattenCastNode((CastNode)en,out_temp);
929 case Kind.CreateObjectNode:
930 return flattenCreateObjectNode((CreateObjectNode)en,out_temp);
932 case Kind.FieldAccessNode:
933 return flattenFieldAccessNode((FieldAccessNode)en,out_temp);
935 case Kind.ArrayAccessNode:
936 return flattenArrayAccessNode((ArrayAccessNode)en,out_temp);
938 case Kind.LiteralNode:
939 return flattenLiteralNode((LiteralNode)en,out_temp);
941 case Kind.MethodInvokeNode:
942 return flattenMethodInvokeNode((MethodInvokeNode)en,out_temp);
945 return flattenNameNode((NameNode)en,out_temp);
948 return flattenOpNode((OpNode)en,out_temp);
950 case Kind.OffsetNode:
951 return flattenOffsetNode((OffsetNode)en,out_temp);
953 case Kind.TertiaryNode:
954 return flattenTertiaryNode((TertiaryNode)en,out_temp);
956 case Kind.InstanceOfNode:
957 return flattenInstanceOfNode((InstanceOfNode)en,out_temp);
959 case Kind.ArrayInitializerNode:
960 return flattenArrayInitializerNode((ArrayInitializerNode)en,out_temp);
965 private NodePair flattenDeclarationNode(DeclarationNode dn) {
966 VarDescriptor vd=dn.getVarDescriptor();
967 TempDescriptor td=getTempforVar(vd);
968 if (dn.getExpression()!=null)
969 return flattenExpressionNode(dn.getExpression(),td);
971 FlatNop fn=new FlatNop();
972 return new NodePair(fn,fn);
976 private NodePair flattenTagDeclarationNode(TagDeclarationNode dn) {
977 TagVarDescriptor tvd=dn.getTagVarDescriptor();
978 TagDescriptor tag=tvd.getTag();
979 TempDescriptor tmp=getTempforVar(tvd);
980 FlatTagDeclaration ftd=new FlatTagDeclaration(tag, tmp);
981 return new NodePair(ftd,ftd);
984 private TempDescriptor getTempforParam(Descriptor d) {
985 if (temptovar.containsKey(d))
986 return (TempDescriptor)temptovar.get(d);
988 if (d instanceof VarDescriptor) {
989 VarDescriptor vd=(VarDescriptor)d;
990 TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
991 temptovar.put(vd,td);
993 } else if (d instanceof TagVarDescriptor) {
994 TagVarDescriptor tvd=(TagVarDescriptor)d;
995 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
996 TempDescriptor td=TempDescriptor.paramtempFactory(tvd.getName(), tagtype, tvd.getTag());
997 temptovar.put(tvd,td);
999 } else throw new Error("Unreconized Descriptor");
1003 private TempDescriptor getTempforVar(Descriptor d) {
1004 if (temptovar.containsKey(d))
1005 return (TempDescriptor)temptovar.get(d);
1007 if (d instanceof VarDescriptor) {
1008 VarDescriptor vd=(VarDescriptor)d;
1009 TempDescriptor td=TempDescriptor.tempFactory(vd.getName(), vd.getType());
1010 temptovar.put(vd,td);
1012 } else if (d instanceof TagVarDescriptor) {
1013 TagVarDescriptor tvd=(TagVarDescriptor)d;
1014 //BUGFIX TAGTYPE - add next line, modify following
1015 //line to tag this new type descriptor, modify
1016 //TempDescriptor constructor & factory to set type
1017 //using this Type To test, use any program with tags
1018 TypeDescriptor tagtype=new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass));
1019 TempDescriptor td=TempDescriptor.tempFactory(tvd.getName(),tagtype, tvd.getTag());
1020 temptovar.put(tvd,td);
1022 } else throw new Error("Unrecognized Descriptor");
1026 private NodePair flattenIfStatementNode(IfStatementNode isn) {
1027 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition",new TypeDescriptor(TypeDescriptor.BOOLEAN));
1028 NodePair cond=flattenExpressionNode(isn.getCondition(),cond_temp);
1029 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1030 NodePair true_np=flattenBlockNode(isn.getTrueBlock());
1032 FlatNop nopend=new FlatNop();
1034 if (isn.getFalseBlock()!=null)
1035 false_np=flattenBlockNode(isn.getFalseBlock());
1037 FlatNop nop=new FlatNop();
1038 false_np=new NodePair(nop,nop);
1041 cond.getEnd().addNext(fcb);
1042 fcb.addTrueNext(true_np.getBegin());
1043 fcb.addFalseNext(false_np.getBegin());
1044 if (true_np.getEnd()!=null)
1045 true_np.getEnd().addNext(nopend);
1046 if (false_np.getEnd()!=null)
1047 false_np.getEnd().addNext(nopend);
1048 if (nopend.numPrev()==0)
1049 return new NodePair(cond.getBegin(), null);
1051 return new NodePair(cond.getBegin(), nopend);
1054 private NodePair flattenLoopNode(LoopNode ln) {
1055 HashSet oldbs=breakset;
1056 HashSet oldcs=continueset;
1057 breakset=new HashSet();
1058 continueset=new HashSet();
1060 if (ln.getType()==LoopNode.FORLOOP) {
1061 NodePair initializer=flattenBlockNode(ln.getInitializer());
1062 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1063 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1064 NodePair update=flattenBlockNode(ln.getUpdate());
1065 NodePair body=flattenBlockNode(ln.getBody());
1066 FlatNode begin=initializer.getBegin();
1067 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1068 fcb.setTrueProb(State.TRUEPROB);
1070 FlatNop nopend=new FlatNop();
1071 FlatBackEdge backedge=new FlatBackEdge();
1073 FlatNop nop2=new FlatNop();
1074 initializer.getEnd().addNext(nop2);
1075 nop2.addNext(condition.getBegin());
1076 if (body.getEnd()!=null)
1077 body.getEnd().addNext(update.getBegin());
1078 update.getEnd().addNext(backedge);
1079 backedge.addNext(condition.getBegin());
1080 condition.getEnd().addNext(fcb);
1081 fcb.addFalseNext(nopend);
1082 fcb.addTrueNext(body.getBegin());
1083 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1084 FlatNode fn=(FlatNode)contit.next();
1086 fn.addNext(update.getBegin());
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.WHILELOOP) {
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=condition.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(backedge);
1109 backedge.addNext(condition.getBegin());
1111 condition.getEnd().addNext(fcb);
1112 fcb.addFalseNext(nopend);
1113 fcb.addTrueNext(body.getBegin());
1115 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1116 FlatNode fn=(FlatNode)contit.next();
1118 fn.addNext(backedge);
1120 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1121 FlatNode fn=(FlatNode)breakit.next();
1127 return new NodePair(begin,nopend);
1128 } else if (ln.getType()==LoopNode.DOWHILELOOP) {
1129 TempDescriptor cond_temp=TempDescriptor.tempFactory("condition", new TypeDescriptor(TypeDescriptor.BOOLEAN));
1130 NodePair condition=flattenExpressionNode(ln.getCondition(),cond_temp);
1131 NodePair body=flattenBlockNode(ln.getBody());
1132 FlatNode begin=body.getBegin();
1133 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1134 fcb.setTrueProb(State.TRUEPROB);
1136 FlatNop nopend=new FlatNop();
1137 FlatBackEdge backedge=new FlatBackEdge();
1139 if (body.getEnd()!=null)
1140 body.getEnd().addNext(condition.getBegin());
1141 condition.getEnd().addNext(fcb);
1142 fcb.addFalseNext(nopend);
1143 fcb.addTrueNext(backedge);
1144 backedge.addNext(body.getBegin());
1146 for(Iterator contit=continueset.iterator();contit.hasNext();) {
1147 FlatNode fn=(FlatNode)contit.next();
1149 fn.addNext(condition.getBegin());
1151 for(Iterator breakit=breakset.iterator();breakit.hasNext();) {
1152 FlatNode fn=(FlatNode)breakit.next();
1158 return new NodePair(begin,nopend);
1159 } else throw new Error();
1162 private NodePair flattenReturnNode(ReturnNode rntree) {
1163 TempDescriptor retval=null;
1165 if (rntree.getReturnExpression()!=null) {
1166 retval=TempDescriptor.tempFactory("ret_value", rntree.getReturnExpression().getType());
1167 cond=flattenExpressionNode(rntree.getReturnExpression(),retval);
1170 FlatReturnNode rnflat=new FlatReturnNode(retval);
1173 if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
1174 MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1175 TempDescriptor thistd=getTempforVar(currmd.getThis());
1176 FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
1180 if (state.DSM&&currmd.getModifiers().isAtomic()) {
1181 FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
1187 cond.getEnd().addNext(ln);
1188 return new NodePair(cond.getBegin(),null);
1190 return new NodePair(ln,null);
1193 private NodePair flattenTaskExitNode(TaskExitNode ten) {
1194 FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.TASKEXIT);
1195 ffan.setTaskExitIndex(ten.getTaskExitIndex());
1196 updateFlagActionNode(ffan, ten.getFlagEffects());
1197 NodePair fcn=flattenConstraintCheck(ten.getChecks());
1198 ffan.addNext(fcn.getBegin());
1199 FlatReturnNode rnflat=new FlatReturnNode(null);
1201 fcn.getEnd().addNext(rnflat);
1202 return new NodePair(ffan, null);
1205 private NodePair flattenConstraintCheck(Vector ccs) {
1206 FlatNode begin=new FlatNop();
1208 return new NodePair(begin,begin);
1209 FlatNode last=begin;
1210 for(int i=0; i<ccs.size(); i++) {
1211 ConstraintCheck cc=(ConstraintCheck) ccs.get(i);
1212 /* Flatten the arguments */
1213 TempDescriptor[] temps=new TempDescriptor[cc.numArgs()];
1214 String[] vars=new String[cc.numArgs()];
1215 for(int j=0; j<cc.numArgs(); j++) {
1216 ExpressionNode en=cc.getArg(j);
1217 TempDescriptor td=TempDescriptor.tempFactory("arg",en.getType());
1219 vars[j]=cc.getVar(j);
1220 NodePair np=flattenExpressionNode(en, td);
1221 last.addNext(np.getBegin());
1225 FlatCheckNode fcn=new FlatCheckNode(cc.getSpec(), vars, temps);
1229 return new NodePair(begin,last);
1232 private NodePair flattenSubBlockNode(SubBlockNode sbn) {
1233 return flattenBlockNode(sbn.getBlockNode());
1236 private NodePair flattenSynchronizedNode(SynchronizedNode sbn) {
1237 TempDescriptor montmp=TempDescriptor.tempFactory("monitor",sbn.getExpr().getType());
1238 NodePair npexp=flattenExpressionNode(sbn.getExpr(), montmp);
1239 NodePair npblock=flattenBlockNode(sbn.getBlockNode());
1241 MethodDescriptor menmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
1242 FlatCall fcen=new FlatCall(menmd, null, montmp, new TempDescriptor[0]);
1244 MethodDescriptor mexmd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
1245 FlatCall fcex=new FlatCall(mexmd, null, montmp, new TempDescriptor[0]);
1247 npexp.getEnd().addNext(fcen);
1248 fcen.addNext(npblock.getBegin());
1249 npblock.getEnd().addNext(fcex);
1250 return new NodePair(npexp.getBegin(), fcex);
1253 private NodePair flattenAtomicNode(AtomicNode sbn) {
1254 NodePair np=flattenBlockNode(sbn.getBlockNode());
1255 FlatAtomicEnterNode faen=new FlatAtomicEnterNode();
1256 FlatAtomicExitNode faexn=new FlatAtomicExitNode(faen);
1257 faen.addNext(np.getBegin());
1258 np.getEnd().addNext(faexn);
1259 return new NodePair(faen, faexn);
1262 private NodePair flattenGenReachNode( GenReachNode grn ) {
1263 FlatGenReachNode fgrn = new FlatGenReachNode( grn.getGraphName() );
1264 return new NodePair( fgrn, fgrn );
1267 private NodePair flattenSESENode(SESENode sn) {
1268 if( sn.isStart() ) {
1269 FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn);
1270 sn.setFlatEnter(fsen);
1271 return new NodePair(fsen, fsen);
1274 FlatSESEExitNode fsexn=new FlatSESEExitNode(sn);
1275 sn.setFlatExit(fsexn);
1276 FlatSESEEnterNode fsen=sn.getStart().getFlatEnter();
1277 fsexn.setFlatEnter(fsen);
1278 sn.getStart().getFlatEnter().setFlatExit( fsexn );
1280 return new NodePair(fsexn, fsexn);
1283 private NodePair flattenContinueBreakNode(ContinueBreakNode cbn) {
1284 FlatNop fn=new FlatNop();
1288 continueset.add(fn);
1289 return new NodePair(fn,null);
1292 private NodePair flattenInstanceOfNode(InstanceOfNode tn, TempDescriptor out_temp) {
1293 TempDescriptor expr_temp=TempDescriptor.tempFactory("expr",tn.getExpr().getType());
1294 NodePair cond=flattenExpressionNode(tn.getExpr(), expr_temp);
1295 FlatInstanceOfNode fion=new FlatInstanceOfNode(tn.getExprType(), expr_temp, out_temp);
1296 cond.getEnd().addNext(fion);
1297 return new NodePair(cond.getBegin(),fion);
1300 private NodePair flattenArrayInitializerNode(ArrayInitializerNode ain, TempDescriptor out_temp) {
1302 TempDescriptor expr_temp=TempDescriptor.tempFactory("arry_init",ain.getType());
1304 // create a new array of size equal to the array initializer
1305 //FlatNode first=null;
1306 //FlatNode last=null;
1307 TempDescriptor[] temps=new TempDescriptor[ain.numVarInitializers()];
1309 for (int i=0; i<con.numArgs(); i++) {
1310 ExpressionNode en=con.getArg(i);
1311 TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
1313 NodePair np=flattenExpressionNode(en, tmp);
1315 first=np.getBegin();
1317 last.addNext(np.getBegin());
1320 TempDescriptor tmp2=(i==0) ?
1322 TempDescriptor.tempFactory("arg",en.getType());
1324 FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.getDisjointId());
1328 // assign each element of the new array to the flattened expression
1331 FlatOpNode fonAssignArray=new FlatOpNode(out_temp, newarry_temp, null, new Operation(Operation.ASSIGN));
1333 //return new NodePair( , fonAssignArray );
1335 System.out.println( "Array initializers not implemented yet." );
1340 private NodePair flattenTertiaryNode(TertiaryNode tn, TempDescriptor out_temp) {
1341 TempDescriptor cond_temp=TempDescriptor.tempFactory("tert_cond",new TypeDescriptor(TypeDescriptor.BOOLEAN));
1342 TempDescriptor true_temp=TempDescriptor.tempFactory("tert_true",tn.getTrueExpr().getType());
1343 TempDescriptor fals_temp=TempDescriptor.tempFactory("tert_fals",tn.getFalseExpr().getType());
1345 NodePair cond=flattenExpressionNode(tn.getCond(),cond_temp);
1346 FlatCondBranch fcb=new FlatCondBranch(cond_temp);
1348 NodePair trueExpr=flattenExpressionNode(tn.getTrueExpr(),true_temp);
1349 FlatOpNode fonT=new FlatOpNode(out_temp, true_temp, null, new Operation(Operation.ASSIGN));
1351 NodePair falseExpr=flattenExpressionNode(tn.getFalseExpr(),fals_temp);
1352 FlatOpNode fonF=new FlatOpNode(out_temp, fals_temp, null, new Operation(Operation.ASSIGN));
1354 FlatNop nopend=new FlatNop();
1356 cond.getEnd().addNext(fcb);
1358 fcb.addTrueNext(trueExpr.getBegin());
1359 fcb.addFalseNext(falseExpr.getBegin());
1361 trueExpr.getEnd().addNext(fonT);
1362 fonT.addNext(nopend);
1364 falseExpr.getEnd().addNext(fonF);
1365 fonF.addNext(nopend);
1367 return new NodePair(cond.getBegin(), nopend);
1370 private NodePair flattenBlockStatementNode(BlockStatementNode bsn) {
1371 switch(bsn.kind()) {
1372 case Kind.BlockExpressionNode:
1373 return flattenBlockExpressionNode((BlockExpressionNode)bsn);
1375 case Kind.DeclarationNode:
1376 return flattenDeclarationNode((DeclarationNode)bsn);
1378 case Kind.TagDeclarationNode:
1379 return flattenTagDeclarationNode((TagDeclarationNode)bsn);
1381 case Kind.IfStatementNode:
1382 return flattenIfStatementNode((IfStatementNode)bsn);
1385 return flattenLoopNode((LoopNode)bsn);
1387 case Kind.ReturnNode:
1388 return flattenReturnNode((IR.Tree.ReturnNode)bsn);
1390 case Kind.TaskExitNode:
1391 return flattenTaskExitNode((IR.Tree.TaskExitNode)bsn);
1393 case Kind.SubBlockNode:
1394 return flattenSubBlockNode((SubBlockNode)bsn);
1396 case Kind.AtomicNode:
1397 return flattenAtomicNode((AtomicNode)bsn);
1399 case Kind.SynchronizedNode:
1400 return flattenSynchronizedNode((SynchronizedNode)bsn);
1403 return flattenSESENode((SESENode)bsn);
1405 case Kind.GenReachNode:
1406 return flattenGenReachNode((GenReachNode)bsn);
1408 case Kind.ContinueBreakNode:
1409 return flattenContinueBreakNode((ContinueBreakNode)bsn);