Snippets

Michael Eichberg [OPAL - 0.8.15] Transforming all methods of all class files of a JAR to a 3-address representation

Updated by Michael Eichberg

File CreateTACsForJAR.scala Modified

  • Ignore whitespace
  • Hide word diff
 // 3) change the project to OPAL-DeveloperTools (`project OPAL-DeveloperTools`)
 // 4) start the scala console (`console`)
 // 5) <paste in the following code>
+import scala.language.existentials
+
 import org.opalj.io.writeAndOpen
 import org.opalj.tac._
 import org.opalj.util.PerformanceEvaluation.time
-val f = new java.io.File("OPAL/bi/target/scala-2.11/resource_managed/test/ai.jar")
+val f = new java.io.File("OPAL/bi/target/scala-2.11/resource_managed/test/arrays.jar")
 val p = org.opalj.br.analyses.Project(f)
 time {
-  p.parForeachMethodWithBody(parallelizationLevel=16){ mi => 
-   
+  println("starting tac generation")
+  val errors = p.parForeachMethodWithBody(parallelizationLevel=16){ mi => 
     // Create representation
-    val taCode = org.opalj.tac.TACAI(p,mi.method)()
+    val taCode = TACAI(p,mi.method)()
    
     // Convert to JavaLike text based representation
     val tac = ToTxt(taCode).mkString("\n")
 
     println(file)
   }
+  errors.foreach(println)
+  println("finished tac generation")
 }(t => println("Analysis time: "+t.toSeconds))
Updated by Michael Eichberg

File CreateTACsForJAR.scala Modified

  • Ignore whitespace
  • Hide word diff
 import org.opalj.io.writeAndOpen
 import org.opalj.tac._
 import org.opalj.util.PerformanceEvaluation.time
-val f = new java.io.File("<THE JAR/CLASS FILE>")
+val f = new java.io.File("OPAL/bi/target/scala-2.11/resource_managed/test/ai.jar")
 val p = org.opalj.br.analyses.Project(f)
-var i = 0
 time {
-  p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
+  p.parForeachMethodWithBody(parallelizationLevel=16){ mi => 
    
     // Create representation
-    val (code,_) = org.opalj.tac.AsQuadruples(mi.method,p.classHierarchy)
+    val taCode = org.opalj.tac.TACAI(p,mi.method)()
    
     // Convert to JavaLike text based representation
-    val tac = ToJavaLike(code)
+    val tac = ToTxt(taCode).mkString("\n")
     val fileNamePrefix = mi.classFile.thisType.toJava+"."+mi.method.name
     val file = writeAndOpen(tac, fileNamePrefix, ".tac.txt")
-   
-    i+= 1
-    println(i+":"+file)
+
+    println(file)
   }
 }(t => println("Analysis time: "+t.toSeconds))
Updated by Michael Eichberg

File CreateTACsForJAR.scala Modified

  • Ignore whitespace
  • Hide word diff
 // 3) change the project to OPAL-DeveloperTools (`project OPAL-DeveloperTools`)
 // 4) start the scala console (`console`)
 // 5) <paste in the following code>
-import org.opalj.io.write
+import org.opalj.io.writeAndOpen
 import org.opalj.tac._
 import org.opalj.util.PerformanceEvaluation.time
-val f = new java.io.File("<THE JAR FILE>")
+val f = new java.io.File("<THE JAR/CLASS FILE>")
 val p = org.opalj.br.analyses.Project(f)
 var i = 0
 time {
-p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
+  p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
    
-   // Create representation
-   val (code,_) = org.opalj.tac.AsQuadruples(mi.method,p.classHierarchy)
+    // Create representation
+    val (code,_) = org.opalj.tac.AsQuadruples(mi.method,p.classHierarchy)
    
-   // Convert to JavaLike text based representation
-   val tac = ToJavaLike(code)
-   val fileNamePrefix = mi.classFile.thisType.toJava+"."+mi.method.name
-   val file = write(tac, fileNamePrefix, ".tac.txt")
+    // Convert to JavaLike text based representation
+    val tac = ToJavaLike(code)
+    val fileNamePrefix = mi.classFile.thisType.toJava+"."+mi.method.name
+    val file = writeAndOpen(tac, fileNamePrefix, ".tac.txt")
    
-   i+= 1
-   println(i+":"+file)
-}
+    i+= 1
+    println(i+":"+file)
+  }
 }(t => println("Analysis time: "+t.toSeconds))
Updated by Michael Eichberg

File CreateTACsForJAR.scala Modified

  • Ignore whitespace
  • Hide word diff
- import org.opalj.io.write
- import org.opalj.tac._
- import org.opalj.util.PerformanceEvaluation.time
- val f = new java.io.File("/Users/eichberg/Downloads/presto-verifier-0.147-executable.zip")
- val p = org.opalj.br.analyses.Project(f)
- var i = 0
- time {
- p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
+// to execute the following code do the following:
+// 1) clone OPAL, 
+// 2) start sbt in OPAL's root directory (`sbt`),
+// 3) change the project to OPAL-DeveloperTools (`project OPAL-DeveloperTools`)
+// 4) start the scala console (`console`)
+// 5) <paste in the following code>
+import org.opalj.io.write
+import org.opalj.tac._
+import org.opalj.util.PerformanceEvaluation.time
+val f = new java.io.File("<THE JAR FILE>")
+val p = org.opalj.br.analyses.Project(f)
+var i = 0
+time {
+p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
    
    // Create representation
    val (code,_) = org.opalj.tac.AsQuadruples(mi.method,p.classHierarchy)
    
    i+= 1
    println(i+":"+file)
- }
- }(t => println("Analysis time: "+t.toSeconds))
+}
+}(t => println("Analysis time: "+t.toSeconds))
Created by Michael Eichberg

File CreateTACsForJAR.scala Added

  • Ignore whitespace
  • Hide word diff
+ import org.opalj.io.write
+ import org.opalj.tac._
+ import org.opalj.util.PerformanceEvaluation.time
+ val f = new java.io.File("/Users/eichberg/Downloads/presto-verifier-0.147-executable.zip")
+ val p = org.opalj.br.analyses.Project(f)
+ var i = 0
+ time {
+ p.parForeachMethodWithBody(parallelizationLevel=32){ mi => 
+   
+   // Create representation
+   val (code,_) = org.opalj.tac.AsQuadruples(mi.method,p.classHierarchy)
+   
+   // Convert to JavaLike text based representation
+   val tac = ToJavaLike(code)
+   val fileNamePrefix = mi.classFile.thisType.toJava+"."+mi.method.name
+   val file = write(tac, fileNamePrefix, ".tac.txt")
+   
+   i+= 1
+   println(i+":"+file)
+ }
+ }(t => println("Analysis time: "+t.toSeconds))
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.