Skip to content

Commit f69828f

Browse files
committed
Add isRestorable to WOODDumpResponse
This can be used by the slide code to determine if a snapshot has enough info in order to restore it.
1 parent 541e56d commit f69828f

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎src/main/kotlin/be/ugent/topl/mio/debugger/MultiverseDebugger.kt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import be.ugent.topl.mio.ui.disassemble
88
import be.ugent.topl.mio.woodstate.Checkpoint
99
import be.ugent.topl.mio.woodstate.WOODDumpResponse
1010
import be.ugent.topl.mio.woodstate.WasmStackValue
11-
import kotlin.collections.iterator
1211

1312
class MultiverseGraph(var rootNode: MultiverseNode = MultiverseNode("main", listOf()), var currentNode: MultiverseNode = rootNode, var instructionOffset: Int = 0) {
1413
/**
@@ -317,8 +316,7 @@ class MultiverseDebugger(
317316
for (checkpoint in checkPointNode.checkpoints) {
318317
currentOffset += checkpoint.instructions_executed
319318
println("Current offset = $currentOffset in node $checkPointNode")
320-
// TODO: Use a function from woodstate to say if it's restorable
321-
if (checkpoint.snapshot.memory != null) {
319+
if (checkpoint.snapshot.isRestorable()) {
322320
if (checkPointNode == targetNode) {
323321
if(targetInstructionOffset >= currentOffset)
324322
return Pair(checkpoint.snapshot, currentOffset)

‎src/main/kotlin/be/ugent/topl/mio/woodstate/WOODState.kt‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ data class WOODDumpResponse(
151151
val events: List<InterruptEvent>?,
152152
val io: List<IOState>?,
153153
val overrides: List<PrimitiveOverride>?
154-
)
154+
) {
155+
fun isRestorable(): Boolean = globals != null && table != null && memory != null
156+
}
155157

156158
data class Checkpoint(
157159
val instructions_executed: Int,
@@ -452,7 +454,7 @@ class WOODState(woodResponse: WOODDumpResponse) {
452454

453455
private fun serialiseAllocationMessage(stateMsgs: HexaStateMessages) {
454456
val wr = this.woodResponse
455-
if (wr.globals == null || wr.table == null || wr.memory == null) {
457+
if (!wr.isRestorable()) {
456458
throw Error("cannot serialise Allocaton Message when state is missing")
457459
}
458460

@@ -462,19 +464,19 @@ class WOODState(woodResponse: WOODDumpResponse) {
462464

463465
// Globals
464466

465-
val gblsAmountHex = HexaEncoder.serializeUInt32BE(wr.globals.size)
467+
val gblsAmountHex = HexaEncoder.serializeUInt32BE(wr.globals!!.size)
466468
logger.trace("Globals: total=${wr.globals.size}")
467469
val globals = "${ExecutionStateType.globalsState}${gblsAmountHex}"
468470

469471
// Table
470-
val tblInitHex = HexaEncoder.serializeUInt32BE(wr.table.init)
472+
val tblInitHex = HexaEncoder.serializeUInt32BE(wr.table!!.init)
471473
val tblMaxHex = HexaEncoder.serializeUInt32BE(wr.table.max)
472474
val tblSizeHex = HexaEncoder.serializeUInt32BE(wr.table.elements.size)
473475
val tbl = "${ExecutionStateType.tableState}${tblInitHex}${tblMaxHex}${tblSizeHex}"
474476

475477
logger.trace("Table: init=${wr.table.init} max=${wr.table.max} size=${wr.table.elements.size}")
476478
// Memory
477-
val memInitHex = HexaEncoder.serializeUInt32BE(wr.memory.init)
479+
val memInitHex = HexaEncoder.serializeUInt32BE(wr.memory!!.init)
478480
val memMaxHex = HexaEncoder.serializeUInt32BE(wr.memory.max)
479481
val memPagesHex = HexaEncoder.serializeUInt32BE(wr.memory.pages)
480482
val mem = "${ExecutionStateType.memState}${memMaxHex}${memInitHex}${memPagesHex}"

0 commit comments

Comments
 (0)