Skip to content

Commit 3e5715d

Browse files
authored
Clean up ConcolicMiniWasm (#83)
* clean up wasm-cps stuff * clean up ConcolicMiniWasm * fmt * add ci
1 parent e061ed6 commit 3e5715d

File tree

5 files changed

+376
-229
lines changed

5 files changed

+376
-229
lines changed

.github/workflows/scala.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ jobs:
7676
sbt 'testOnly gensym.TestLibrary'
7777
sbt 'testOnly gensym.wasm.TestEval'
7878
sbt 'testOnly gensym.wasm.TestScriptRun'
79+
sbt 'testOnly gensym.wasm.TestConcolic'

src/main/scala/wasm/AST.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ case class ElemListExpr(exprs: List[List[Instr]]) extends ElemList
3333
abstract class FuncField extends WIR
3434
case class FuncBodyDef(tipe: FuncType, localNames: List[String], locals: List[ValueType], body: List[Instr])
3535
extends FuncField
36+
// TODO: FunInline was never used
3637
case class FunInlineImport(mod: String, name: String, typeUse: Option[Int], imports: Any /*FIXME*/ ) extends FuncField
3738
case class FunInlineExport(fd: List[FuncDef]) extends FuncField
3839

src/main/scala/wasm/ConcolicDriver.scala

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,28 @@ object ConcolicDriver {
1919

2020
def symVToZ3(symV: SymVal): Z3AST = symV match {
2121
case SymV(name) => z3Ctx.mkConst(name, intSort) // might not be an int?
22-
case SymBinary(op, lhs, rhs) => op match {
23-
case Add(_) => z3Ctx.mkAdd(symVToZ3(lhs), symVToZ3(rhs)) // does numtype matter?
24-
case Sub(_) => z3Ctx.mkSub(symVToZ3(lhs), symVToZ3(rhs))
25-
case Mul(_) => z3Ctx.mkMul(symVToZ3(lhs), symVToZ3(rhs))
26-
case _ => ???
27-
}
28-
case SymUnary(op, v) => op match {
29-
case _ => ???
30-
}
22+
case SymBinary(op, lhs, rhs) =>
23+
op match {
24+
case Add(_) => z3Ctx.mkAdd(symVToZ3(lhs), symVToZ3(rhs)) // does numtype matter?
25+
case Sub(_) => z3Ctx.mkSub(symVToZ3(lhs), symVToZ3(rhs))
26+
case Mul(_) => z3Ctx.mkMul(symVToZ3(lhs), symVToZ3(rhs))
27+
case _ => ???
28+
}
29+
case SymUnary(op, v) =>
30+
op match {
31+
case _ => ???
32+
}
3133
case SymIte(cond, thenV, elseV) => z3Ctx.mkITE(condToZ3(cond), symVToZ3(thenV), symVToZ3(elseV))
32-
case Concrete(v) => ???
33-
case _ => ???
34+
case Concrete(v) => ???
35+
case _ => ???
3436
}
3537
def condToZ3(cond: Cond): Z3AST = cond match {
3638
case CondEqz(v) => z3Ctx.mkEq(symVToZ3(v), z3Ctx.mkInt(0, intSort))
37-
case Not(cond) => z3Ctx.mkNot(condToZ3(cond))
38-
case RelCond(op, lhs, rhs) => op match {
39-
case _ => ???
40-
}
39+
case Not(cond) => z3Ctx.mkNot(condToZ3(cond))
40+
case RelCond(op, lhs, rhs) =>
41+
op match {
42+
case _ => ???
43+
}
4144
}
4245

4346
val solver = z3Ctx.mkSolver()
@@ -85,16 +88,21 @@ object ConcolicDriver {
8588
def loop(worklist: Queue[HashMap[Int, Value]]): Unit = worklist match {
8689
case Queue() => ()
8790
case env +: rest => {
88-
Evaluator.execWholeProgram(module, mainFun, env, (_endStack, _endSymStack, pathConds) => {
89-
println(s"env: $env")
90-
val newEnv = condsToEnv(pathConds)
91-
val newWork = for (i <- 0 until pathConds.length) yield {
92-
val newConds = negateCond(pathConds, i)
93-
checkPCToFile(newConds)
94-
condsToEnv(newConds)
91+
val moduleInst = ModuleInstance(module)
92+
Evaluator(moduleInst).execWholeProgram(
93+
Some(mainFun),
94+
env,
95+
(_endStack, _endSymStack, pathConds) => {
96+
println(s"env: $env")
97+
val newEnv = condsToEnv(pathConds)
98+
val newWork = for (i <- 0 until pathConds.length) yield {
99+
val newConds = negateCond(pathConds, i)
100+
checkPCToFile(newConds)
101+
condsToEnv(newConds)
102+
}
103+
loop(rest ++ newWork)
95104
}
96-
loop(rest ++ newWork)
97-
})
105+
)
98106
}
99107
}
100108

@@ -110,6 +118,5 @@ object DriverSimpleTest {
110118
ConcolicDriver.exec(module, mainFun, startEnv)(new Z3Context())
111119
}
112120

113-
def main(args: Array[String]) = {
114-
}
121+
def main(args: Array[String]) = {}
115122
}

0 commit comments

Comments
 (0)