2 import java.util.Vector;
3 import java.util.HashSet;
5 import java.util.Iterator;
7 public class FlatNode {
10 static int idcounter=0;
11 public final int nodeid;
20 public String toString() {
21 throw new Error(this.getClass().getName() + "does not implement toString!");
23 public int numNext() {
26 public FlatNode getNext(int i) {
27 return (FlatNode) next.get(i);
30 public int numPrev() {
33 public FlatNode getPrev(int i) {
34 return (FlatNode) prev.get(i);
36 public void addNext(FlatNode n) {
41 public void removeNext(FlatNode n) {
44 public void removePrev(FlatNode n) {
48 /** This function modifies the graph */
49 public void setNext(int i, FlatNode n) {
50 FlatNode old=getNext(i);
52 old.prev.remove(this);
55 /** This function modifies the graph */
56 public void setNewNext(int i, FlatNode n) {
62 /** This function modifies the graph */
63 public void setprev(int i, FlatNode n) {
66 /** This function modifies the graph */
67 public void setnext(int i, FlatNode n) {
70 public void addPrev(FlatNode p) {
76 public TempDescriptor [] readsTemps() {
77 return new TempDescriptor[0];
79 public TempDescriptor [] writesTemps() {
80 return new TempDescriptor[0];
82 public FlatNode clone(TempMap t) {
83 throw new Error("no clone method for"+this);
86 public void rewriteUse(TempMap t) {
87 System.out.println(toString());
91 public void rewriteDef(TempMap t) {
92 System.out.println(toString());
96 public Set<FlatNode> getReachableSet(Set<FlatNode> endset) {
97 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
98 HashSet<FlatNode> visited=new HashSet<FlatNode>();
100 while(!tovisit.isEmpty()) {
101 FlatNode fn=tovisit.iterator().next();
104 if (endset!=null&&!endset.contains(fn)) {
105 for(int i=0; i<fn.numNext(); i++) {
106 FlatNode nn=fn.getNext(i);
107 if (!visited.contains(nn))
115 public void replace(FlatNode fnnew) {
116 fnnew.prev.setSize(prev.size());
117 fnnew.next.setSize(next.size());
118 for(int i=0;i<prev.size();i++) {
119 FlatNode nprev=(FlatNode)prev.get(i);
120 fnnew.prev.set(i,nprev);
121 for(int j=0;j<nprev.numNext();j++) {
122 FlatNode n=nprev.getNext(j);
124 nprev.next.set(j, fnnew);
127 for(int i=0;i<next.size();i++) {
128 FlatNode nnext=(FlatNode)next.get(i);
129 fnnew.next.set(i,nnext);
130 for(int j=0;j<nnext.numPrev();j++) {
131 FlatNode n=nnext.getPrev(j);
133 nnext.prev.set(j, fnnew);
140 public void setLineNum(int lineNum){
141 this.lineNum=lineNum;
144 public int getLineNume(){