changes.
authoryeom <yeom>
Mon, 13 Aug 2012 08:12:28 +0000 (08:12 +0000)
committeryeom <yeom>
Mon, 13 Aug 2012 08:12:28 +0000 (08:12 +0000)
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Benchmarks/SSJava/MP3DecoderInfer/LayerIIIDecoder.java
Robust/src/Benchmarks/SSJava/MP3DecoderInfer/infer/makefile

index c9877d8e611e19adf14d32137be2dcbb24cd819c..6404a8f9984fdc520736c8a12d0ebf077898cf04 100644 (file)
@@ -184,7 +184,14 @@ public class LocationInference {
   }
 
   private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
   }
 
   private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
-    String pattern = "class " + cd.getSymbol() + " ";
+
+    String classSymbol = cd.getSymbol();
+    int idx = classSymbol.lastIndexOf("$");
+    if (idx != -1) {
+      classSymbol = classSymbol.substring(idx + 1);
+    }
+
+    String pattern = "class " + classSymbol + " ";
     if (strLine.indexOf(pattern) != -1) {
       mapDescToDefinitionLine.put(cd, lineNum);
     }
     if (strLine.indexOf(pattern) != -1) {
       mapDescToDefinitionLine.put(cd, lineNum);
     }
@@ -246,6 +253,8 @@ public class LocationInference {
 
   private String generateLatticeDefinition(Descriptor desc) {
 
 
   private String generateLatticeDefinition(Descriptor desc) {
 
+    Set<String> sharedLocSet = new HashSet<String>();
+
     SSJavaLattice<String> lattice = getLattice(desc);
     String rtr = "@LATTICE(\"";
 
     SSJavaLattice<String> lattice = getLattice(desc);
     String rtr = "@LATTICE(\"";
 
@@ -266,6 +275,9 @@ public class LocationInference {
               first = false;
             }
             rtr += key;
               first = false;
             }
             rtr += key;
+            if (lattice.isSharedLoc(key)) {
+              rtr += "," + key + "*";
+            }
           }
         }
 
           }
         }
 
@@ -279,6 +291,15 @@ public class LocationInference {
               first = false;
             }
             rtr += loc + "<" + key;
               first = false;
             }
             rtr += loc + "<" + key;
+            if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
+              rtr += "," + key + "*";
+              sharedLocSet.add(key);
+            }
+            if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
+              rtr += "," + loc + "*";
+              sharedLocSet.add(loc);
+            }
+
           }
         }
       }
           }
         }
       }
@@ -303,63 +324,60 @@ public class LocationInference {
     readOriginalSourceFiles();
 
     setupToAnalyze();
     readOriginalSourceFiles();
 
     setupToAnalyze();
-
     while (!toAnalyzeIsEmpty()) {
       ClassDescriptor cd = toAnalyzeNext();
 
       setupToAnalazeMethod(cd);
 
       LocationInfo locInfo = mapClassToLocationInfo.get(cd);
     while (!toAnalyzeIsEmpty()) {
       ClassDescriptor cd = toAnalyzeNext();
 
       setupToAnalazeMethod(cd);
 
       LocationInfo locInfo = mapClassToLocationInfo.get(cd);
-
       String sourceFileName = cd.getSourceFileName();
 
       String sourceFileName = cd.getSourceFileName();
 
+      if (cd.isInterface()) {
+        continue;
+      }
+
       int classDefLine = mapDescToDefinitionLine.get(cd);
       Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
 
       int classDefLine = mapDescToDefinitionLine.get(cd);
       Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
 
-      if (locInfo != null) {
+      if (locInfo == null) {
+        locInfo = getLocationInfo(cd);
+      }
 
 
-        Map<Descriptor, CompositeLocation> mapDescToInferLoc = locInfo.getMapDescToInferLocation();
-        Set<Descriptor> fieldDescSet = mapDescToInferLoc.keySet();
-        for (Iterator iterator = fieldDescSet.iterator(); iterator.hasNext();) {
-          Descriptor fieldDesc = (Descriptor) iterator.next();
-          String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier();
-          if (!getLattice(cd).containsKey(locIdentifier)) {
-            getLattice(cd).put(locIdentifier);
-          }
+      for (Iterator iter = cd.getFields(); iter.hasNext();) {
+        Descriptor fieldDesc = (Descriptor) iter.next();
+        String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier();
+        if (!getLattice(cd).containsKey(locIdentifier)) {
+          getLattice(cd).put(locIdentifier);
         }
         }
+      }
 
 
-        String fieldLatticeDefStr = generateLatticeDefinition(cd);
-        String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
-        sourceVec.set(classDefLine, annoatedSrc);
-
-        // generate annotations for field declarations
-        LocationInfo fieldLocInfo = getLocationInfo(cd);
-        Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
-
-        for (Iterator iter = cd.getFields(); iter.hasNext();) {
-          FieldDescriptor fd = (FieldDescriptor) iter.next();
+      String fieldLatticeDefStr = generateLatticeDefinition(cd);
+      String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
+      sourceVec.set(classDefLine, annoatedSrc);
 
 
-          String locAnnotationStr;
-          if (inferLocMap.containsKey(fd)) {
-            CompositeLocation inferLoc = inferLocMap.get(fd);
-            locAnnotationStr = generateLocationAnnoatation(inferLoc);
-          } else {
-            // if the field is not accssed by SS part, just assigns dummy
-            // location
-            locAnnotationStr = "@LOC(\"LOC\")";
-          }
-          int fdLineNum = fd.getLineNum();
-          String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
-          String fieldDeclaration = fd.toString();
-          fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
+      // generate annotations for field declarations
+      LocationInfo fieldLocInfo = getLocationInfo(cd);
+      Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
 
 
-          int idx = orgFieldDeclarationStr.indexOf(fieldDeclaration);
-          String annoatedStr =
-              orgFieldDeclarationStr.substring(0, idx) + locAnnotationStr + " "
-                  + orgFieldDeclarationStr.substring(idx);
-          sourceVec.set(fdLineNum, annoatedStr);
+      for (Iterator iter = cd.getFields(); iter.hasNext();) {
+        FieldDescriptor fd = (FieldDescriptor) iter.next();
 
 
+        String locAnnotationStr;
+        if (inferLocMap.containsKey(fd)) {
+          CompositeLocation inferLoc = inferLocMap.get(fd);
+          locAnnotationStr = generateLocationAnnoatation(inferLoc);
+        } else {
+          // if the field is not accssed by SS part, just assigns dummy
+          // location
+          locAnnotationStr = "@LOC(\"LOC\")";
         }
         }
+        int fdLineNum = fd.getLineNum();
+        String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
+        String fieldDeclaration = fd.toString();
+        fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
+
+        String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
+        sourceVec.set(fdLineNum, annoatedStr);
 
       }
 
 
       }
 
@@ -372,22 +390,23 @@ public class LocationInference {
 
           MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
 
 
           MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
 
-          Map<Descriptor, CompositeLocation> inferLocMap =
+          Map<Descriptor, CompositeLocation> methodInferLocMap =
               methodLocInfo.getMapDescToInferLocation();
               methodLocInfo.getMapDescToInferLocation();
-          Set<Descriptor> localVarDescSet = inferLocMap.keySet();
+          Set<Descriptor> localVarDescSet = methodInferLocMap.keySet();
 
           for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
             Descriptor localVarDesc = (Descriptor) iterator.next();
 
           for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
             Descriptor localVarDesc = (Descriptor) iterator.next();
-            CompositeLocation inferLoc = inferLocMap.get(localVarDesc);
+            CompositeLocation inferLoc = methodInferLocMap.get(localVarDesc);
 
             String locAnnotationStr = generateLocationAnnoatation(inferLoc);
 
             if (!isParameter(md, localVarDesc)) {
               if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
                 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
 
             String locAnnotationStr = generateLocationAnnoatation(inferLoc);
 
             if (!isParameter(md, localVarDesc)) {
               if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
                 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
-
                 String orgSourceLine = sourceVec.get(varLineNum);
                 String orgSourceLine = sourceVec.get(varLineNum);
-                int idx = orgSourceLine.indexOf(localVarDesc.toString());
+                int idx =
+                    orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
+                assert (idx != -1);
                 String annoatedStr =
                     orgSourceLine.substring(0, idx) + locAnnotationStr + " "
                         + orgSourceLine.substring(idx);
                 String annoatedStr =
                     orgSourceLine.substring(0, idx) + locAnnotationStr + " "
                         + orgSourceLine.substring(idx);
@@ -395,7 +414,7 @@ public class LocationInference {
               }
             } else {
               String methodDefStr = sourceVec.get(methodDefLine);
               }
             } else {
               String methodDefStr = sourceVec.get(methodDefLine);
-              int idx = methodDefStr.indexOf(localVarDesc.toString());
+              int idx = methodDefStr.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
               assert (idx != -1);
               String annoatedStr =
                   methodDefStr.substring(0, idx) + locAnnotationStr + " "
               assert (idx != -1);
               String annoatedStr =
                   methodDefStr.substring(0, idx) + locAnnotationStr + " "
@@ -411,11 +430,26 @@ public class LocationInference {
 
         }
       }
 
         }
       }
+
     }
 
     codeGen();
   }
 
     }
 
     codeGen();
   }
 
+  private String generateVarDeclaration(VarDescriptor varDesc) {
+
+    TypeDescriptor td = varDesc.getType();
+    String rtr = td.toString();
+    if (td.isArray()) {
+      for (int i = 0; i < td.getArrayCount(); i++) {
+        rtr += "[]";
+      }
+    }
+    rtr += " " + varDesc.getName();
+    return rtr;
+
+  }
+
   private String generateLocationAnnoatation(CompositeLocation loc) {
     String rtr = "@LOC(\"";
 
   private String generateLocationAnnoatation(CompositeLocation loc) {
     String rtr = "@LOC(\"";
 
index d0f217dc8c3a872909493a3c132b69bb5ae9c6fb..c022ba06dc86338fdd4db4064ad7fae21567b476 100644 (file)
@@ -197,8 +197,7 @@ final class LayerIIIDecoder implements FrameDecoder {
     channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
     max_gr = (header.version() == Header.MPEG1) ? 2 : 1;
 
     channels = (header.mode() == Header.SINGLE_CHANNEL) ? 1 : 2;
     max_gr = (header.version() == Header.MPEG1) ? 2 : 1;
 
-    sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1) ? 3
-        : (header.version() == Header.MPEG25_LSF) ? 6 : 0); // SZD
+    sfreq = header.sample_frequency() + ((header.version() == Header.MPEG1) ? 3 : (header.version() == Header.MPEG25_LSF) ? 6 : 0); // SZD
 
     if (channels == 2) {
       switch (which_channels) {
 
     if (channels == 2) {
       switch (which_channels) {
@@ -1068,10 +1067,10 @@ final class LayerIIIDecoder implements FrameDecoder {
 
   private void huffman_decode(int part2_start_local, int ch, int gr) {
 
 
   private void huffman_decode(int part2_start_local, int ch, int gr) {
 
-    int x[] = new int[1];
-    int y[] = new int[1];
-    int v[] = new int[1];
-    int w[] = new int[1];
+    int[] x = new int[1];
+    int[] y = new int[1];
+    int[] v = new int[1];
+    int[] w = new int[1];
 
     int part2_3_end = part2_start_local + si.ch[ch].gr[gr].part2_3_length;
     int num_bits;
 
     int part2_3_end = part2_start_local + si.ch[ch].gr[gr].part2_3_length;
     int num_bits;
@@ -1204,8 +1203,7 @@ final class LayerIIIDecoder implements FrameDecoder {
   //
 
   // ssjava
   //
 
   // ssjava
-  private void dequantize_sample(
-  /* float xr[][], */int ch, int gr) {
+  private void dequantize_sample(int ch, int gr) {
 
     // gr_info_s gr_info = (si.ch[ch].gr[gr]); remove alias!
     int cb = 0;
 
     // gr_info_s gr_info = (si.ch[ch].gr[gr]); remove alias!
     int cb = 0;
@@ -1367,7 +1365,7 @@ final class LayerIIIDecoder implements FrameDecoder {
   // ssjava
   //
 
   // ssjava
   //
 
-  private void reorder(/* float xr[][], */int ch, int gr) {
+  private void reorder(int ch, int gr) {
     // the purpose of reordering: move 'short samples' back to their original
     // position
     // after reorder, the samples are no long ordered by frequency
     // the purpose of reordering: move 'short samples' back to their original
     // position
     // after reorder, the samples are no long ordered by frequency
@@ -2403,7 +2401,7 @@ final class LayerIIIDecoder implements FrameDecoder {
    * ExceptionInInitializerError(ex); } }
    */
 
    * ExceptionInInitializerError(ex); } }
    */
 
-  static int[] reorder(int scalefac_band[]) { // SZD: converted from
+  static int[] reorder(int[] scalefac_band) { // SZD: converted from
                                               // LAME
     int j = 0;
     int ix[] = new int[576];
                                               // LAME
     int j = 0;
     int ix[] = new int[576];
index 4a12624472b1c997a0d9d3604677cc5d3dd88014..5304e86afa7edb9cbf74ef0d4de5b3aef2738dd0 100644 (file)
@@ -1,4 +1,4 @@
-BUILDSCRIPT=../../../buildscript
+BUILDSCRIPT=../../../../buildscript
 
 PROGRAM=MP3Player
 SOURCE_FILES=MP3Player.java Player.java
 
 PROGRAM=MP3Player
 SOURCE_FILES=MP3Player.java Player.java