#disasm #vm #disassembly #swamp-vm-disasm

swamp-vm-disasm

disassembler for the opcodes in the swamp vm

14 releases

Uses new Rust 2024

new 0.1.16 Apr 7, 2025
0.1.15 Apr 1, 2025
0.1.13 Mar 30, 2025
0.0.14 Apr 1, 2025

#51 in Emulators

Download history 189/week @ 2025-03-15 295/week @ 2025-03-22 673/week @ 2025-03-29 241/week @ 2025-04-05

1,398 downloads per month
Used in 8 crates (6 directly)

MIT license

42KB
787 lines

Swamp VM Disassembler

Provides functions to translate Swamp Virtual Machine (VM) bytecode (BinaryInstruction from swamp-vm-types) into a human-readable, assembly-like textual representation. This is primarily useful for debugging the Swamp compiler backend or inspecting generated bytecode.

Overview

This crate takes the low-level, packed BinaryInstruction structs used by the Swamp VM and converts them into formatted strings that represent the instruction's opcode and operands in a more understandable way. It interprets the raw operand values based on the specific opcode, identifying them as frame memory addresses, constant addresses, immediate values, instruction pointers, etc.

Key Features

  • Human-Readable Output: Converts numeric opcodes and operands into mnemonic names and symbolic representations (e.g., $001A for frame address, @#00000005 for constant address).
  • Color Output: Offers functions (disasm_color, disasm_instructions_color) that use ANSI terminal colors (via the yansi crate) to visually distinguish different operand types (e.g., reads vs. writes, frame vs. constant, temporary vs. persistent frame variables).
  • Plain Text Output: Provides functions (disasm_no_color, disasm_instructions_no_color) for environments where color is not desired or supported.
  • Operand Interpretation: Correctly interprets operand values based on the instruction's opcode.
  • Contextual Information: Can incorporate comments and instruction pointer labels (ip_infos) into the output.
  • Temporary Variable Highlighting: Differentiates frame memory addresses that fall into the temporary region (based on the provided FrameMemorySize).

Installation

Add this to your Cargo.toml:

[dependencies]
swamp-vm-disasm = "0.1.16"

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/swamp/swamp

Dependencies

~110KB