How robalb/x86-64-playground works
This project is an innovative, client‐side x86-64 playground that allows users to write, test, and debug assembly code directly from their browsers. Essentially, it ties together a web-based user interface built with Svelte and Typescript and a heavily modified, WebAssembly port of the Blink x86-64-linux emulator. Its purpose is to provide an interactive, GDB-like debugging experience as well as an interface for testing assembly snippets in a fully-emulated Linux environment—all without relying on a traditional server backend.
Main Components
• Web UI / Frontend:
• Located in the “webapp” directory, this single-page application is built using Svelte and Typescript.
• It includes various components such as the Editor, Disassembler, Registers, Hexdump, Terminal, and several control menus (e.g., file menu, share dialog, theme/debug controls).
• Assets like CSS, configuration files (jsconfig.json, vite.config.js), and static resources (index.html, images, fonts) are also part of this layer.
• Emulator / WebAssembly Module:
• Found in the “blink” directory, this is the core x86-64 emulator source code written in C, which is compiled to WebAssembly.
• Integration files include build scripts, Makefiles, and the tool wrapper (in “blink/tool”) that transform the Blink emulator into a C library readily accessible from JavaScript.
• The Typescript wrapper (e.g., in webapp/src/core/blink.ts) exposes the emulator’s API to the web application.
• Build and Tooling Infrastructure:
• Various scripts (compile_blink.sh, compile_demo_programs.sh, etc.) and directories (“blink/tool”, “musl_binutils”) support building both the emulator (Blink) and auxiliary demo programs.
• The “docs” and “field_notes” directories, along with third-party subdirectories, provide design documentation, testing frameworks, and examples demonstrating how everything integrates.
• Demo Programs and Testing:
• The “demo_programs” directory includes sample assembly programs used to validate and showcase the functionality of the emulator.
Relationships & Interactions
• User Interaction:
• The user writes or uploads assembly code using the editor in the Web UI.
• From there, the snippet is sent to the integrated emulator via the Typescript API.
• Communication with the Emulator:
• The web application loads the Blink emulator as a WebAssembly module.
• A bridge (the “webapp/src/core” folder with files for managing app state, assembling input, and interfacing with blink.ts) handles the bi-directional communication between the UI and emulator.
• Data Flow:
• Code Input → Compiler/Assembler (via configured assemblers like GNU Binutils, Fasm, Nasm from webapp assets) → WebAssembly module (Blink emulator) → Execution results (registers, memory state, disassembled code) → Rendered on the UI components.
• Offline Deployment:
• Being a static, single-page application hosted on GitHub Pages, the entire product, including the emulator core, runs entirely in the client’s browser.
Architectural Patterns
• Single Page Application (SPA): The entire web front end operates as a static SPA.
• WebAssembly Integration: The Blink emulator is encapsulated as a WebAssembly module, exposing its API via a TS wrapper.
• Modular Design: Separation of concerns is evident from distinct directories for UI (webapp), emulator source (blink), build tooling, and third-party libraries.
• Build Pipelines: The presence of Makefiles, shell scripts, and configuration files hints at a multi-step custom build system that compiles C code into the WASM binary, bundles it, and integrates with the web UI.
Relevant Technologies & Frameworks
• Frontend: Svelte, Typescript, Vite (for building the webapp), along with CSS and standard JavaScript.
• Backend Emulation: C source code compiled using Makefiles and shell scripts, and then transformed into a WebAssembly module.
• Supporting Libraries and Tools: Blink itself (originally a separate x86-64 emulator), musl, various third-party projects (e.g., qemu assets, libz, sectorlisp, ltp tests) that support comprehensive testing and functionality.