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) {
37 public void removeNext(FlatNode n) {
40 public void removePrev(FlatNode n) {
44 /** This function modifies the graph */
45 public void setNext(int i, FlatNode n) {
46 FlatNode old=getNext(i);
48 old.prev.remove(this);
51 /** This function modifies the graph */
52 public void setNewNext(int i, FlatNode n) {
58 /** This function modifies the graph */
59 public void setprev(int i, FlatNode n) {
62 /** This function modifies the graph */
63 public void setnext(int i, FlatNode n) {
66 public void addPrev(FlatNode p) {
72 public TempDescriptor [] readsTemps() {
73 return new TempDescriptor[0];
75 public TempDescriptor [] writesTemps() {
76 return new TempDescriptor[0];
78 public FlatNode clone(TempMap t) {
79 throw new Error("no clone method for"+this);
82 public void rewriteUse(TempMap t) {
83 System.out.println(toString());
87 public void rewriteDef(TempMap t) {
88 System.out.println(toString());
92 public Set<FlatNode> getReachableSet(Set<FlatNode> endset) {
93 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
94 HashSet<FlatNode> visited=new HashSet<FlatNode>();
96 while(!tovisit.isEmpty()) {
97 FlatNode fn=tovisit.iterator().next();
100 if (endset!=null&&!endset.contains(fn)) {
101 for(int i=0; i<fn.numNext(); i++) {
102 FlatNode nn=fn.getNext(i);
103 if (!visited.contains(nn))
111 public void replace(FlatNode fnnew) {
112 fnnew.prev.setSize(prev.size());
113 fnnew.next.setSize(next.size());
114 for(int i=0;i<prev.size();i++) {
115 FlatNode nprev=(FlatNode)prev.get(i);
116 fnnew.prev.set(i,nprev);
117 for(int j=0;j<nprev.numNext();j++) {
118 FlatNode n=nprev.getNext(j);
120 nprev.next.set(j, fnnew);
123 for(int i=0;i<next.size();i++) {
124 FlatNode nnext=(FlatNode)next.get(i);
125 fnnew.next.set(i,nnext);
126 for(int j=0;j<nnext.numPrev();j++) {
127 FlatNode n=nnext.getPrev(j);
129 nnext.prev.set(j, fnnew);