Giter VIP home page Giter VIP logo

z3-wasm's Introduction

Z3 WASM

This library is superceded by the official WebAssembly/TypeScript/Javascript bindings of Z3, see https://github.com/Z3Prover/z3/tree/master/src/api/js

Original README

This repository contains scripts that makes interaction with the Z3 solver from a browser using WASM easier.

  • build.sh contains commands to fetch and compile Z3 using emscripten.
  • api/ contains a C API which exposes the Z3 API to Javascript, and the api.js file contains some glue code that enables easier interaction with the C API.
  • example/ contains an example of how to use the api.c module using a dynamically linked native version of the Z3 library, this cannot be used from the browser.
  • index.html contains an example on how to load and use the Z3 Javascript glue code.

Both the location of the Z3 repository and the Z3 version can be controlled using environment variables. Z3_BASE_DIR controls the location of the cloned Z3 repository, while Z3_VERSION alters the version that is fetched from Github.

Binding Generator

The bindgen directory contains some Python scripts to automate generating Javascript bindings for the Z3 C Api.

Currently, all functions declared in z3/src/api/z3.h of the original Z3 source are used for the Javascript bindings, all Z3_* types are treated as opaque pointers (i.e., just numbers from Javascript's point of view) except for Z3_string which is treated as a string.

As of yet, the bindings remain untested, so it might be possible that an incorrect type is assigned to a particular parameter which might lead to undefined behaviour.

Related repositories

Clément Pit-Claudel has performed similar steps as I have taken here. However, its scripts are meant to be used on Ubuntu or Debian derivates, and do not work nicely on other distributions of Linux. Furthermore, its Z3 version is outdated, and numerous users have reported either compilation issues or issues while using the library.

z3-wasm's People

Contributors

bramvdbogaerde avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

z3-wasm's Issues

Avoid using -pthread

We are currently compiling Z3 to WebAssembly using the -pthread option, the reason for this is because Z3 seems to be using some Z3 functionality.

Emscripten supports pthreads, but needs a SharedArrayBuffer which is only available on pages that have specific COP headers set [1].

This somewhat limits the hosting possibilities (although they can be mitigated using service workers [2]).

Using the Z3 supported --single-threaded option does not seem to resolve the issue.

The proposal of this issue is to investigate the origins of the pthread dependency, and remove it from Z3 (either by doing some automated patch work, or by contributing a fix to the official Z3 repository).

[1] https://emscripten.org/docs/porting/pthreads.html
[2] https://github.com/gzuidhof/coi-serviceworker

Uncaught exception when running solve with non-trivial examples

When using non-trivial SMTlib code, the WASM module throws an exception.

Example program

(declare-const x Int)
(assert (= x 5))
(check-sat)

The exception is generated from the compiled C++ code, and must be viewed by following the memory addresses that are intercepted by the Emscripten runtime.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.