changes to MGC class library
[IRC.git] / Robust / src / Analysis / FlatIRGraph / FlatIRGraph.java
index 26f7f34b723223021ab872b7cf53787c928799ca..8b113cf9e1d700b6337d56eece71e008d5188046 100644 (file)
@@ -39,14 +39,21 @@ public class FlatIRGraph {
     for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator(); it_classes.hasNext(); ) {
       ClassDescriptor cd = (ClassDescriptor)it_classes.next();
       for(Iterator it_methods=cd.getMethods(); it_methods.hasNext(); ) {
-       MethodDescriptor md = (MethodDescriptor)it_methods.next();
-       FlatMethod fm = state.getMethodFlat(md);
-       writeFlatIRGraph(fm,cd.getSymbol()+"."+md.getSymbol());
+        MethodDescriptor md = (MethodDescriptor)it_methods.next();
+        FlatMethod fm = state.getMethodFlat(md);
+
+        // make sure the graph name reflects the method signature so
+        // overloaded methods don't clobber one another
+        String graphName = cd.getSymbol()+"."+md.getSymbol();        
+        for (int i = 0; i < fm.numParameters(); ++i) {
+          graphName += fm.getParameter(i).getSymbol();
+        }
+        writeFlatIRGraph(fm, graphName);
       }
     }
   }
-
-  private void writeFlatIRGraph(FlatMethod fm, String graphname) throws java.io.IOException {
+  
+  public void writeFlatIRGraph(FlatMethod fm, String graphname) throws java.io.IOException {
     // give every node in the flat IR graph a unique label
     // so a human being can inspect the graph and verify
     // correctness
@@ -58,7 +65,7 @@ public class FlatIRGraph {
     // take symbols out of graphname that cause dot to fail
     graphname = graphname.replaceAll("[\\W]", "");
 
-    flatbw=new BufferedWriter(new FileWriter(graphname+"_flatIRGraph.dot") );
+    flatbw=new BufferedWriter(new FileWriter("FLATIR_"+graphname+".dot") );
     flatbw.write("digraph "+graphname+" {\n");
 
     visited=new HashSet<FlatNode>();
@@ -71,19 +78,19 @@ public class FlatIRGraph {
       visited.add(fn);
 
       if( fn.kind() == FKind.FlatMethod ) {
-       // FlatMethod does not have toString
-       flatbw.write(makeDotNodeDec(graphname, flatnodetolabel.get(fn), fn.getClass().getName(), "FlatMethod") );
+        // FlatMethod does not have toString
+        flatbw.write(makeDotNodeDec(graphname, flatnodetolabel.get(fn), fn.getClass().getName(), "FlatMethod") );
       } else {
-       flatbw.write(makeDotNodeDec(graphname, flatnodetolabel.get(fn), fn.getClass().getName(), fn.toString() ) );
+        flatbw.write(makeDotNodeDec(graphname, flatnodetolabel.get(fn), fn.getClass().getName(), fn.toString() ) );
       }
 
       for(int i=0; i<fn.numNext(); i++) {
-       FlatNode nn=fn.getNext(i);
-       flatbw.write("  node"+flatnodetolabel.get(fn)+" -> node"+flatnodetolabel.get(nn)+";\n");
+        FlatNode nn=fn.getNext(i);
+        flatbw.write("  node"+flatnodetolabel.get(fn)+" -> node"+flatnodetolabel.get(nn)+";\n");
 
-       if( !visited.contains(nn) ) {
-         toVisit.add(nn);
-       }
+        if( !visited.contains(nn) ) {
+          toVisit.add(nn);
+        }
       }
     }
 
@@ -97,7 +104,7 @@ public class FlatIRGraph {
     for(int i=0; i<fn.numNext(); i++) {
       FlatNode nn=fn.getNext(i);
       if(!visited.contains(nn)) {
-       labelFlatNodes(nn);
+        labelFlatNodes(nn);
       }
     }
   }