Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite IR Interpreter #241

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
182c9e8
refactor call to a statement & add unreachable and return jumps
ailrst Aug 19, 2024
3711e4d
move transforms out of RunUtils.scala
ailrst Aug 19, 2024
fd56c9a
remove old cfg
ailrst Aug 9, 2024
bd6b2ad
update docs
ailrst Aug 19, 2024
96b9028
pe based expr evaluator
ailrst Aug 19, 2024
d264b97
interpreter test
ailrst Aug 19, 2024
a3bf83b
rewrite interpreter in functional style
ailrst Aug 22, 2024
74c4bc2
cleanup call/return
ailrst Aug 22, 2024
9e23558
cleanup memory ops to enter effects
ailrst Aug 22, 2024
7571aa3
tracing interpreter
ailrst Aug 26, 2024
f36c13e
compile with state monad
ailrst Aug 27, 2024
2c16c83
fix state monad interp
ailrst Aug 28, 2024
dd11175
indirect calls
ailrst Aug 28, 2024
c7b4a56
tracing interpreter
ailrst Aug 28, 2024
f64f904
breakpoints
ailrst Aug 28, 2024
897c565
improve breakpoints
ailrst Aug 29, 2024
cc97052
reorg
ailrst Aug 29, 2024
695b2d2
refactor with statemonad[s, either[v]]
ailrst Aug 29, 2024
00b482a
redo error handling
ailrst Aug 29, 2024
1a139d2
refactor call to a statement & add unreachable and return jumps
ailrst Aug 19, 2024
7e94536
move transforms out of RunUtils.scala
ailrst Aug 19, 2024
aae0064
remove old cfg
ailrst Aug 9, 2024
e2c0cd4
update docs
ailrst Aug 19, 2024
a3adee3
fix
ailrst Aug 30, 2024
4a92c99
fix externals
ailrst Aug 30, 2024
b994c99
disable IDE analyses if mainproc is external
ailrst Aug 30, 2024
b83c9ff
Merge branch 'call-statement' into interpreter
ailrst Aug 30, 2024
d6c5767
work on differential testing
ailrst Aug 30, 2024
2a03a23
hook for dynlinking
ailrst Sep 2, 2024
8b694c0
load full symtab
ailrst Sep 2, 2024
57ca6b3
update relf grammar
ailrst Sep 3, 2024
b276981
init bss
ailrst Sep 3, 2024
888d360
cleanup
ailrst Sep 3, 2024
0abf654
cleanup init trace
ailrst Sep 3, 2024
9192ce3
intrinsic stub and cleanup errors
ailrst Sep 3, 2024
5342358
init relocation table
ailrst Sep 3, 2024
87b0f86
pull stepper outside effects to fix interpreter composition again
ailrst Sep 4, 2024
f5a0590
cleanup
ailrst Sep 4, 2024
a6b58e8
cleanup
ailrst Sep 4, 2024
dd64c14
constprop test with interpreter
ailrst Sep 4, 2024
8be5cb6
interpreter docs
ailrst Sep 4, 2024
d2a2486
fix list
ailrst Sep 4, 2024
d06e268
paragraph
ailrst Sep 4, 2024
4ae3997
trap eval exceptions to monadic errors
ailrst Sep 4, 2024
4fc8ed2
improve interpretOne
ailrst Sep 4, 2024
8f966ce
notes on initialisation
ailrst Sep 4, 2024
f00b44b
simplify invoc funcs
ailrst Sep 4, 2024
ceef233
note missing features
ailrst Sep 5, 2024
cff6c97
run through all system tests
ailrst Sep 5, 2024
822c127
add resource limit
ailrst Sep 5, 2024
9b8f715
doc resource limit
ailrst Sep 5, 2024
648a41d
tweak doc
ailrst Sep 5, 2024
dfa7209
fix
ailrst Sep 5, 2024
38f871c
tweak interpretrlimit
ailrst Sep 5, 2024
6559180
basic malloc implementation
ailrst Sep 9, 2024
c6e938d
implement printf
ailrst Sep 10, 2024
285099b
cleanup intrins
ailrst Sep 10, 2024
aac7f5c
cleanup
ailrst Sep 23, 2024
1c2a5d5
Merge remote-tracking branch 'upstream/main' into interpreter
ailrst Sep 23, 2024
46ff66a
cleanup
ailrst Sep 23, 2024
970c55a
Merge branch 'main' into interpreter
Nov 8, 2024
1a8067c
make compiler options consistent
Nov 8, 2024
32bf439
fix use of deprecated examples
Nov 8, 2024
9cc3c31
fix use of deprecated examples
Nov 8, 2024
fe3678f
give State filename consistent with Package, formatting, clean up imp…
Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run through all system tests
  • Loading branch information
ailrst committed Sep 5, 2024
commit cff6c970584815b036bd132cb148ac959aea2cc9
4 changes: 2 additions & 2 deletions src/main/scala/util/functional.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ case class State[S, A, E](f: S => (S, Either[E, A])) {

def >>(o: State[S,A,E]) = for {
_ <- this
_ <- o
} yield (())
x <- o
} yield (x)


def flatMap[B](f: A => State[S, B, E]): State[S, B, E] = State(s => {
Expand Down
64 changes: 29 additions & 35 deletions src/test/scala/DifferentialAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.scalatest.funsuite.*
import specification.*
import util.{BASILConfig, IRLoading, ILLoadingConfig, IRContext, RunUtils, StaticAnalysis, StaticAnalysisConfig, StaticAnalysisContext, BASILResult, Logger, LogLevel, IRTransform}
import ir.eval.{interpretTrace, interpret, ExecEffect, Stopped}
import test_util.*


import java.io.IOException
Expand Down Expand Up @@ -44,9 +45,9 @@ class DifferentialAnalysis extends AnyFunSuite {
assert(filterEvents(traceInit.t).mkString("\n") == filterEvents(traceRes.t).mkString("\n"))
}

def testProgram(testName: String, examplePath: String) = {
def testProgram(testName: String, examplePath: String, suffix: String =".adt") = {

val loading = ILLoadingConfig(inputFile = examplePath + testName + ".adt",
val loading = ILLoadingConfig(inputFile = examplePath + testName + suffix,
relfFile = examplePath + testName + ".relf",
dumpIL = None,
)
Expand All @@ -67,35 +68,13 @@ class DifferentialAnalysis extends AnyFunSuite {
testProgram(testName, examplePath)
}

test("indirect_call_gcc_example") {
val testName = "indirect_call"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/gcc/"
testProgram(testName, examplePath)
}

test("indirect_call_clang_example") {
val testName = "indirect_call"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/clang/"
testProgram(testName, examplePath)
}

test("jumptable2_example") {
val testName = "jumptable2"
val examplePath = System.getProperty("user.dir") + s"/examples/$testName/"
testProgram(testName, examplePath)
}

test("jumptable2_gcc_example") {
val testName = "jumptable2"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/gcc/"
testProgram(testName, examplePath)
}

test("jumptable2_clang_example") {
val testName = "jumptable2"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/clang/"
testProgram(testName, examplePath)
}

test("jumptable_example") {
val testName = "jumptable"
Expand All @@ -109,22 +88,37 @@ class DifferentialAnalysis extends AnyFunSuite {
testProgram(testName, examplePath)
}

test("functionpointer_gcc_example") {
val testName = "functionpointer"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/gcc/"
testProgram(testName, examplePath)
}

test("functionpointer_clang_example") {
val testName = "functionpointer"
val examplePath = System.getProperty("user.dir") + s"/src/test/correct/$testName/clang/"
testProgram(testName, examplePath)
}


test("function_got_example") {
val testName = "function_got"
val examplePath = System.getProperty("user.dir") + s"/examples/$testName/"
testProgram(testName, examplePath)
}


def runSystemTests(): Unit = {

val path = System.getProperty("user.dir") + s"/src/test/correct/"
val programs: Array[String] = getSubdirectories(path)

// get all variations of each program
for (p <- programs) {
val programPath = path + "/" + p
val variations = getSubdirectories(programPath)
println(variations.mkString("\n"))
variations.foreach(variation => {
test("analysis_differential:" + p + "/" + variation + ":BAP") {
testProgram(p, path + "/" + p + "/" + variation + "/", suffix=".adt")
}
test("analysis_differential:" + p + "/" + variation + ":GTIRB") {
testProgram(p, path + "/" + p + "/" + variation + "/", suffix=".gts")
}
}
)
}
}


runSystemTests()
}
22 changes: 2 additions & 20 deletions src/test/scala/SystemTests.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.scalatest.funsuite.AnyFunSuite
import util.{Logger, PerformanceTimer}
import test_util.*

import Numeric.Implicits.*
import java.io.{BufferedWriter, File, FileWriter}
Expand Down Expand Up @@ -215,25 +216,6 @@ trait SystemTests extends AnyFunSuite {
true
}

/** @param directoryName
* of the parent directory
* @return
* the names all subdirectories of the given parent directory
*/
def getSubdirectories(directoryName: String): Array[String] = {
Option(File(directoryName).listFiles(_.isDirectory)) match {
case None => throw java.io.IOException(s"failed to read directory '$directoryName'")
case Some(subdirs) => subdirs.map(_.getName)
}
}

def log(text: String, path: String): Unit = {
val writer = BufferedWriter(FileWriter(path, false))
writer.write(text)
writer.flush()
writer.close()
}

}

class SystemTestsBAP extends SystemTests {
Expand Down Expand Up @@ -343,4 +325,4 @@ def loadHisto() = {
val timeValues = res("verifyTime").map(_.toDouble)
val histo = histogram(50, Some(800.0, 1000.0))(timeValues.toSeq)
println(histoToSvg("test histogram", 500, 300, histo, 800.0, 1000.0))
}
}
22 changes: 22 additions & 0 deletions src/test/scala/test_util/TestUtil.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package test_util
import java.io.{BufferedWriter, File, FileWriter}

import ir.{Block, Procedure, Program}
import util.{BASILConfig, BASILResult, BoogieGeneratorConfig, ILLoadingConfig, RunUtils, StaticAnalysisConfig}
Expand Down Expand Up @@ -40,3 +41,24 @@ trait TestUtil {
)
}
}


/** @param directoryName
* of the parent directory
* @return
* the names all subdirectories of the given parent directory
*/
def getSubdirectories(directoryName: String): Array[String] = {
Option(File(directoryName).listFiles(_.isDirectory)) match {
case None => throw java.io.IOException(s"failed to read directory '$directoryName'")
case Some(subdirs) => subdirs.map(_.getName)
}
}

def log(text: String, path: String): Unit = {
val writer = BufferedWriter(FileWriter(path, false))
writer.write(text)
writer.flush()
writer.close()
}