package IR.Flat; import IR.*; import IR.Tree.*; import java.util.*; public class BuildFlat { State state; Hashtable temptovar; MethodDescriptor currmd; TypeUtil typeutil; public BuildFlat(State st, TypeUtil typeutil) { state=st; temptovar=new Hashtable(); this.typeutil=typeutil; } public Hashtable getMap() { return temptovar; } public void buildFlat() { Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); while(it.hasNext()) { ClassDescriptor cn=(ClassDescriptor)it.next(); flattenClass(cn); } Iterator task_it=state.getTaskSymbolTable().getDescriptorsIterator(); while(task_it.hasNext()) { TaskDescriptor td=(TaskDescriptor)task_it.next(); flattenTask(td); } } private void flattenTask(TaskDescriptor td) { BlockNode bn=state.getMethodBody(td); NodePair np=flattenBlockNode(bn); FlatNode fn=np.getBegin(); if (np.getEnd().kind()!=FKind.FlatReturnNode) { FlatReturnNode rnflat=new FlatReturnNode(null); np.getEnd().addNext(rnflat); } FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.PRE); ffan.addNext(fn); FlatMethod fm=new FlatMethod(td); fm.addNext(ffan); Hashtable visitedset=new Hashtable(); for(int i=0;i1) { NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); fn.addNext(np.getBegin()); return new NodePair(first,np.getEnd()); } else return new NodePair(first, fn); } } private NodePair generateNewArrayLoop(TempDescriptor[] temparray, TypeDescriptor td, TempDescriptor tmp, int i, boolean isglobal) { TempDescriptor index=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT)); TempDescriptor tmpone=TempDescriptor.tempFactory("index",new TypeDescriptor(TypeDescriptor.INT)); FlatNop fnop=new FlatNop();//last node //index=0 FlatLiteralNode fln=new FlatLiteralNode(index.getType(),new Integer(0),index); //tmpone=1 FlatLiteralNode fln2=new FlatLiteralNode(tmpone.getType(),new Integer(1),tmpone); TempDescriptor tmpbool=TempDescriptor.tempFactory("comp",new TypeDescriptor(TypeDescriptor.BOOLEAN)); FlatOpNode fcomp=new FlatOpNode(tmpbool,index,temparray[i],new Operation(Operation.LT)); FlatCondBranch fcb=new FlatCondBranch(tmpbool); //is index