🕸 On the Web with WebAssembly (original) (raw)

  1. Introduction
  2. 1. 📦 Install
  3. 2. 💡 Concepts
    1. 2.1. Call Graph
    2. 2.2. Paths
    3. 2.3. Dominators and Retained Size
    4. 2.4. Generic Functions and Monomorphization
  4. 3. 🏋️‍♀️ Usage
    1. 3.1. ⌨ Command Line Interface
      1. 3.1.1. twiggy top
        1. 3.1.2. twiggy paths
        2. 3.1.3. twiggy monos
        3. 3.1.4. twiggy dominators
        4. 3.1.5. twiggy diff
        5. 3.1.6. twiggy garbage
    2. 3.2. 🦀 As a Crate
    3. 3.3. 🕸 On the Web with WebAssembly
  5. 4. 🔎 Supported Binary Formats
  6. 5. 🙌 Contributing to Twiggy
    1. 5.1. Building
    2. 5.2. Testing
    3. 5.3. Code Formatting
    4. 5.4. Pull Requests
    5. 5.5. Team

Twiggy🌱

🕸 On the Web with WebAssembly

First, ensure you have the wasm32-unknown-unknown Rust target installed and up-to-date:

rustup target add wasm32-unknown-unknown

Next, install wasm-bindgen:

cargo install wasm-bindgen-cli

Finally, build twiggy's WebAssembly API with wasm-bindgen:

cd twiggy/wasm-api
cargo build --release --target wasm32-unknown-unknown
wasm-bindgen ../target/wasm32-unknown-unknown/release/twiggy_wasm_api.wasm --out-dir .

This should produce two artifacts in the current directory:

  1. twiggy_wasm_api_bg.wasm: The WebAssembly file containing twiggy.
  2. twiggy_wasm_api.js: The JavaScript bindings to twiggy's WebAssembly.

You can now use twiggy from JavaScript like this:

import { Items, Monos } from './twiggy_wasm_api';

// Parse a binary's data into a collection of items.
const items = Items.parse(myData);

// Configure an analysis and its options.
const opts = Monos.new();
opts.set_max_generics(10);
opts.set_max_monos(10);

// Run the analysis on the parsed items.
const monos = JSON.parse(items.monos(opts));