#vm #embedding #disassembly

swamp-vm-disasm

disassembler for the opcodes in the swamp vm

10 releases

Uses new Rust 2024

new 0.1.13 Mar 30, 2025
0.1.12 Mar 30, 2025

#66 in Emulators

Download history 206/week @ 2025-03-16 367/week @ 2025-03-23

573 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.13"

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