...
 
Commits (2)
......@@ -50,13 +50,15 @@ after_test:
artifacts:
- path: "%DEPLOY_NAME%"
name: wabt
- path: "%DEPLOY_NAME%.sha256"
name: sha256
deploy:
description: 'wabt release'
provider: GitHub
auth_token:
secure: lHQSdycL1FHsFKZZ0RSnYSUtRitYaLb4uxDjCSOpYHnk4gIO/0/DLu4aoU2VvD7Y
artifact: "%DEPLOY_NAME%"
artifact: wabt,sha256
on:
appveyor_repo_tag: true
deploy: true
......@@ -3,3 +3,5 @@
/fuzz-out
/emscripten
*.pyc
.idea/
/cmake-build-debug/
......@@ -26,6 +26,7 @@ option(USE_LSAN "Use leak sanitizer" OFF)
option(USE_UBSAN "Use undefined behavior sanitizer" OFF)
option(CODE_COVERAGE "Build with code coverage enabled" OFF)
option(WITH_EXCEPTIONS "Build with exceptions enabled" OFF)
option(WERROR "Build with warnings as errors" OFF)
if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
set(COMPILER_IS_CLANG 1)
......@@ -79,7 +80,11 @@ if (COMPILER_IS_MSVC)
# seems to not like float compare w/ HUGE_VALF; bug?
# disable warnings C4267 and C4244: conversion/truncation from larger to smaller type.
# disable warning C4800: implicit conversion from larger int to bool
add_definitions(-W3 -wd4018 -wd4056 -wd4756 -wd4267 -wd4244 -wd4800 -WX -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
add_definitions(-W3 -wd4018 -wd4056 -wd4756 -wd4267 -wd4244 -wd4800 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
if (WERROR)
add_definitions(-WX)
endif ()
if (NOT WITH_EXCEPTIONS)
# disable exception use in C++ library
......@@ -90,12 +95,16 @@ else ()
# interfaces, etc.
# disable -Wpointer-arith: this is a GCC extension, and doesn't work in MSVC.
add_definitions(
-Wall -Wextra -Werror -Wno-unused-parameter -Wpointer-arith -g
-Wall -Wextra -Wno-unused-parameter -Wpointer-arith -g
-Wuninitialized
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wold-style-cast")
if (WERROR)
add_definitions(-Werror)
endif ()
if (NOT WITH_EXCEPTIONS)
add_definitions(-fno-exceptions)
endif ()
......@@ -408,6 +417,7 @@ if (NOT EMSCRIPTEN)
# wabt-unittests
set(UNITTESTS_SRCS
src/test-binary-reader.cc
src/test-circular-array.cc
src/test-interp.cc
src/test-intrusive-list.cc
......@@ -423,22 +433,22 @@ if (NOT EMSCRIPTEN)
SOURCES ${UNITTESTS_SRCS}
LIBS libgtest ${CMAKE_THREAD_LIBS_INIT}
)
endif ()
if (NOT CMAKE_VERSION VERSION_LESS "3.2")
set(USES_TERMINAL USES_TERMINAL)
endif ()
if (NOT CMAKE_VERSION VERSION_LESS "3.2")
set(USES_TERMINAL USES_TERMINAL)
endif ()
# test running
find_package(PythonInterp 2.7 REQUIRED)
set(RUN_TESTS_PY ${WABT_SOURCE_DIR}/test/run-tests.py)
add_custom_target(run-tests
COMMAND ${CMAKE_BINARY_DIR}/wabt-unittests
COMMAND ${PYTHON_EXECUTABLE} ${RUN_TESTS_PY} --bindir ${CMAKE_BINARY_DIR}
DEPENDS ${WABT_EXECUTABLES}
WORKING_DIRECTORY ${WABT_SOURCE_DIR}
${USES_TERMINAL}
)
# test running
find_package(PythonInterp 2.7 REQUIRED)
set(RUN_TESTS_PY ${WABT_SOURCE_DIR}/test/run-tests.py)
add_custom_target(run-tests
COMMAND ${CMAKE_BINARY_DIR}/wabt-unittests
COMMAND ${PYTHON_EXECUTABLE} ${RUN_TESTS_PY} --bindir ${CMAKE_BINARY_DIR}
DEPENDS ${WABT_EXECUTABLES}
WORKING_DIRECTORY ${WABT_SOURCE_DIR}
${USES_TERMINAL}
)
endif ()
# install
if (BUILD_TOOLS OR BUILD_TESTS)
......
[![Build Status](https://travis-ci.org/WebAssembly/wabt.svg?branch=master)](https://travis-ci.org/WebAssembly/wabt) [![Windows status](https://ci.appveyor.com/api/projects/status/79hqj5l0qggw645d/branch/master?svg=true)](https://ci.appveyor.com/project/WebAssembly/wabt/branch/master)
[![Build Status](https://travis-ci.org/WebAssembly/wabt.svg?branch=master)](https://travis-ci.org/WebAssembly/wabt) [![Windows status](https://ci.appveyor.com/api/projects/status/8vl5jwtk5ch6r84t/branch/master?svg=true)](https://ci.appveyor.com/project/WebAssembly/wabt/branch/master)
# WABT: The WebAssembly Binary Toolkit
WABT (we pronounce it "wabbit") is a suite of tools for WebAssembly, including:
- **wat2wasm**: translate from [WebAssembly text format](https://webassembly.github.io/spec/core/text/index.html) to the [WebAssembly binary format](https://webassembly.github.io/spec/core/binary/index.html)
- **wasm2wat**: the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
- **wasm-objdump**: print information about a wasm binary. Similiar to objdump.
- **wasm-interp**: decode and run a WebAssembly binary file using a stack-based interpreter
- **wat-desugar**: parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
- **wasm2c**: convert a WebAssembly binary file to a C source and header
- [**wat2wasm**](https://webassembly.github.io/wabt/doc/wat2wasm.1.html): translate from [WebAssembly text format](https://webassembly.github.io/spec/core/text/index.html) to the [WebAssembly binary format](https://webassembly.github.io/spec/core/binary/index.html)
- [**wasm2wat**](https://webassembly.github.io/wabt/doc/wasm2wat.1.html): the inverse of wat2wasm, translate from the binary format back to the text format (also known as a .wat)
- [**wasm-objdump**](https://webassembly.github.io/wabt/doc/wasm-objdump.1.html): print information about a wasm binary. Similiar to objdump.
- [**wasm-interp**](https://webassembly.github.io/wabt/doc/wasm-interp.1.html): decode and run a WebAssembly binary file using a stack-based interpreter
- [**wat-desugar**](https://webassembly.github.io/wabt/doc/wat-desugar.1.html): parse .wat text form as supported by the spec interpreter (s-expressions, flat syntax, or mixed) and print "canonical" flat format
- [**wasm2c**](https://webassembly.github.io/wabt/doc/wasm2c.1.html): convert a WebAssembly binary file to a C source and header
- [**wasm-strip**](https://webassembly.github.io/wabt/doc/wasm-strip.1.html): remove sections of a WebAssembly binary file
- [**wasm-validate**](https://webassembly.github.io/wabt/doc/wasm-validate.1.html): validate a file in the WebAssembly binary format
- [**wast2json**](https://webassembly.github.io/wabt/doc/wast2json.1.html): convert a file in the wasm spec test format to a JSON file and associated wasm binary files
- [**wasm-opcodecnt**](https://webassembly.github.io/wabt/doc/wasm-opcodecnt.1.html): count opcode usage for instructions
- [**spectest-interp**](https://webassembly.github.io/wabt/doc/spectest-interp.1.html): read a Spectest JSON file, and run its tests in the interpreter
These tools are intended for use in (or for development of) toolchains or other
systems that want to manipulate WebAssembly files. Unlike the WebAssembly spec
......@@ -24,9 +29,9 @@ target; instead they aim for full fidelity and compliance with the spec (e.g.
Wabt has been compiled to JavaScript via emscripten. Some of the functionality is available in the following demos:
- [index](https://cdn.rawgit.com/WebAssembly/wabt/e0719fe0/demo/index.html)
- [wat2wasm](https://cdn.rawgit.com/WebAssembly/wabt/e0719fe0/demo/wat2wasm/)
- [wasm2wat](https://cdn.rawgit.com/WebAssembly/wabt/e0719fe0/demo/wasm2wat/)
- [index](https://webassembly.github.io/wabt/demo/)
- [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/)
- [wasm2wat](https://webassembly.github.io/wabt/demo/wasm2wat/)
## Cloning
......@@ -53,6 +58,10 @@ $ make
This will build the default version of the tools: a debug build using the Clang
compiler.
**NOTE**: Under the hood, this uses make to run CMake, which then calls make again.
On some systems, this doesn't build properly. If you see these errors, you can build
using CMake directly as described below.
There are many make targets available for other configurations as well. They
are generated from every combination of a compiler, build type and
configuration.
......@@ -71,6 +80,8 @@ $ make clang-debug-lsan
$ make gcc-debug-no-re2c
```
### Building using CMake directly
You can also run CMake yourself, the normal way:
```console
......@@ -155,7 +166,7 @@ You can use `--help` to get additional help:
$ out/wat2wasm --help
```
Or try the [online demo](https://cdn.rawgit.com/WebAssembly/wabt/e0719fe0/demo/wat2wasm/).
Or try the [online demo](https://webassembly.github.io/wabt/demo/wat2wasm/).
## Running wasm2wat
......@@ -175,7 +186,7 @@ You can use `--help` to get additional help:
$ out/wasm2wat --help
```
Or try the [online demo](https://cdn.rawgit.com/WebAssembly/wabt/e0719fe0/demo/wasm2wat/).
Or try the [online demo](https://webassembly.github.io/wabt/demo/wasm2wat/).
## Running wasm-interp
......
html {
font-size: 80%;
line-height: 1.3;
}
* {
box-sizing: border-box;
}
body {
font-family: sans-serif;
font-size: 1rem;
line-height: 1.3125rem;
margin: 0;
}
h1 {
font-size: 2.375rem;
line-height: 2.625rem;
margin-top: 1.3125rem;
margin-bottom: 1.3125rem;
}
h2 {
font-size: 1.75rem;
line-height: 2.625rem;
margin-top: 1.3125rem;
margin-bottom: 1.3125rem;
}
h3 {
font-size: 1.3125rem;
line-height: 1.3125rem;
margin-top: 1.3125rem;
margin-bottom: 0rem;
}
h4 {
font-size: 1rem;
line-height: 1.3125rem;
margin-top: 1.3125rem;
margin-bottom: 0rem;
}
h5 {
font-size: 1rem;
line-height: 1.3125rem;
margin-top: 1.3125rem;
margin-bottom: 0rem;
}
p, ul {
padding-left: 0;
margin-top: 0rem;
margin-bottom: 1.3125rem;
}
ul ul, ol ol, ul ol, ol ul {
margin-top: 0rem;
margin-bottom: 0rem;
}
pre {
margin: 0;
}
.right {
float: right;
white-space: nowrap;
}
.hidden {
display: none;
}
#split-grid {
position: absolute;
height: 100%;
left: 0;
right: 0;
top: 0;
}
.CodeMirror, .output {
position: absolute;
height: calc(100% - 2.625rem);
top: 2.625rem;
left: 0;
right: 0;
}
.output {
padding: 0.3125rem;
overflow: auto;
}
.toolbar {
position: absolute;
top: 0;
right: 0;
left: 0;
color: #555;
background-color: #eee;
z-index: 9;
height: 2.625rem;
line-height: 2rem;
padding: 0.3125rem 0.3125rem 0;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
}
.split-horizontal, .gutter-horizontal {
height: 100%;
float: left;
}
.gutter-horizontal {
cursor: ew-resize;
background-image: url('third_party/split/vertical.png');
}
.gutter-vertical {
cursor: ns-resize;
background-image: url('third_party/split/horizontal.png');
}
.gutter {
touch-action: none;
user-select: none;
background-color: #ddd;
background-repeat: no-repeat;
background-position: 50%;
z-index: 0;
}
.split {
position: relative;
overflow: hidden;
}
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1;
position: relative;
}
header {
padding: 0 1em;
z-index: 10;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);
}
ul {
margin: 1em;
list-style: none;
}
<!--
Copyright 2017 WebAssembly Community Group participants
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>wabt demos</title>
<link href="custom.css" rel="stylesheet">
</head>
<body>
<header>
<h1>wabt demos</h1>
</header>
<main>
<ul>
<li>
<a href="wat2wasm/index.html">wat2wasm demo</a>
<p>
Example showing converting text to binary.
</p>
</li>
<li>
<a href="wasm2wat/index.html">wasm2wat demo</a>
<p>
Example showing converting binary to text.
</p>
</li>
</ul>
</main>
</body>
</html>
This diff was suppressed by a .gitattributes entry.
MIT License
Copyright (C) 2017 by Marijn Haverbeke <marijnh@gmail.com> and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff is collapsed.
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineSimpleMode = function(name, states) {
CodeMirror.defineMode(name, function(config) {
return CodeMirror.simpleMode(config, states);
});
};
CodeMirror.simpleMode = function(config, states) {
ensureState(states, "start");
var states_ = {}, meta = states.meta || {}, hasIndentation = false;
for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
var list = states_[state] = [], orig = states[state];
for (var i = 0; i < orig.length; i++) {
var data = orig[i];
list.push(new Rule(data, states));
if (data.indent || data.dedent) hasIndentation = true;
}
}
var mode = {
startState: function() {
return {state: "start", pending: null,
local: null, localState: null,
indent: hasIndentation ? [] : null};
},
copyState: function(state) {
var s = {state: state.state, pending: state.pending,
local: state.local, localState: null,
indent: state.indent && state.indent.slice(0)};
if (state.localState)
s.localState = CodeMirror.copyState(state.local.mode, state.localState);
if (state.stack)
s.stack = state.stack.slice(0);
for (var pers = state.persistentStates; pers; pers = pers.next)
s.persistentStates = {mode: pers.mode,
spec: pers.spec,
state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state),
next: s.persistentStates};
return s;
},
token: tokenFunction(states_, config),
innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; },
indent: indentFunction(states_, meta)
};
if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop))
mode[prop] = meta[prop];
return mode;
};
function ensureState(states, name) {
if (!states.hasOwnProperty(name))
throw new Error("Undefined state " + name + " in simple mode");
}
function toRegex(val, caret) {
if (!val) return /(?:)/;
var flags = "";
if (val instanceof RegExp) {
if (val.ignoreCase) flags = "i";
val = val.source;
} else {
val = String(val);
}
return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
}
function asToken(val) {
if (!val) return null;
if (typeof val == "string") return val.replace(/\./g, " ");
var result = [];
for (var i = 0; i < val.length; i++)
result.push(val[i] && val[i].replace(/\./g, " "));
return result;
}
function Rule(data, states) {
if (data.next || data.push) ensureState(states, data.next || data.push);
this.regex = toRegex(data.regex);
this.token = asToken(data.token);
this.data = data;
}
function tokenFunction(states, config) {
return function(stream, state) {
if (state.pending) {
var pend = state.pending.shift();
if (state.pending.length == 0) state.pending = null;
stream.pos += pend.text.length;
return pend.token;
}
if (state.local) {
if (state.local.end && stream.match(state.local.end)) {
var tok = state.local.endToken || null;
state.local = state.localState = null;
return tok;
} else {
var tok = state.local.mode.token(stream, state.localState), m;
if (state.local.endScan && (m = state.local.endScan.exec(stream.current())))
stream.pos = stream.start + m.index;
return tok;
}
}
var curState = states[state.state];
for (var i = 0; i < curState.length; i++) {
var rule = curState[i];
var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex);
if (matches) {
if (rule.data.next) {
state.state = rule.data.next;
} else if (rule.data.push) {
(state.stack || (state.stack = [])).push(state.state);
state.state = rule.data.push;
} else if (rule.data.pop && state.stack && state.stack.length) {
state.state = state.stack.pop();
}
if (rule.data.mode)
enterLocalMode(config, state, rule.data.mode, rule.token);
if (rule.data.indent)
state.indent.push(stream.indentation() + config.indentUnit);
if (rule.data.dedent)
state.indent.pop();
if (matches.length > 2) {
state.pending = [];
for (var j = 2; j < matches.length; j++)
if (matches[j])
state.pending.push({text: matches[j], token: rule.token[j - 1]});
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
return rule.token[0];
} else if (rule.token && rule.token.join) {
return rule.token[0];
} else {
return rule.token;
}
}
}
stream.next();
return null;
};
}
function cmp(a, b) {
if (a === b) return true;
if (!a || typeof a != "object" || !b || typeof b != "object") return false;
var props = 0;
for (var prop in a) if (a.hasOwnProperty(prop)) {
if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false;
props++;
}
for (var prop in b) if (b.hasOwnProperty(prop)) props--;
return props == 0;
}
function enterLocalMode(config, state, spec, token) {
var pers;
if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next)
if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p;
var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec);
var lState = pers ? pers.state : CodeMirror.startState(mode);
if (spec.persistent && !pers)
state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates};
state.localState = lState;
state.local = {mode: mode,
end: spec.end && toRegex(spec.end),
endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false),
endToken: token && token.join ? token[token.length - 1] : token};
}
function indexOf(val, arr) {
for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true;
}
function indentFunction(states, meta) {
return function(state, textAfter, line) {
if (state.local && state.local.mode.indent)
return state.local.mode.indent(state.localState, textAfter, line);
if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1)
return CodeMirror.Pass;
var pos = state.indent.length - 1, rules = states[state.state];
scan: for (;;) {
for (var i = 0; i < rules.length; i++) {
var rule = rules[i];
if (rule.data.dedent && rule.data.dedentIfLineStart !== false) {
var m = rule.regex.exec(textAfter);
if (m && m[0]) {
pos--;
if (rule.next || rule.push) rules = states[rule.next || rule.push];
textAfter = textAfter.slice(m[0].length);
continue scan;
}
}
}
break;
}
return pos < 0 ? 0 : state.indent[pos];
};
}
});
/*! Split.js - v1.3.5
* Copyright (c) 2017 Nathan Cahill
* MIT https://github.com/nathancahill/Split.js/blob/master/LICENSE.txt
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Split=t()}(this,function(){"use strict";var e=window,t=e.document,n="addEventListener",i="removeEventListener",r="getBoundingClientRect",s=function(){return!1},o=e.attachEvent&&!e[n],a=["","-webkit-","-moz-","-o-"].filter(function(e){var n=t.createElement("div");return n.style.cssText="width:"+e+"calc(9px)",!!n.style.length}).shift()+"calc",l=function(e){return"string"==typeof e||e instanceof String?t.querySelector(e):e};return function(u,c){function z(e,t,n){var i=A(y,t,n);Object.keys(i).forEach(function(t){return e.style[t]=i[t]})}function h(e,t){var n=B(y,t);Object.keys(n).forEach(function(t){return e.style[t]=n[t]})}function f(e){var t=E[this.a],n=E[this.b],i=t.size+n.size;t.size=e/this.size*i,n.size=i-e/this.size*i,z(t.element,t.size,this.aGutterSize),z(n.element,n.size,this.bGutterSize)}function m(e){var t;this.dragging&&((t="touches"in e?e.touches[0][b]-this.start:e[b]-this.start)<=E[this.a].minSize+M+this.aGutterSize?t=E[this.a].minSize+this.aGutterSize:t>=this.size-(E[this.b].minSize+M+this.bGutterSize)&&(t=this.size-(E[this.b].minSize+this.bGutterSize)),f.call(this,t),c.onDrag&&c.onDrag())}function g(){var e=E[this.a].element,t=E[this.b].element;this.size=e[r]()[y]+t[r]()[y]+this.aGutterSize+this.bGutterSize,this.start=e[r]()[G]}function d(){var t=this,n=E[t.a].element,r=E[t.b].element;t.dragging&&c.onDragEnd&&c.onDragEnd(),t.dragging=!1,e[i]("mouseup",t.stop),e[i]("touchend",t.stop),e[i]("touchcancel",t.stop),t.parent[i]("mousemove",t.move),t.parent[i]("touchmove",t.move),delete t.stop,delete t.move,n[i]("selectstart",s),n[i]("dragstart",s),r[i]("selectstart",s),r[i]("dragstart",s),n.style.userSelect="",n.style.webkitUserSelect="",n.style.MozUserSelect="",n.style.pointerEvents="",r.style.userSelect="",r.style.webkitUserSelect="",r.style.MozUserSelect="",r.style.pointerEvents="",t.gutter.style.cursor="",t.parent.style.cursor=""}function S(t){var i=this,r=E[i.a].element,o=E[i.b].element;!i.dragging&&c.onDragStart&&c.onDragStart(),t.preventDefault(),i.dragging=!0,i.move=m.bind(i),i.stop=d.bind(i),e[n]("mouseup",i.stop),e[n]("touchend",i.stop),e[n]("touchcancel",i.stop),i.parent[n]("mousemove",i.move),i.parent[n]("touchmove",i.move),r[n]("selectstart",s),r[n]("dragstart",s),o[n]("selectstart",s),o[n]("dragstart",s),r.style.userSelect="none",r.style.webkitUserSelect="none",r.style.MozUserSelect="none",r.style.pointerEvents="none",o.style.userSelect="none",o.style.webkitUserSelect="none",o.style.MozUserSelect="none",o.style.pointerEvents="none",i.gutter.style.cursor=j,i.parent.style.cursor=j,g.call(i)}function v(e){e.forEach(function(t,n){if(n>0){var i=F[n-1],r=E[i.a],s=E[i.b];r.size=e[n-1],s.size=t,z(r.element,r.size,i.aGutterSize),z(s.element,s.size,i.bGutterSize)}})}function p(){F.forEach(function(e){e.parent.removeChild(e.gutter),E[e.a].element.style[y]="",E[e.b].element.style[y]=""})}void 0===c&&(c={});var y,b,G,E,w=l(u[0]).parentNode,D=e.getComputedStyle(w).flexDirection,U=c.sizes||u.map(function(){return 100/u.length}),k=void 0!==c.minSize?c.minSize:100,x=Array.isArray(k)?k:u.map(function(){return k}),L=void 0!==c.gutterSize?c.gutterSize:10,M=void 0!==c.snapOffset?c.snapOffset:30,O=c.direction||"horizontal",j=c.cursor||("horizontal"===O?"ew-resize":"ns-resize"),C=c.gutter||function(e,n){var i=t.createElement("div");return i.className="gutter gutter-"+n,i},A=c.elementStyle||function(e,t,n){var i={};return"string"==typeof t||t instanceof String?i[e]=t:i[e]=o?t+"%":a+"("+t+"% - "+n+"px)",i},B=c.gutterStyle||function(e,t){return n={},n[e]=t+"px",n;var n};"horizontal"===O?(y="width","clientWidth",b="clientX",G="left","paddingLeft"):"vertical"===O&&(y="height","clientHeight",b="clientY",G="top","paddingTop");var F=[];return E=u.map(function(e,t){var i,s={element:l(e),size:U[t],minSize:x[t]};if(t>0&&(i={a:t-1,b:t,dragging:!1,isFirst:1===t,isLast:t===u.length-1,direction:O,parent:w},i.aGutterSize=L,i.bGutterSize=L,i.isFirst&&(i.aGutterSize=L/2),i.isLast&&(i.bGutterSize=L/2),"row-reverse"===D||"column-reverse"===D)){var a=i.a;i.a=i.b,i.b=a}if(!o&&t>0){var c=C(t,O);h(c,L),c[n]("mousedown",S.bind(i)),c[n]("touchstart",S.bind(i)),w.insertBefore(c,s.element),i.gutter=c}0===t||t===u.length-1?z(s.element,s.size,L/2):z(s.element,s.size,L);var f=s.element[r]()[y];return f<s.minSize&&(s.minSize=f),t>0&&F.push(i),s}),o?{setSizes:v,destroy:p}:{setSizes:v,getSizes:function(){return E.map(function(e){return e.size})},collapse:function(e){if(e===F.length){var t=F[e-1];g.call(t),o||f.call(t,t.size-t.bGutterSize)}else{var n=F[e];g.call(n),o||f.call(n,n.aGutterSize)}},destroy:p}}});
/*
* Copyright 2017 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var editorEl = document.querySelector('.editor');
var uploadEl = document.getElementById('upload');
var selectEl = document.getElementById('select');
var uploadInputEl = document.getElementById('uploadInput');
var generateNamesEl = document.getElementById('generateNames');
var foldExprsEl = document.getElementById('foldExprs');
var inlineExportEl = document.getElementById('inlineExport');
var readDebugNamesEl = document.getElementById('readDebugNames');
var options = {mode: 'wast', lineNumbers: true};
var editor = CodeMirror.fromTextArea(editorEl, options);
var fileBuffer = null;
function compile(contents) {
if (!contents) {
return;
}
var readDebugNames = readDebugNamesEl.checked;
var generateNames = generateNamesEl.checked;
var foldExprs = foldExprsEl.checked;
var inlineExport = inlineExportEl.checked;
WabtModule().then(function(wabt) {
try {
var module = wabt.readWasm(contents, {readDebugNames: readDebugNames});
if (generateNames) {
module.generateNames();
module.applyNames();
}
var result =
module.toText({foldExprs: foldExprs, inlineExport: inlineExport});
editor.setValue(result);
} catch (e) {
editor.setValue(e.toString());
} finally {
if (module) module.destroy();
}
});
}
function onUploadClicked(e) {
uploadInput.value = '';
// See https://developer.mozilla.com/en-US/docs/Web/API/MouseEvent
var event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
uploadInput.dispatchEvent(event);
}
function onUploadedFile(e) {
var file = e.target.files[0];
var reader = new FileReader();
reader.onload = function(e) {
fileBuffer = new Uint8Array(e.target.result);
compile(fileBuffer);
};
reader.readAsArrayBuffer(file);
}
function recompileIfChanged(el) {
el.addEventListener('change', function() { compile(fileBuffer); });
}
function setExample(index) {
var contents = examples[index].contents;
fileBuffer = contents;
compile(contents);
}
function onSelectChanged(e) {
setExample(this.selectedIndex);
}
uploadEl.addEventListener('click', onUploadClicked);
uploadInputEl.addEventListener('change', onUploadedFile);
recompileIfChanged(generateNamesEl);
recompileIfChanged(foldExprsEl);
recompileIfChanged(inlineExportEl);
recompileIfChanged(readDebugNamesEl);
selectEl.addEventListener('change', onSelectChanged);
for (var i = 0; i < examples.length; ++i) {
var example = examples[i];
var option = document.createElement('option');
option.textContent = example.name;
selectEl.appendChild(option);
}
selectEl.selectedIndex = 0;
setExample(selectEl.selectedIndex);
/*
* Copyright 2017 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var examples = [
{
name: 'simple',
contents: new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 7, 1, 96, 2, 127, 127,
1, 127, 3, 2, 1, 0, 7, 10, 1, 6, 97, 100, 100, 84, 119,
111, 0, 0, 10, 9, 1, 7, 0, 32, 0, 32, 1, 106, 11, 0,
25, 4, 110, 97, 109, 101, 1, 9, 1, 0, 6, 97, 100, 100, 84,
119, 111, 2, 7, 1, 0, 2, 0, 0, 1, 0
]),
},
{
name: 'factorial',
contents: new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 6, 1, 96, 1, 126, 1, 126,
3, 2, 1, 0, 7, 7, 1, 3, 102, 97, 99, 0, 0, 10, 25, 1,
23, 0, 32, 0, 66, 1, 83, 4, 126, 66, 1, 5, 32, 0, 32, 0,
66, 1, 125, 16, 0, 126, 11, 11, 0, 20, 4, 110, 97, 109, 101, 1,
6, 1, 0, 3, 102, 97, 99, 2, 5, 1, 0, 1, 0, 0
]),
},
{
name: 'stuff',
contents: new Uint8Array([
0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 3, 96, 1, 125,
0, 96, 1, 127, 1, 127, 96, 0, 0, 2, 11, 1, 3, 102,
111, 111, 3, 98, 97, 114, 0, 0, 3, 3, 2, 2, 0, 4,
5, 1, 112, 1, 0, 1, 5, 4, 1, 1, 1, 1, 7, 9,
1, 5, 102, 117, 110, 99, 49, 0, 1, 8, 1, 1, 10, 10,
2, 2, 0, 11, 5, 0, 65, 42, 26, 11, 11, 8, 1, 0,
65, 0, 11, 2, 104, 105, 0, 44, 4, 110, 97, 109, 101, 1,
24, 3, 0, 7, 105, 109, 112, 111, 114, 116, 48, 1, 5, 102,
117, 110, 99, 48, 2, 5, 102, 117, 110, 99, 49, 2, 11, 3,
0, 1, 0, 0, 1, 0, 2, 1, 0, 0
]),
},
];
<!--
Copyright 2017 WebAssembly Community Group participants
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>wasm2wat demo</title>
<link href="../third_party/codemirror/codemirror.css" rel="stylesheet">
<link href="../custom.css" rel="stylesheet">
</head>
<body>
<header>
<h1>wasm2wat demo</h1>
<p>WebAssembly has a
<a href="http://webassembly.github.io/spec/text/index.html">text format</a>
and a
<a href="http://webassembly.github.io/spec/binary/index.html">binary format</a>.
This demo converts from the binary format to the text format.
</p>
<p>
Upload a WebAssembly binary file, and the text format will be displayed.
</p>
<div>
<p>
</p>
</div>
</header>
<main>
<div class="toolbar">
<input type="checkbox" id="generateNames" checked>
<label for="generateNames">Generate Names</label>
<input type="checkbox" id="foldExprs" checked>
<label for="foldExprs">Fold Expressions</label>
<input type="checkbox" id="inlineExport" checked>
<label for="inlineExport">Inline Export</label>
<input type="checkbox" id="readDebugNames" checked>
<label for="readDebugNames">Read Debug Names</label>
<div class="right">
<input type="file" id="uploadInput" class="hidden"></a>
<label>example:</label>
<select id="select" class="form-select"></select>
<button class="btn" type="button" id="upload">Upload</button>
</div>
</div>
<textarea class="editor" autofocus autocomplete="off" autocorrect="off"
autocapitalize="off" spellcheck="false" hidden></textarea>
</main>
<script src="../third_party/codemirror/codemirror.js"></script>
<script src="../third_party/codemirror/simple-mode.js"></script>
<script src="../wast-mode.js"></script>
<script src="../libwabt.js"></script>
<script src="examples.js"></script>
<script src="demo.js"></script>
</body>
</html>
/*
* Copyright 2017 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var mode = CodeMirror.defineSimpleMode('wast', {
start: [
{regex: /[+\-]?(?:nan(?::0x[0-9a-fA-F]+)?|infinity|inf|0x[0-9a-fA-F]+\.?[0-9a-fA-F]*p[+\/-]?\d+|\d+(?:\.\d*)?[eE][+\-]?\d*|\d+\.\d*|0x[0-9a-fA-F]+|\d+)/, token: "number"},
{regex: /anyfunc|mut|nop|block|if|then|else|loop|br|br_if|br_table|call|call_indirect|drop|end|return|get_local|set_local|tee_local|get_global|set_global|i32\.load|i64\.load|f32\.load|f64\.load|i32\.store|i64\.store|f32\.store|f64\.store|i32\.load8_s|i64\.load8_s|i32\.load8_u|i64\.load8_u|i32\.load16_s|i64\.load16_s|i32\.load16_u|i64\.load16_u|i64\.load32_s|i64\.load32_u|i32\.store8|i64\.store8|i32\.store16|i64\.store16|i32\.const|i64\.const|f32\.const|f64\.const|i32\.eqz|i64\.eqz|i32\.clz|i64\.clz|i32\.ctz|i64\.ctz|i32\.popcnt|i64\.popcnt|f32\.neg|f64\.neg|f32\.abs|f64\.abs|f32\.sqrt|f64\.sqrt|f32\.ceil|f64\.ceil|f32\.floor|f64\.floor|f32\.trunc|f64\.trunc|f32\.nearest|f64\.nearest|i32\.add|i64\.add|i32\.sub|i64\.sub|i32\.mul|i64\.mul|i32\.div_s|i64\.div_s|i32\.div_u|i64\.div_u|i32\.rem_s|i64\.rem_s|i32\.rem_u|i64\.rem_u|i32\.and|i64\.and|i32\.or|i64\.or|i32\.xor|i64\.xor|i32\.shl|i64\.shl|i32\.shr_s|i64\.shr_s|i32\.shr_u|i64\.shr_u|i32\.rotl|i64\.rotl|i32\.rotr|i64\.rotr|f32\.add|f64\.add|f32\.sub|f64\.sub|f32\.mul|f64\.mul|f32\.div|f64\.div|f32\.min|f64\.min|f32\.max|f64\.max|f32\.copysign|f64\.copysign|i32\.eq|i64\.eq|i32\.ne|i64\.ne|i32\.lt_s|i64\.lt_s|i32\.lt_u|i64\.lt_u|i32\.le_s|i64\.le_s|i32\.le_u|i64\.le_u|i32\.gt_s|i64\.gt_s|i32\.gt_u|i64\.gt_u|i32\.ge_s|i64\.ge_s|i32\.ge_u|i64\.ge_u|f32\.eq|f64\.eq|f32\.ne|f64\.ne|f32\.lt|f64\.lt|f32\.le|f64\.le|f32\.gt|f64\.gt|f32\.ge|f64\.ge|i64\.extend_s\/i32|i64\.extend_u\/i32|i32\.wrap\/i64|i32\.trunc_s\/f32|i64\.trunc_s\/f32|i32\.trunc_s\/f64|i64\.trunc_s\/f64|i32\.trunc_u\/f32|i64\.trunc_u\/f32|i32\.trunc_u\/f64|i64\.trunc_u\/f64|f32\.convert_s\/i32|f64\.convert_s\/i32|f32\.convert_s\/i64|f64\.convert_s\/i64|f32\.convert_u\/i32|f64\.convert_u\/i32|f32\.convert_u\/i64|f64\.convert_u\/i64|f64\.promote\/f32|f32\.demote\/f64|f32\.reinterpret\/i32|i32\.reinterpret\/f32|f64\.reinterpret\/i64|i64\.reinterpret\/f64|select|unreachable|current_memory|memory.size|grow_memory|memory.grow|type|func|param|result|local|global|module|table|memory|start|elem|data|offset|import|export|i32|i64|f32|f64/, token: "keyword"},
{regex: /\$([a-zA-Z0-9_`\+\-\*\/\\\^~=<>!\?@#$%&|:\.]+)/, token: "variable-2"},
{regex: /"(?:[^"\\\x00-\x1f\x7f]|\\[nt\\'"]|\\[0-9a-fA-F][0-9a-fA-F])*"/, token: "string"},
{regex: /\(;.*?/, token: "comment", next: "comment"},
{regex: /;;.*$/, token: "comment"},
{regex: /\(/, indent: true},
{regex: /\)/, dedent: true},
],
comment: [
{regex: /.*?;\)/, token: "comment", next: "start"},
{regex: /.*/, token: "comment"},
],
meta: {
dontIndentStates: ['comment'],
},
});
/*
* Copyright 2016 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Split(["#top-left", "#top-right"]);
Split(["#bottom-left", "#bottom-right"]);
Split(["#top-row", "#bottom-row"], {
direction: 'vertical'
});
var features = {};
WabtModule().then(function(wabt) {
var FEATURES = [
'exceptions',
'mutable_globals',
'sat_float_to_int',
'sign_extension',
'simd',
'threads',
'multi_value',
'tail_call',
];
var kCompileMinMS = 100;
var outputEl = document.getElementById('output');
var jsLogEl = document.getElementById('js_log');
var selectEl = document.getElementById('select');
var downloadEl = document.getElementById('download');
var downloadLink = document.getElementById('downloadLink');
var binaryBuffer = null;
var binaryBlobUrl = null;
for (var feature of FEATURES) {
var featureEl = document.getElementById(feature);
features[feature] = featureEl.checked;
featureEl.addEventListener('change', event => {
var feature = event.target.id;
features[feature] = event.target.checked;
onWatChange();
});
}
var wasmInstance = null;
var wrappedConsole = Object.create(console);
wrappedConsole.log = (...args) => {
let line = args.map(String).join('') + '\n';
jsLogEl.textContent += line;
console.log(...args);
}
var watEditor = CodeMirror((elt) => {
document.getElementById('top-left').appendChild(elt);
}, {
mode: 'wast',
lineNumbers: true,
});
var jsEditor = CodeMirror((elt) => {
document.getElementById('bottom-left').appendChild(elt);
}, {
mode: 'javascript',
lineNumbers: true,
});
function debounce(f, wait) {
var lastTime = 0;
var timeoutId = -1;
var wrapped = function() {
var time = +new Date();
if (time - lastTime < wait) {
if (timeoutId == -1)
timeoutId = setTimeout(wrapped, (lastTime + wait) - time);
return;
}
if (timeoutId != -1)
clearTimeout(timeoutId);
timeoutId = -1;
lastTime = time;
f.apply(null, arguments);
};
return wrapped;
}
function compile() {
outputEl.textContent = '';
var binaryOutput;
try {
var module = wabt.parseWat('test.wast', watEditor.getValue(), features);
module.resolveNames();
module.validate(features);
var binaryOutput = module.toBinary({log: true, write_debug_names:true});
outputEl.textContent = binaryOutput.log;
binaryBuffer = binaryOutput.buffer;
var blob = new Blob([binaryOutput.buffer]);
if (binaryBlobUrl) {
URL.revokeObjectURL(binaryBlobUrl);
}
binaryBlobUrl = URL.createObjectURL(blob);
downloadLink.setAttribute('href', binaryBlobUrl);
downloadEl.classList.remove('disabled');
} catch (e) {
outputEl.textContent += e.toString();
downloadEl.classList.add('disabled');
} finally {
if (module) module.destroy();
}
}
function run() {
jsLogEl.textContent = '';
if (binaryBuffer === null) return;
try {
let wasm = new WebAssembly.Module(binaryBuffer);
let js = jsEditor.getValue();
let fn = new Function('wasmModule', 'console', js + '//# sourceURL=demo.js');
fn(wasm, wrappedConsole);
} catch (e) {
jsLogEl.textContent += String(e);
}
}
var onWatChange = debounce(compile, kCompileMinMS);
var onJsChange = debounce(run, kCompileMinMS);
function setExample(index) {
var example = examples[index];
watEditor.setValue(example.contents);
onWatChange();
jsEditor.setValue(example.js);
onJsChange();
}
function onSelectChanged(e) {
setExample(this.selectedIndex);
}
function onDownloadClicked(e) {
// See https://developer.mozilla.com/en-US/docs/Web/API/MouseEvent
var event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
});
downloadLink.dispatchEvent(event);
}
watEditor.on('change', onWatChange);
jsEditor.on('change', onJsChange);
selectEl.addEventListener('change', onSelectChanged);
downloadEl.addEventListener('click', onDownloadClicked);
for (var i = 0; i < examples.length; ++i) {
var example = examples[i];
var option = document.createElement('option');
option.textContent = example.name;
selectEl.appendChild(option);
}
selectEl.selectedIndex = 1;
setExample(selectEl.selectedIndex);
});
/*
* Copyright 2016 WebAssembly Community Group participants
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var examples = [
{
name: 'empty',
contents: '(module)',
js: '',
},