Skip to content

Commit 464fee8

Browse files
LipenCaelmBleidd
andauthored
Support simple calls (#246)
Co-authored-by: Alexey Menshutin <alex.menshutin99@gmail.com>
1 parent 54d248a commit 464fee8

File tree

8 files changed

+502
-170
lines changed

8 files changed

+502
-170
lines changed

usvm-ts/src/main/kotlin/org/usvm/machine/expr/TSExprResolver.kt

Lines changed: 212 additions & 103 deletions
Large diffs are not rendered by default.

usvm-ts/src/main/kotlin/org/usvm/machine/interpreter/TSInterpreter.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,12 @@ class TSInterpreter(
8989

9090
private fun visitIfStmt(scope: TSStepScope, stmt: EtsIfStmt) {
9191
val exprResolver = exprResolverWithScope(scope)
92+
val expr = exprResolver.resolve(stmt.condition) ?: return
9293

93-
val conditionExpr = exprResolver.resolve(stmt.condition) ?: run {
94-
logger.warn { "Failed to resolve condition: $stmt" }
95-
return
96-
}
97-
98-
val boolExpr = if (conditionExpr.sort == ctx.boolSort) {
99-
conditionExpr.asExpr(ctx.boolSort)
94+
val boolExpr = if (expr.sort == ctx.boolSort) {
95+
expr.asExpr(ctx.boolSort)
10096
} else {
101-
ctx.mkTruthyExpr(conditionExpr, scope)
97+
ctx.mkTruthyExpr(expr, scope)
10298
}
10399

104100
val (negStmt, posStmt) = applicationGraph.successors(stmt).take(2).toList()
@@ -126,7 +122,6 @@ class TSInterpreter(
126122

127123
private fun visitAssignStmt(scope: TSStepScope, stmt: EtsAssignStmt) {
128124
val exprResolver = exprResolverWithScope(scope)
129-
130125
val expr = exprResolver.resolve(stmt.rhv) ?: return
131126

132127
check(expr.sort != ctx.unresolvedSort) {
@@ -135,7 +130,7 @@ class TSInterpreter(
135130

136131
scope.doWithState {
137132
val idx = mapLocalToIdx(lastEnteredMethod, stmt.lhv)
138-
saveSortForLocal(lastEnteredMethod, idx, expr.sort)
133+
saveSortForLocal(idx, expr.sort)
139134

140135
val lValue = URegisterStackLValue(expr.sort, idx)
141136
memory.write(lValue, expr.asExpr(lValue.sort), guard = ctx.trueExpr)
@@ -146,10 +141,17 @@ class TSInterpreter(
146141
}
147142

148143
private fun visitCallStmt(scope: TSStepScope, stmt: EtsCallStmt) {
149-
TODO() // IMPORTANT do not forget to fill sorts of arguments map
144+
val exprResolver = exprResolverWithScope(scope)
145+
exprResolver.resolve(stmt.expr) ?: return
146+
147+
scope.doWithState {
148+
val nextStmt = stmt.nextStmt ?: return@doWithState
149+
newStmt(nextStmt)
150+
}
150151
}
151152

152153
private fun visitThrowStmt(scope: TSStepScope, stmt: EtsThrowStmt) {
154+
// TODO do not forget to pop the sorts call stack in the state
153155
TODO()
154156
}
155157

0 commit comments

Comments
 (0)