private void flattenTask(TaskDescriptor td) {
BlockNode bn=state.getMethodBody(td);
FlatNode fn=flattenBlockNode(bn).getBegin();
- FlatMethod fm=new FlatMethod(td, fn);
+ FlatFlagActionNode ffan=new FlatFlagActionNode();
+ ffan.addNext(fn);
+ FlatMethod fm=new FlatMethod(td, ffan);
for(int i=0;i<td.numParameters();i++) {
fm.addParameterTemp(getTempforVar(td.getParameter(i)));
}
+
+ /* Flatten Vector of Flag Effects */
+ Vector flags=td.getFlagEffects();
+ updateFlagActionNode(ffan,flags);
+
state.addFlatCode(td,fm);
}
+
+ /* This method transforms a vector of FlagEffects into the FlatFlagActionNode */
+ private void updateFlagActionNode(FlatFlagActionNode ffan, Vector flags) {
+ for(int i=0;i<flags.size();i++) {
+ FlagEffects fes=(FlagEffects)flags.get(i);
+ TempDescriptor flagtemp=getTempforVar(fes.getVar());
+ for(int j=0;j<fes.numEffects();j++) {
+ FlagEffect fe=fes.getEffect(j);
+ ffan.addFlagAction(flagtemp, fe.getFlag(), fe.getStatus());
+ }
+ }
+ }
+
private void flattenClass(ClassDescriptor cn) {
Iterator methodit=cn.getMethods();
while(methodit.hasNext()) {
public static final int FlatSetElementNode=11;
public static final int FlatElementNode=12;
public static final int FlatTaskExitNode=13;
+ public static final int FlatFlagActionNode=14;
}
--- /dev/null
+package IR.Flat;
+import IR.FlagDescriptor;
+import java.util.Hashtable;
+import java.util.HashSet;
+import java.util.Iterator;
+
+public class FlatFlagActionNode extends FlatNode {
+ Hashtable tempflagpairs;
+
+ public FlatFlagActionNode() {
+ tempflagpairs=new Hashtable();
+ }
+
+ public void addFlagAction(TempDescriptor td, FlagDescriptor fd, boolean status) {
+ TempFlagPair tfp=new TempFlagPair(td,fd);
+ if (tempflagpairs.containsKey(tfp)) {
+ throw new Error("Temp/Flag combination used twice: "+tfp);
+ }
+ tempflagpairs.put(tfp, new Boolean(status));
+ }
+
+ public int kind() {
+ return FKind.FlatFlagActionNode;
+ }
+
+ public TempDescriptor [] readsTemps() {
+ if (tempflagpairs.size()==0)
+ return new TempDescriptor [0];
+ else {
+ HashSet temps=new HashSet();
+ for(Iterator it=tempflagpairs.keySet().iterator();it.hasNext();) {
+ TempFlagPair tfp=(TempFlagPair)it.next();
+ temps.add(tfp.getTemp());
+ }
+ return (TempDescriptor[]) temps.toArray(new TempDescriptor [temps.size()]);
+ }
+ }
+}
public int kind() {
return FKind.FlatTaskExitNode;
}
-
- public TempDescriptor [] readsTemps() {
- return new TempDescriptor [0];
- }
}
return Kind.FlagNode;
}
+ public boolean getStatus() {
+ return status;
+ }
+
public String printNode(int indent) {
if (status)
return name;