package IR.Flat;
import IR.*;
import IR.Tree.*;
import java.util.*;
public class BuildFlat {
State state;
Hashtable temptovar;
public BuildFlat(State st) {
state=st;
temptovar=new Hashtable();
}
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);
FlatNode fn=flattenBlockNode(bn).getBegin();
FlatMethod fm=new FlatMethod(td, fn);
for(int i=0;i
1) {
NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0);
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) {
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