Skip to content

Commit 6035cbd

Browse files
committed
Update binary metadata to match the updated WARDuino --dump-info output + use it for arg counts when mocking
This way we now have much more information about primitives and the mock window can show the correct number of argument text fields for each primitive based on the metadata instead of hardcoded values.
1 parent 7cd5ace commit 6035cbd

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ class MultiverseDebugger(
257257
overrides.clear()
258258
for (snapshotOverrides in snapshot.overrides) {
259259
// Ignore overrides that don't appear in this program. Maybe they were for another program that we hot loaded.
260-
if (snapshotOverrides.fidx >= wasmBinary.metadata.primitive_fidx_mapping.size)
260+
if (snapshotOverrides.fidx >= wasmBinary.metadata.primitives.size)
261261
continue
262262

263-
val primitiveName = wasmBinary.metadata.primitive_fidx_mapping[snapshotOverrides.fidx]
263+
val primitiveName = wasmBinary.metadata.primitives[snapshotOverrides.fidx].name
264264
if (!overrides.containsKey(primitiveName)) {
265265
overrides[primitiveName] = mutableMapOf()
266266
}
@@ -291,11 +291,11 @@ class MultiverseDebugger(
291291
val checkpoint = newCheckpoints.last()
292292
if (graph.currentNode.children.isEmpty() && change > 0 && checkpoint?.fidx_called != null) {
293293
val newNode = if (isAfterChoicePoint(checkpoint.snapshot.pc!!)) {
294-
PrimitiveNode(wasmBinary.metadata.primitive_fidx_mapping[checkpoint.fidx_called], checkpoint.args!!).apply {
294+
PrimitiveNode(wasmBinary.metadata.primitives[checkpoint.fidx_called].name, checkpoint.args!!).apply {
295295
values.add(checkpoint.returns!!.first())
296296
}
297297
} else {
298-
DeterministicPrimitiveNode(wasmBinary.metadata.primitive_fidx_mapping[checkpoint.fidx_called], checkpoint.args!!)
298+
DeterministicPrimitiveNode(wasmBinary.metadata.primitives[checkpoint.fidx_called].name, checkpoint.args!!)
299299
}
300300

301301
if (graph.currentNode.parent != null) {

src/main/kotlin/be/ugent/topl/mio/sourcemap/BinaryInfo.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ data class WasmInfo(
88
val after_choicepoints: Set<Int>,
99
val primitive_calls: Set<Int>,
1010
val after_primitive_calls: Set<Int>,
11-
val primitive_fidx_mapping: List<String>
11+
val primitives: List<WasmPrimitive>
12+
)
13+
14+
data class WasmPrimitive(
15+
val fidx: Int,
16+
val name: String,
17+
val module: String,
18+
val arg_types: List<String>,
19+
val return_types: List<String>
1220
)
1321
data class WasmBinary(val file: File, val metadata: WasmInfo)
1422

src/main/kotlin/be/ugent/topl/mio/ui/CheckpointVisualiser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ data class CheckpointNode(val t: Int, val binaryInfo: WasmInfo, val checkpoint:
137137
init {
138138
var str = "Checkpoint t = $t"
139139
if (checkpoint.fidx_called != null) {
140-
str += ", fidx = ${checkpoint.fidx_called}, ${binaryInfo.primitive_fidx_mapping[checkpoint.fidx_called]}(${checkpoint.args?.joinToString(",")})"
140+
str += ", fidx = ${checkpoint.fidx_called}, ${binaryInfo.primitives[checkpoint.fidx_called].name}(${checkpoint.args?.joinToString(",")})"
141141
}
142142
userObject = str
143143
}

src/main/kotlin/be/ugent/topl/mio/ui/InteractiveDebugger.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package be.ugent.topl.mio.ui
22

33
import WasmBinary
4+
import WasmPrimitive
45
import be.ugent.topl.mio.DebuggerConfig
56
import be.ugent.topl.mio.connections.Connection
67
import be.ugent.topl.mio.debugger.ConstraintParser
@@ -638,8 +639,10 @@ class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config
638639
val currentNode = multiverseDebugger.graph.currentNode
639640
val mainPanel = JPanel()
640641
val primitiveSelector = JComboBox<String>()
641-
multiverseDebugger.wasmBinary.metadata.primitive_fidx_mapping.forEach {
642-
primitiveSelector.addItem(it)
642+
multiverseDebugger.wasmBinary.metadata.primitives.forEach {
643+
if (it.return_types.isNotEmpty()) {
644+
primitiveSelector.addItem(it.name)
645+
}
643646
}
644647
mainPanel.add(primitiveSelector)
645648
mainPanel.add(JLabel("("))
@@ -649,11 +652,9 @@ class MultiversePanel(private val multiverseDebugger: MultiverseDebugger, config
649652
val argTextFields = mutableListOf<JTextField>()
650653
fun updateArgFields() {
651654
argTextFields.clear()
652-
// TODO: Determine the count based on binary info from WARDuino
653-
val argCount = if (
654-
primitiveSelector.selectedItem.toString() == "display_width" ||
655-
primitiveSelector.selectedItem.toString() == "display_height" ||
656-
primitiveSelector.selectedItem.toString() == "random_int") 0 else 1
655+
val argCount = multiverseDebugger.wasmBinary.metadata.primitives.find {
656+
it.name == primitiveSelector.selectedItem as String
657+
}!!.arg_types.size
657658
repeat(argCount) {
658659
argTextFields.add(JTextField())
659660
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ data class PrimitiveOverride(
131131
primitiveName: String,
132132
args: List<Int>,
133133
returnValue: Int
134-
) : this(metadata.primitive_fidx_mapping.indexOf(primitiveName), args, returnValue)
134+
) : this(metadata.primitives.find { it.name == primitiveName }!!.fidx, args, returnValue)
135135

136-
fun getPrimitiveName(metadata: WasmInfo): String = metadata.primitive_fidx_mapping[fidx]
136+
fun getPrimitiveName(metadata: WasmInfo): String = metadata.primitives[fidx].name
137137
}
138138

139139
data class WOODDumpResponse(

0 commit comments

Comments
 (0)