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

TS symbolic machine expansion #201

Merged
merged 22 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.plugin.use.PluginDependenciesSpec
object Versions {
const val detekt = "1.18.1"
const val ini4j = "0.5.4"
const val jacodb = "30594f5f7c"
const val jacodb = "4164b3cc64"
const val juliet = "1.3.2"
const val junit = "5.9.3"
const val kotlin = "1.9.20"
Expand Down
4 changes: 2 additions & 2 deletions usvm-ts/src/main/kotlin/org/usvm/TSApplicationGraph.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.usvm

import org.jacodb.ets.base.EtsStmt
import org.jacodb.ets.graph.EtsApplicationGraph
import org.jacodb.ets.graph.EtsApplicationGraphImpl
import org.jacodb.ets.model.EtsFile
import org.jacodb.ets.model.EtsMethod
import org.usvm.statistics.ApplicationGraph

class TSApplicationGraph(project: EtsFile) : ApplicationGraph<EtsMethod, EtsStmt> {
private val applicationGraph = EtsApplicationGraph(project)
private val applicationGraph = EtsApplicationGraphImpl(project)

override fun predecessors(node: EtsStmt): Sequence<EtsStmt> =
applicationGraph.predecessors(node)
Expand Down
42 changes: 42 additions & 0 deletions usvm-ts/src/main/kotlin/org/usvm/TSBinaryOperator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.usvm

import io.ksmt.utils.cast

sealed class TSBinaryOperator(
val onBool: TSContext.(UExpr<UBoolSort>, UExpr<UBoolSort>) -> UExpr<out USort> = shouldNotBeCalled,
val onBv: TSContext.(UExpr<UBvSort>, UExpr<UBvSort>) -> UExpr<out USort> = shouldNotBeCalled,
val onFp: TSContext.(UExpr<UFpSort>, UExpr<UFpSort>) -> UExpr<out USort> = shouldNotBeCalled,
) {

object Eq : TSBinaryOperator(
onBool = UContext<TSSizeSort>::mkEq,
onBv = UContext<TSSizeSort>::mkEq,
onFp = UContext<TSSizeSort>::mkFpEqualExpr,
)

object Neq : TSBinaryOperator(
onBool = { lhs, rhs -> lhs.neq(rhs) },
onBv = { lhs, rhs -> lhs.neq(rhs) },
onFp = { lhs, rhs -> mkFpEqualExpr(lhs, rhs).not() },
)

internal operator fun invoke(lhs: UExpr<out USort>, rhs: UExpr<out USort>): UExpr<out USort> {
val lhsSort = lhs.sort
val rhsSort = rhs.sort

if (lhsSort != rhsSort) TODO("Implement type coercion")

return when {
lhsSort is UBoolSort -> lhs.tctx.onBool(lhs.cast(), rhs.cast())
lhsSort is UBvSort -> lhs.tctx.onBv(lhs.cast(), rhs.cast())
lhsSort is UFpSort -> lhs.tctx.onFp(lhs.cast(), rhs.cast())

else -> error("Unexpected sorts: $lhsSort, $rhsSort")
}
}

companion object {
private val shouldNotBeCalled: TSContext.(UExpr<out USort>, UExpr<out USort>) -> UExpr<out USort> =
{ _, _ -> error("Should not be called") }
}
}
4 changes: 2 additions & 2 deletions usvm-ts/src/main/kotlin/org/usvm/TSComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class TSComponents(
private val closeableResources = mutableListOf<AutoCloseable>()

override val useSolverForForks: Boolean
get() = TODO("Not yet implemented")
get() = options.useSolverForForks

override fun <Context : UContext<TSSizeSort>> mkSizeExprProvider(ctx: Context): USizeExprProvider<TSSizeSort> {
TODO("Not yet implemented")
return UBv32SizeExprProvider(ctx)
}

override fun mkTypeSystem(
Expand Down
21 changes: 20 additions & 1 deletion usvm-ts/src/main/kotlin/org/usvm/TSContext.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package org.usvm

import org.jacodb.ets.base.EtsBooleanType
import org.jacodb.ets.base.EtsNumberType
import org.jacodb.ets.base.EtsRefType
import org.jacodb.ets.base.EtsType

typealias TSSizeSort = UBv32Sort

class TSContext(components: TSComponents) : UContext<TSSizeSort>(components)
class TSContext(components: TSComponents) : UContext<TSSizeSort>(components) {

val undefinedSort: TSUndefinedSort by lazy { TSUndefinedSort(this) }

private val undefinedValue by lazy { TSUndefinedValue(this) }

fun typeToSort(type: EtsType): USort = when (type) {
is EtsBooleanType -> boolSort
is EtsNumberType -> fp64Sort
is EtsRefType -> addressSort
else -> TODO("Support all JacoDB types")
}

fun mkUndefinedValue(): TSUndefinedValue = undefinedValue
}
Loading