2 import java.util.Vector;
3 import java.util.HashSet;
5 import java.util.Iterator;
7 public class FlatNode {
16 public String toString() {
17 throw new Error(this.getClass().getName() + "does not implement toString!");
19 public int numNext() {
22 public FlatNode getNext(int i) {
23 return (FlatNode) next.get(i);
26 public int numPrev() {
29 public FlatNode getPrev(int i) {
30 return (FlatNode) prev.get(i);
32 public void addNext(FlatNode n) {
36 public void removePrev(FlatNode n) {
39 /** This function modifies the graph */
40 public void setNext(int i, FlatNode n) {
41 FlatNode old=getNext(i);
43 old.prev.remove(this);
46 /** This function modifies the graph */
47 public void setNewNext(int i, FlatNode n) {
53 /** This function modifies the graph */
54 public void setprev(int i, FlatNode n) {
57 /** This function modifies the graph */
58 public void setnext(int i, FlatNode n) {
61 public void addPrev(FlatNode p) {
67 public TempDescriptor [] readsTemps() {
68 return new TempDescriptor[0];
70 public TempDescriptor [] writesTemps() {
71 return new TempDescriptor[0];
73 public FlatNode clone(TempMap t) {
74 throw new Error("no clone method for"+this);
77 public void rewriteUse(TempMap t) {
78 System.out.println(toString());
82 public void rewriteDef(TempMap t) {
83 System.out.println(toString());
87 public Set<FlatNode> getReachableSet(Set<FlatNode> endset) {
88 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
89 HashSet<FlatNode> visited=new HashSet<FlatNode>();
91 while(!tovisit.isEmpty()) {
92 FlatNode fn=tovisit.iterator().next();
95 if (endset!=null&&!endset.contains(fn)) {
96 for(int i=0; i<fn.numNext(); i++) {
97 FlatNode nn=fn.getNext(i);
98 if (!visited.contains(nn))
106 public void replace(FlatNode fnnew) {
107 fnnew.prev.setSize(prev.size());
108 fnnew.next.setSize(next.size());
109 for(int i=0;i<prev.size();i++) {
110 FlatNode nprev=(FlatNode)prev.get(i);
111 fnnew.prev.set(i,nprev);
112 for(int j=0;j<nprev.numNext();j++) {
113 FlatNode n=nprev.getNext(j);
115 nprev.next.set(j, fnnew);
118 for(int i=0;i<next.size();i++) {
119 FlatNode nnext=(FlatNode)next.get(i);
120 fnnew.next.set(i,nnext);;
121 for(int j=0;j<nnext.numPrev();j++) {
122 FlatNode n=nnext.getPrev(j);
124 nnext.prev.set(j, fnnew);