Skip to content

jonathanharg/binaryen.py

Repository files navigation

Binaryen.py

Binaryen.py is a python wrapper for Binaryen. Use this to create, optimise and interpret WebAssembly binaries in python.

Installation

First make sure Binaryen is installed and accessible from your path. For Linux/MacOS it's recommended to install it from your package manager or homebrew (on MacOS). Alternatively, download precompiled binaries of Binaryen.

Install through PyPI.

pip install binaryen.py

Test

pytest --doctest-modules --doctest-continue-on-failure

Format

black --extend-exclude binaryen/_binaryen_cffi.py .

Docs

mkdocs serve

Updating the Python header file

Get the latest binaryen header file and binaries.

Comment out #include <stdbool.h>, #include <stddef.h> and #include <stdint.h>

cpp -nostdinc -E -P binaryen-c.h | sed '/^\/\//d; s/##//g; s/;;/;/g;' | tr '\n' ' ' | sed '1s/^[[:space:]]*//; s/  */ /g;s/; /;\n/g;' | sed '/^__attribute__((deprecated))/d' | clang-format -style "{ColumnLimit: 0}" > binaryen-py.h

This cleans up the header file and removes deprecated code

Replace Union types with the largest type of that Union. E.g.

struct BinaryenLiteral
{
  uintptr_t type;
  union
  {
    int32_t i32;
    int64_t i64;
    float f32;
    double f64;
    uint8_t v128[16];
    const char *func;
  };
};

Becomes

struct BinaryenLiteral
{
  uintptr_t type;
  uint8_t v128[16];
};

Build the cffi interface by running python binaryen_build.py

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy