pkg:wasm moved to GitHub

Remove code from SDK

See https://github.com/dart-lang/wasm

Change-Id: Ie5a68216f67605b20b8288793de752bac1f1b396
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202542
Auto-Submit: Kevin Moore <kevmoo@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
This commit is contained in:
Kevin Moore 2021-06-04 22:35:17 +00:00 committed by commit-bot@chromium.org
parent 75c9f63da0
commit 063d0ef286
43 changed files with 0 additions and 4487 deletions

View file

@ -769,12 +769,6 @@
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "wasm",
"rootUri": "../pkg/wasm",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "watcher",
"rootUri": "../third_party/pkg/watcher",

View file

@ -116,7 +116,6 @@ vector_math:third_party/pkg/vector_math/lib
vm:pkg/vm/lib
vm_service:pkg/vm_service/lib
vm_snapshot_analysis:pkg/vm_snapshot_analysis/lib
wasm:pkg/wasm/lib
watcher:third_party/pkg/watcher/lib
webdriver:third_party/pkg/webdriver/lib
webkit_inspection_protocol:third_party/pkg/webkit_inspection_protocol/lib

3
pkg/wasm/.gitignore vendored
View file

@ -1,3 +0,0 @@
.dart_tool/
.packages
pubspec.lock

View file

@ -1,6 +0,0 @@
# Below is a list of people and organizations that have contributed
# to the Dart project. Names should be added to the list like so:
#
# Name/Organization <email address>
Google LLC

View file

@ -1,27 +0,0 @@
Copyright 2020, the Dart project authors.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,48 +0,0 @@
Provides utilities for loading and running WASM modules
Built on top of the [Wasmer](https://github.com/wasmerio/wasmer) runtime.
## Setup
Run `dart run wasm:setup` to build the Wasmer runtime.
## Basic Usage
As a simple example, we'll try to call the following C function from Dart using
`package:wasm`. For a more detailed example that uses WASI, check out the
example directory.
```c++
extern "C" int square(int n) { return n * n; }
```
We can compile this C++ code to WASM using a recent version of clang:
```bash
clang --target=wasm32 -nostdlib -Wl,--export-all -Wl,--no-entry -o square.wasm square.cc
```
Then we can load and run it like this:
```dart
import 'dart:io';
import 'package:wasm/wasm.dart';
void main() {
final data = File('square.wasm').readAsBytesSync();
final mod = WasmModule(data);
print(mod.describe());
final inst = mod.instantiate().build();
final square = inst.lookupFunction('square');
print(square(12));
}
```
This should print:
```
export memory: memory
export function: int32 square(int32)
144
```

View file

@ -1,70 +0,0 @@
include: package:lints/recommended.yaml
analyzer:
strong-mode:
implicit-casts: false
linter:
rules:
- avoid_catching_errors
#- avoid_dynamic_calls
- avoid_function_literals_in_foreach_calls
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_renaming_method_parameters
- avoid_returning_null_for_void
- avoid_returning_this
- avoid_unused_constructor_parameters
- await_only_futures
- cancel_subscriptions
- camel_case_types
- cascade_invocations
- constant_identifier_names
- directives_ordering
- empty_statements
- file_names
- implementation_imports
- iterable_contains_unrelated_type
- join_return_with_assignment
- library_private_types_in_public_api
- lines_longer_than_80_chars
- list_remove_unrelated_type
- missing_whitespace_between_adjacent_strings
- no_runtimeType_toString
- non_constant_identifier_names
- only_throw_errors
- overridden_fields
- package_names
- package_prefixed_library_names
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_function_declarations_over_variables
- prefer_if_null_operators
- prefer_initializing_formals
- prefer_inlined_adds
- prefer_interpolation_to_compose_strings
- prefer_is_not_operator
- prefer_null_aware_operators
- prefer_single_quotes
- prefer_relative_imports
- prefer_typing_uninitialized_variables
- prefer_void_to_null
- provide_deprecation_message
- require_trailing_commas
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- unnecessary_brace_in_string_interps
- unnecessary_lambdas
- unnecessary_null_aware_assignments
- unnecessary_overrides
- unnecessary_parenthesis
- unnecessary_statements
- unnecessary_string_interpolations
- use_is_even_rather_than_modulo
- use_string_buffers
- void_checks

View file

@ -1,2 +0,0 @@
Cargo.lock
/out

View file

@ -1,13 +0,0 @@
[package]
name = "wasmer"
version = "1.0.0-alpha5"
[lib]
name = "wasmer"
crate-type = ["staticlib"]
path = "wasmer.rs"
[dependencies.wasmer-c-api]
version = "1.0.0-alpha5"
default-features = false
features = ["jit", "cranelift", "wasi"]

View file

@ -1,26 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "include/dart_api.h"
#include "include/dart_api_dl.h"
#define FINALIZER(type) \
extern "C" void wasm_##type##_delete(void*); \
extern "C" void wasm_##type##_finalizer(void*, void* native_object) { \
wasm_##type##_delete(native_object); \
} \
DART_EXPORT void set_finalizer_for_##type(Dart_Handle dart_object, \
void* native_object) { \
Dart_NewFinalizableHandle_DL(dart_object, native_object, 0, \
wasm_##type##_finalizer); \
}
FINALIZER(engine);
FINALIZER(store);
FINALIZER(module);
FINALIZER(instance);
FINALIZER(trap);
FINALIZER(memorytype);
FINALIZER(memory);
FINALIZER(func);

View file

@ -1,201 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Builds the wasmer runtime library, to by used by package:wasm. Requires
// rustc, cargo, clang, and clang++. If a target triple is not specified, it
// will default to the host target.
// Usage: dart run wasm:setup [target-triple]
import 'dart:convert';
import 'dart:io' hide exit;
import 'package:wasm/src/shared.dart';
Future<void> main(List<String> args) async {
if (args.length > 1) {
print('Usage: $invocationString [target-triple]');
exitCode = 64; // bad usage
return;
}
final target = args.isNotEmpty ? args[0] : await _getTargetTriple();
try {
await _main(target);
} on ProcessException catch (e) {
final invocation = [e.executable, ...e.arguments].join(' ');
print('FAILED with exit code ${e.errorCode} `$invocation`');
exitCode = 70; // software error
return;
}
}
Uri _getSdkDir() {
// The common case, and how cli_util.dart computes the Dart SDK directory,
// path.dirname called twice on Platform.resolvedExecutable.
final exe = Uri.file(Platform.resolvedExecutable);
final commonSdkDir = exe.resolve('../../dart-sdk/');
if (FileSystemEntity.isDirectorySync(commonSdkDir.path)) {
return commonSdkDir;
}
// This is the less common case where the user is in the checked out Dart
// SDK, and is executing dart via:
// ./out/ReleaseX64/dart ...
final checkedOutSdkDir = exe.resolve('../dart-sdk/');
if (FileSystemEntity.isDirectorySync(checkedOutSdkDir.path)) {
return checkedOutSdkDir;
}
final homebrewOutSdkDir = exe.resolve('..');
final homebrewIncludeDir = homebrewOutSdkDir.resolve('include');
if (FileSystemEntity.isDirectorySync(homebrewIncludeDir.path)) {
return homebrewOutSdkDir;
}
// If neither returned above, we return the common case:
return commonSdkDir;
}
Uri _getOutDir(Uri root) {
final pkgRoot = packageRootUri(root);
if (pkgRoot == null) {
throw ArgumentError('Could not find "$pkgConfigFile" within "$root".');
}
return pkgRoot.resolve(wasmToolDir);
}
String _getOutLib(String target) {
final os = RegExp(r'^.*-.*-(.*)').firstMatch(target)?.group(1) ?? '';
if (os == 'darwin' || os == 'ios') {
return appleLib;
} else if (os == 'windows') {
return 'wasmer.dll';
}
return linuxLib;
}
Future<String> _getTargetTriple() async {
final _regexp = RegExp(r'^([^=]+)="(.*)"$');
final process = await Process.start('rustc', ['--print', 'cfg']);
final sub = process.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
.listen((line) => stderr.writeln(line));
final cfg = <String, String?>{};
await process.stdout
.transform(utf8.decoder)
.transform(const LineSplitter())
.forEach((line) {
final match = _regexp.firstMatch(line);
if (match != null) cfg[match.group(1)!] = match.group(2);
});
await sub.cancel();
var arch = cfg['target_arch'] ?? 'unknown';
var vendor = cfg['target_vendor'] ?? 'unknown';
var os = cfg['target_os'] ?? 'unknown';
if (os == 'macos') os = 'darwin';
var env = cfg['target_env'];
return [arch, vendor, os, env]
.where((element) => element != null && element.isNotEmpty)
.join('-');
}
Future<void> _run(String exe, List<String> args) async {
print('\n$exe ${args.join(' ')}\n');
final process =
await Process.start(exe, args, mode: ProcessStartMode.inheritStdio);
final result = await process.exitCode;
if (result != 0) {
throw ProcessException(exe, args, '', result);
}
}
Future<void> _main(String target) async {
final sdkDir = _getSdkDir();
final binDir = Platform.script;
final outDir = _getOutDir(Directory.current.uri);
final outLib = outDir.resolve(_getOutLib(target)).path;
print('Dart SDK directory: ${sdkDir.path}');
print('Script directory: ${binDir.path}');
print('Output directory: ${outDir.path}');
print('Target: $target');
print('Output library: $outLib');
// Build wasmer crate.
await _run('cargo', [
'build',
'--target',
target,
'--target-dir',
outDir.path,
'--manifest-path',
binDir.resolve('Cargo.toml').path,
'--release'
]);
const dartApiDlImplPath = 'include/internal/dart_api_dl_impl.h';
final dartApiDlImplFile = File.fromUri(sdkDir.resolve(dartApiDlImplPath));
// Hack around a bug with dart_api_dl_impl.h include path in dart_api_dl.c.
if (!dartApiDlImplFile.existsSync()) {
Directory(outDir.resolve('include/internal/').path)
.createSync(recursive: true);
await dartApiDlImplFile.copy(outDir.resolve(dartApiDlImplPath).path);
}
// Build dart_api_dl.o.
await _run('clang', [
'-DDART_SHARED_LIB',
'-DNDEBUG',
'-fno-exceptions',
'-fPIC',
'-O3',
'-target',
target,
'-I',
sdkDir.resolve('include/').path,
'-I',
outDir.resolve('include/').path,
'-c',
sdkDir.resolve('include/dart_api_dl.c').path,
'-o',
outDir.resolve('dart_api_dl.o').path
]);
// Build finalizers.o.
await _run('clang++', [
'-DDART_SHARED_LIB',
'-DNDEBUG',
'-fno-exceptions',
'-fno-rtti',
'-fPIC',
'-O3',
'-std=c++11',
'-target',
target,
'-I',
sdkDir.path,
'-I',
outDir.resolve('include/').path,
'-c',
binDir.resolve('finalizers.cc').path,
'-o',
outDir.resolve('finalizers.o').path
]);
// Link wasmer, dart_api_dl, and finalizers to create the output library.
await _run('clang++', [
'-shared',
'-fPIC',
'-target',
target,
outDir.resolve('dart_api_dl.o').path,
outDir.resolve('finalizers.o').path,
outDir.resolve('$target/release/libwasmer.a').path,
'-o',
outLib
]);
}

View file

@ -1 +0,0 @@
pub extern crate wasmer_c_api;

View file

@ -1,49 +0,0 @@
# Example usage of `package:wasm`
This example demonstrates how to use package:wasm to run a wasm build of the
[Brotli compression library](https://github.com/google/brotli).
### Running the example
`dart brotli.dart lipsum.txt`
This will compress lipsum.txt, report the compression ratio, then decompress it
and verify that the result matches the input.
### Generating wasm code
`libbrotli.wasm` was built by cloning the
[Brotli repo](https://github.com/google/brotli), and compiling it using
[wasienv](https://github.com/wasienv/wasienv).
There are several ways of building wasm code. The most important difference
between the tool sets is how the wasm code they generate interacts with the OS.
For very simple code this difference doesn't matter. But if the library does any
sort of OS interaction, such as file IO, or even using malloc, it will need to
use either Emscripten or WASI for that interaction. package:wasm only supports
WASI at the moment.
To target WASI, one option is to use
[wasi-libc](https://github.com/WebAssembly/wasi-libc) and a recent version of
clang. Set the target to `--target=wasm32-unknown-wasi` and the `--sysroot` to
wasi-libc.
Another option is to build using [wasienv](https://github.com/wasienv/wasienv),
which is a set of tools that are essentially just an ergonomic wrapper around
the clang + wasi-libc approach. This is how libbrotli.wasm was built:
1. Install [wasienv](https://github.com/wasienv/wasienv) and clone the
[Brotli repo](https://github.com/google/brotli).
2. Compile every .c file in brotli/c/common/, dec/, and enc/, using wasicc:
`wasicc -c foo.c -o out/foo.o -I c/include`
3. Link all the .o files together using wasild:
`wasild --no-entry --export=bar out/foo.o $wasienv_sysroot/lib/wasm32-wasi/libc.a`
The `--no-entry` flag tells the linker to ignore the fact that there's no
`main()` function, which is important for libraries. `--export=bar` will
export the `bar()` function from the library, so that it can be found by
package:wasm. For libbrotli.wasm, every function in c/include/brotli/encode.h
and decode.h was exported. Brotli used functions from libc, so the wasm
version of libc that comes with wasienv was also linked in. If there are
still undefined symbols after linking in the wasi libraries, the
`--allow-undefined` flag tells the linker to treat undefined symbols as
function imports. These functions can then be supplied from Dart code.

View file

@ -1,111 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Example of using package:wasm to run a wasm build of the Brotli compression
// library. Usage:
// dart brotli.dart input.txt
import 'dart:io';
import 'dart:typed_data';
import 'package:wasm/wasm.dart';
// Brotli compression parameters.
const _kDefaultQuality = 11;
const _kDefaultWindow = 22;
const _kDefaultMode = 0;
void main(List<String> args) {
if (args.length != 1) {
print('Requires one argument: a path to the input file.');
exitCode = 64; // bad usage
return;
}
final inputFilePath = args.single;
print('Loading "$inputFilePath"...');
var inputDataFile = File(inputFilePath);
if (!inputDataFile.existsSync()) {
print('Input file "$inputFilePath" does not exist.');
exitCode = 66; // no input file
return;
}
var inputData = inputDataFile.readAsBytesSync();
print('Input size: ${inputData.length} bytes');
print('\nLoading wasm module');
var brotliPath = Platform.script.resolve('libbrotli.wasm');
var moduleData = File(brotliPath.path).readAsBytesSync();
var module = WasmModule(moduleData);
print(module.describe());
var builder = module.builder()..enableWasi();
var instance = builder.build();
var memory = instance.memory;
var compress = instance.lookupFunction('BrotliEncoderCompress');
var decompress = instance.lookupFunction('BrotliDecoderDecompress');
// Grow the module's memory to get unused space to put our data.
// [initial memory][input data][output data][size][decoded data][size]
var inputPtr = memory.lengthInBytes;
memory.grow((3 * inputData.length / WasmMemory.kPageSizeInBytes).ceil());
var memoryView = memory.view;
var outputPtr = inputPtr + inputData.length;
var outSizePtr = outputPtr + inputData.length;
var decodedPtr = outSizePtr + 4;
var decSizePtr = decodedPtr + inputData.length;
memoryView.setRange(inputPtr, inputPtr + inputData.length, inputData);
var sizeBytes = ByteData(4)..setUint32(0, inputData.length, Endian.host);
memoryView.setRange(
outSizePtr,
outSizePtr + 4,
sizeBytes.buffer.asUint8List(),
);
print('\nCompressing...');
var status = compress(
_kDefaultQuality,
_kDefaultWindow,
_kDefaultMode,
inputData.length,
inputPtr,
outSizePtr,
outputPtr,
);
print('Compression status: $status');
var compressedSize =
ByteData.sublistView(memoryView, outSizePtr, outSizePtr + 4)
.getUint32(0, Endian.host);
print('Compressed size: $compressedSize bytes');
var spaceSaving = 100 * (1 - compressedSize / inputData.length);
print('Space saving: ${spaceSaving.toStringAsFixed(2)}%');
var decSizeBytes = ByteData(4)..setUint32(0, inputData.length, Endian.host);
memoryView.setRange(
decSizePtr,
decSizePtr + 4,
decSizeBytes.buffer.asUint8List(),
);
print('\nDecompressing...');
status = decompress(compressedSize, outputPtr, decSizePtr, decodedPtr);
print('Decompression status: $status');
var decompressedSize =
ByteData.sublistView(memoryView, decSizePtr, decSizePtr + 4)
.getUint32(0, Endian.host);
print('Decompressed size: $decompressedSize bytes');
print('\nVerifying decompression...');
assert(inputData.length == decompressedSize);
for (var i = 0; i < inputData.length; ++i) {
assert(inputData[i] == memoryView[decodedPtr + i]);
}
print('Decompression succeeded :)');
}

Binary file not shown.

View file

@ -1,10 +0,0 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam feugiat efficitur est a sodales. Ut et odio at nunc fermentum ullamcorper nec in libero. Mauris et interdum elit. Integer in diam nec felis venenatis consectetur. Curabitur elementum egestas augue ac sollicitudin. Cras vulputate efficitur nulla. In blandit sapien ultrices maximus posuere.
Suspendisse in mi at arcu scelerisque tincidunt. Nullam venenatis ex nunc, ut efficitur nulla vehicula eget. Fusce sagittis facilisis ligula nec semper. Nullam et semper ligula. Curabitur sollicitudin ultrices elit et sodales. In iaculis erat scelerisque ipsum scelerisque rutrum. Quisque sollicitudin dolor eu venenatis venenatis. Donec non varius lacus. Phasellus fermentum id mauris nec consequat. Curabitur ultrices, mauris ut scelerisque aliquam, neque augue elementum mi, at accumsan est massa vitae metus. Donec sit amet accumsan dolor, sed vehicula augue. Nunc augue ligula, faucibus tincidunt lorem sed, efficitur ullamcorper erat. Curabitur pellentesque auctor nisi. Cras placerat, massa quis scelerisque commodo, augue leo aliquam elit, sed tempor turpis neque sed nulla. Proin vulputate malesuada augue, quis finibus felis rutrum nec.
Phasellus molestie, tellus eget hendrerit accumsan, diam nunc scelerisque nisi, quis aliquet augue lacus non diam. Nulla facilisi. Nulla est urna, egestas vel luctus nec, sagittis in risus. Mauris aliquam viverra massa vitae efficitur. Integer fringilla sollicitudin ex, et maximus sem gravida ultrices. Vestibulum nec sodales nulla. Cras dapibus maximus venenatis. Vivamus condimentum porttitor mollis. Aliquam congue eleifend condimentum. Donec sagittis bibendum gravida. Nulla condimentum viverra sapien, quis congue libero aliquet nec. Fusce et interdum nisi. Suspendisse at commodo eros. Mauris malesuada nisi in tortor accumsan iaculis. Nam hendrerit interdum magna, eu aliquam est varius eu. Nullam auctor ornare erat, sit amet maximus orci fringilla eu.
Vivamus ullamcorper enim eget tellus lobortis mattis. Vivamus nec tincidunt ipsum. Quisque pharetra non neque non sagittis. Morbi ultrices massa nulla, ac eleifend nulla bibendum mollis. Donec in sodales massa, id luctus dolor. Pellentesque vel auctor tortor, eu imperdiet felis. Pellentesque eleifend eros ipsum, sagittis feugiat enim placerat at. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam lacinia pharetra est.
Duis elit arcu, faucibus ac libero ut, auctor volutpat elit. Duis blandit quis felis at ultricies. Duis ac eros id velit pretium sagittis. Praesent eget orci porttitor, posuere purus ac, interdum eros. Nam augue velit, euismod nec lobortis vitae, rutrum ut libero. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean porttitor sem ante. Integer elit purus, sollicitudin sit amet est in, accumsan suscipit libero. Donec finibus metus scelerisque, mattis dui quis, suscipit turpis. Aliquam rhoncus leo ipsum, vel hendrerit ante porta sit amet. Donec dui nisi, bibendum non rutrum vel, ornare nec diam. Proin tristique ipsum eu pulvinar finibus. Duis pellentesque massa a condimentum elementum. Maecenas efficitur ac est in eleifend. Mauris sit amet lacus blandit, pulvinar ex in, commodo eros.

View file

@ -1,449 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:ffi';
import 'dart:typed_data';
import 'package:ffi/ffi.dart';
import 'runtime.dart';
import 'wasm_error.dart';
import 'wasmer_api.dart';
/// A compiled module that can be instantiated.
class WasmModule {
late final Pointer<WasmerStore> _store;
late final Pointer<WasmerModule> _module;
/// Compile a module.
WasmModule(Uint8List data) {
var runtime = WasmRuntime();
_store = runtime.newStore(this);
_module = runtime.compile(this, _store, data);
}
/// Returns a [WasmInstanceBuilder] that is used to add all the imports that
/// the module needs before instantiating it.
WasmInstanceBuilder builder() => WasmInstanceBuilder._(this);
/// Create a new memory with the given number of initial pages, and optional
/// maximum number of pages.
WasmMemory createMemory(int pages, [int? maxPages]) =>
WasmMemory._create(_store, pages, maxPages);
/// Returns a description of all of the module's imports and exports, for
/// debugging.
String describe() {
var description = StringBuffer();
var runtime = WasmRuntime();
var imports = runtime.importDescriptors(_module);
for (var imp in imports) {
description.write('import $imp\n');
}
var exports = runtime.exportDescriptors(_module);
for (var exp in exports) {
description.write('export $exp\n');
}
return description.toString();
}
}
Pointer<WasmerTrap> _wasmFnImportTrampoline(
Pointer<_WasmFnImport> imp,
Pointer<WasmerValVec> args,
Pointer<WasmerValVec> results,
) {
try {
_WasmFnImport._call(imp, args, results);
} catch (exception) {
return WasmRuntime().newTrap(imp.ref.store, exception);
}
return nullptr;
}
void _wasmFnImportFinalizer(Pointer<_WasmFnImport> imp) {
_wasmFnImportToFn.remove(imp.address);
calloc.free(imp);
}
final _wasmFnImportTrampolineNative = Pointer.fromFunction<
Pointer<WasmerTrap> Function(
Pointer<_WasmFnImport>,
Pointer<WasmerValVec>,
Pointer<WasmerValVec>,
)>(_wasmFnImportTrampoline);
final _wasmFnImportToFn = <int, Function>{};
final _wasmFnImportFinalizerNative =
Pointer.fromFunction<Void Function(Pointer<_WasmFnImport>)>(
_wasmFnImportFinalizer,
);
class _WasmFnImport extends Struct {
@Int32()
external int returnType;
external Pointer<WasmerStore> store;
static void _call(
Pointer<_WasmFnImport> imp,
Pointer<WasmerValVec> rawArgs,
Pointer<WasmerValVec> rawResult,
) {
var fn = _wasmFnImportToFn[imp.address] as Function;
var args = [];
for (var i = 0; i < rawArgs.ref.length; ++i) {
args.add(rawArgs.ref.data[i].toDynamic);
}
assert(
rawResult.ref.length == 1 || imp.ref.returnType == wasmerValKindVoid,
);
var result = Function.apply(fn, args);
if (imp.ref.returnType != wasmerValKindVoid) {
rawResult.ref.data[0].kind = imp.ref.returnType;
switch (imp.ref.returnType) {
case wasmerValKindI32:
rawResult.ref.data[0].i32 = result as int;
break;
case wasmerValKindI64:
rawResult.ref.data[0].i64 = result as int;
break;
case wasmerValKindF32:
rawResult.ref.data[0].f32 = result as int;
break;
case wasmerValKindF64:
rawResult.ref.data[0].f64 = result as int;
break;
}
}
}
}
/// Used to collect all of the imports that a [WasmModule] requires before it is
/// built.
class WasmInstanceBuilder {
final _importOwner = _WasmImportOwner();
final _importIndex = <String, int>{};
final _imports = calloc<WasmerExternVec>();
final WasmModule _module;
late final List<WasmImportDescriptor> _importDescs;
Pointer<WasmerWasiEnv> _wasiEnv = nullptr;
WasmInstanceBuilder._(this._module)
: _importDescs = WasmRuntime().importDescriptors(_module._module) {
_imports.ref.length = _importDescs.length;
_imports.ref.data = calloc<Pointer<WasmerExtern>>(_importDescs.length);
for (var i = 0; i < _importDescs.length; ++i) {
var imp = _importDescs[i];
_importIndex['${imp.moduleName}::${imp.name}'] = i;
_imports.ref.data[i] = nullptr;
}
}
int _getIndex(String moduleName, String name) {
var index = _importIndex['$moduleName::$name'];
if (index == null) {
throw WasmError('Import not found: $moduleName::$name');
} else if (_imports.ref.data[index] != nullptr) {
throw WasmError('Import already filled: $moduleName::$name');
} else {
return index;
}
}
/// Add a WasmMemory to the imports.
void addMemory(
String moduleName,
String name,
WasmMemory memory,
) {
var index = _getIndex(moduleName, name);
var imp = _importDescs[index];
if (imp.kind != wasmerExternKindMemory) {
throw WasmError('Import is not a memory: $imp');
}
_imports.ref.data[index] = WasmRuntime().memoryToExtern(memory._mem);
}
/// Add a function to the imports.
void addFunction(String moduleName, String name, Function fn) {
var index = _getIndex(moduleName, name);
var imp = _importDescs[index];
if (imp.kind != wasmerExternKindFunction) {
throw WasmError('Import is not a function: $imp');
}
var runtime = WasmRuntime();
var returnType = runtime.getReturnType(imp.funcType);
var wasmFnImport = calloc<_WasmFnImport>();
wasmFnImport.ref.returnType = returnType;
wasmFnImport.ref.store = _module._store;
_wasmFnImportToFn[wasmFnImport.address] = fn;
var fnImp = runtime.newFunc(
_importOwner,
_module._store,
imp.funcType,
_wasmFnImportTrampolineNative,
wasmFnImport,
_wasmFnImportFinalizerNative,
);
_imports.ref.data[index] = runtime.functionToExtern(fnImp);
}
/// Enable WASI and add the default WASI imports.
void enableWasi({
bool captureStdout = false,
bool captureStderr = false,
}) {
if (_wasiEnv != nullptr) {
throw WasmError('WASI is already enabled.');
}
var runtime = WasmRuntime();
var config = runtime.newWasiConfig();
if (captureStdout) runtime.captureWasiStdout(config);
if (captureStderr) runtime.captureWasiStderr(config);
_wasiEnv = runtime.newWasiEnv(config);
runtime.getWasiImports(_module._store, _module._module, _wasiEnv, _imports);
}
/// Build the module instance.
WasmInstance build() {
for (var i = 0; i < _importDescs.length; ++i) {
if (_imports.ref.data[i] == nullptr) {
throw WasmError('Missing import: ${_importDescs[i]}');
}
}
return WasmInstance._(_module, _importOwner, _imports, _wasiEnv);
}
}
// TODO: should not be required once the min supported Dart SDK includes
// github.com/dart-lang/sdk/commit/8fd81f72281d9d3aa5ef3890c947cc7305c56a50
class _WasmImportOwner {}
/// An instantiated [WasmModule].
///
/// Created by calling [WasmInstanceBuilder.build].
class WasmInstance {
final _WasmImportOwner _importOwner;
final _functions = <String, WasmFunction>{};
final WasmModule _module;
final Pointer<WasmerWasiEnv> _wasiEnv;
late final Pointer<WasmerInstance> _instance;
Pointer<WasmerMemory>? _exportedMemory;
Stream<List<int>>? _stdout;
Stream<List<int>>? _stderr;
WasmInstance._(
this._module,
this._importOwner,
Pointer<WasmerExternVec> imports,
this._wasiEnv,
) {
var runtime = WasmRuntime();
_instance = runtime.instantiate(
_importOwner,
_module._store,
_module._module,
imports,
);
var exports = runtime.exports(_instance);
var exportDescs = runtime.exportDescriptors(_module._module);
assert(exports.ref.length == exportDescs.length);
for (var i = 0; i < exports.ref.length; ++i) {
var e = exports.ref.data[i];
var kind = runtime.externKind(exports.ref.data[i]);
var name = exportDescs[i].name;
if (kind == wasmerExternKindFunction) {
var f = runtime.externToFunction(e);
var ft = exportDescs[i].funcType;
_functions[name] = WasmFunction._(
name,
f,
runtime.getArgTypes(ft),
runtime.getReturnType(ft),
);
} else if (kind == wasmerExternKindMemory) {
// WASM currently allows only one memory per module.
var mem = runtime.externToMemory(e);
_exportedMemory = mem;
if (_wasiEnv != nullptr) {
runtime.wasiEnvSetMemory(_wasiEnv, mem);
}
}
}
}
/// Searches the instantiated module for the given function.
///
/// Returns a [WasmFunction], but the return type is [dynamic] to allow
/// easy invocation as a [Function].
///
/// Returns `null` if no function exists with name [name].
dynamic lookupFunction(String name) => _functions[name];
/// Returns the memory exported from this instance.
WasmMemory get memory {
if (_exportedMemory == null) {
throw WasmError('Wasm module did not export its memory.');
}
return WasmMemory._fromExport(_exportedMemory as Pointer<WasmerMemory>);
}
/// Returns a stream that reads from `stdout`.
///
/// To use this, you must enable WASI when instantiating the module, and set
/// `captureStdout` to `true`.
Stream<List<int>> get stdout {
if (_wasiEnv == nullptr) {
throw WasmError("Can't capture stdout without WASI enabled.");
}
return _stdout ??= WasmRuntime().getWasiStdoutStream(_wasiEnv);
}
/// Returns a stream that reads from `stderr`.
///
/// To use this, you must enable WASI when instantiating the module, and set
/// `captureStderr` to `true`.
Stream<List<int>> get stderr {
if (_wasiEnv == nullptr) {
throw WasmError("Can't capture stderr without WASI enabled.");
}
return _stderr ??= WasmRuntime().getWasiStderrStream(_wasiEnv);
}
}
/// Memory of a [WasmInstance].
///
/// Access via [WasmInstance.memory] or create via [WasmModule.createMemory].
class WasmMemory {
late final Pointer<WasmerMemory> _mem;
late Uint8List _view;
WasmMemory._fromExport(this._mem) {
_view = WasmRuntime().memoryView(_mem);
}
/// Create a new memory with the given number of initial pages, and optional
/// maximum number of pages.
WasmMemory._create(Pointer<WasmerStore> store, int pages, int? maxPages) {
_mem = WasmRuntime().newMemory(this, store, pages, maxPages);
_view = WasmRuntime().memoryView(_mem);
}
/// The WASM spec defines the page size as 64KiB.
static const int kPageSizeInBytes = 64 * 1024;
/// The length of the memory in pages.
int get lengthInPages => WasmRuntime().memoryLength(_mem);
/// The length of the memory in bytes.
int get lengthInBytes => _view.lengthInBytes;
/// The byte at the given [index].
int operator [](int index) => _view[index];
/// Sets the byte at the given index to value.
void operator []=(int index, int value) {
_view[index] = value;
}
/// A view into the memory.
Uint8List get view => _view;
/// Grow the memory by [deltaPages] and invalidates any existing views into
/// the memory.
void grow(int deltaPages) {
var runtime = WasmRuntime()..growMemory(_mem, deltaPages);
_view = runtime.memoryView(_mem);
}
}
/// A callable function from a [WasmInstance].
///
/// Access by calling [WasmInstance.lookupFunction].
class WasmFunction {
final String _name;
final Pointer<WasmerFunc> _func;
final List<int> _argTypes;
final int _returnType;
final Pointer<WasmerValVec> _args = calloc<WasmerValVec>();
final Pointer<WasmerValVec> _results = calloc<WasmerValVec>();
WasmFunction._(this._name, this._func, this._argTypes, this._returnType) {
_args.ref.length = _argTypes.length;
_args.ref.data =
_argTypes.isEmpty ? nullptr : calloc<WasmerVal>(_argTypes.length);
_results.ref.length = _returnType == wasmerValKindVoid ? 0 : 1;
_results.ref.data =
_returnType == wasmerValKindVoid ? nullptr : calloc<WasmerVal>();
for (var i = 0; i < _argTypes.length; ++i) {
_args.ref.data[i].kind = _argTypes[i];
}
}
@override
String toString() =>
WasmRuntime.getSignatureString(_name, _argTypes, _returnType);
bool _fillArg(dynamic arg, int i) {
switch (_argTypes[i]) {
case wasmerValKindI32:
if (arg is! int) return false;
_args.ref.data[i].i32 = arg;
return true;
case wasmerValKindI64:
if (arg is! int) return false;
_args.ref.data[i].i64 = arg;
return true;
case wasmerValKindF32:
if (arg is! num) return false;
_args.ref.data[i].f32 = arg;
return true;
case wasmerValKindF64:
if (arg is! num) return false;
_args.ref.data[i].f64 = arg;
return true;
}
return false;
}
dynamic apply(List<dynamic> args) {
if (args.length != _argTypes.length) {
throw ArgumentError('Wrong number arguments for WASM function: $this');
}
for (var i = 0; i < args.length; ++i) {
if (!_fillArg(args[i], i)) {
throw ArgumentError('Bad argument type for WASM function: $this');
}
}
WasmRuntime().call(_func, _args, _results, toString());
if (_returnType == wasmerValKindVoid) {
return null;
}
var result = _results.ref.data[0];
assert(_returnType == result.kind);
switch (_returnType) {
case wasmerValKindI32:
return result.i32;
case wasmerValKindI64:
return result.i64;
case wasmerValKindF32:
return result.f32;
case wasmerValKindF64:
return result.f64;
}
}
@override
dynamic noSuchMethod(Invocation invocation) {
if (invocation.memberName == #call) {
return apply(invocation.positionalArguments);
}
return super.noSuchMethod(invocation);
}
}

View file

@ -1,122 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
import 'package:ffi/ffi.dart';
import 'shared.dart';
import 'wasm_error.dart';
import 'wasmer_api.dart';
part 'runtime.g.dart';
class WasmImportDescriptor {
final int kind;
final String moduleName;
final String name;
final Pointer<WasmerFunctype> funcType;
WasmImportDescriptor._(this.kind, this.moduleName, this.name, this.funcType);
@override
String toString() {
var kindName = wasmerExternKindName(kind);
if (kind == wasmerExternKindFunction) {
var runtime = WasmRuntime();
var sig = WasmRuntime.getSignatureString(
'$moduleName::$name',
runtime.getArgTypes(funcType),
runtime.getReturnType(funcType),
);
return '$kindName: $sig';
} else {
return '$kindName: $moduleName::$name';
}
}
}
class WasmExportDescriptor {
final int kind;
final String name;
final Pointer<WasmerFunctype> funcType;
WasmExportDescriptor._(this.kind, this.name, this.funcType);
@override
String toString() {
var kindName = wasmerExternKindName(kind);
if (kind == wasmerExternKindFunction) {
var runtime = WasmRuntime();
var sig = WasmRuntime.getSignatureString(
name,
runtime.getArgTypes(funcType),
runtime.getReturnType(funcType),
);
return '$kindName: $sig';
} else {
return '$kindName: $name';
}
}
}
class _WasmTrapsEntry {
final Object exception;
_WasmTrapsEntry(this.exception);
}
class _WasiStreamIterator implements Iterator<List<int>> {
static const int _bufferLength = 1024;
final Pointer<Uint8> _buf = calloc<Uint8>(_bufferLength);
final Pointer<WasmerWasiEnv> _env;
final Function _reader;
int _length = 0;
_WasiStreamIterator(this._env, this._reader);
@override
bool moveNext() {
_length = _reader(_env, _buf, _bufferLength) as int;
return true;
}
@override
List<int> get current => _buf.asTypedList(_length);
}
class _WasiStreamIterable extends Iterable<List<int>> {
final Pointer<WasmerWasiEnv> _env;
final Function _reader;
_WasiStreamIterable(this._env, this._reader);
@override
Iterator<List<int>> get iterator => _WasiStreamIterator(_env, _reader);
}
String _getLibName() {
if (Platform.isMacOS) return appleLib;
if (Platform.isLinux) return linuxLib;
// TODO(dartbug.com/37882): Support more platforms.
throw WasmError('Wasm not currently supported on this platform');
}
String? _getLibPathFrom(Uri root) {
final pkgRoot = packageRootUri(root);
return pkgRoot?.resolve('$wasmToolDir${_getLibName()}').path;
}
String _getLibPath() {
var path = _getLibPathFrom(Platform.script.resolve('./'));
if (path != null) return path;
path = _getLibPathFrom(Directory.current.uri);
if (path != null) return path;
throw WasmError('Wasm library not found. Did you `$invocationString`?');
}

View file

@ -1,768 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use the following command
// "generate_ffi_boilerplate.py".
// ignore_for_file: cascade_invocations
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: unused_field
part of 'runtime.dart';
class WasmRuntime {
static final WasmRuntime _inst = WasmRuntime._init();
final DynamicLibrary _lib;
final _traps = <int, _WasmTrapsEntry>{};
late final Pointer<WasmerEngine> _engine;
late final WasmerDartInitializeApiDLFn _Dart_InitializeApiDL;
late final WasmerSetFinalizerForEngineFn _set_finalizer_for_engine;
late final WasmerSetFinalizerForFuncFn _set_finalizer_for_func;
late final WasmerSetFinalizerForInstanceFn _set_finalizer_for_instance;
late final WasmerSetFinalizerForMemoryFn _set_finalizer_for_memory;
late final WasmerSetFinalizerForMemorytypeFn _set_finalizer_for_memorytype;
late final WasmerSetFinalizerForModuleFn _set_finalizer_for_module;
late final WasmerSetFinalizerForStoreFn _set_finalizer_for_store;
late final WasmerSetFinalizerForTrapFn _set_finalizer_for_trap;
late final WasmerWasiConfigInheritStderrFn _wasi_config_inherit_stderr;
late final WasmerWasiConfigInheritStdoutFn _wasi_config_inherit_stdout;
late final WasmerWasiConfigNewFn _wasi_config_new;
late final WasmerWasiEnvDeleteFn _wasi_env_delete;
late final WasmerWasiEnvNewFn _wasi_env_new;
late final WasmerWasiEnvReadStderrFn _wasi_env_read_stderr;
late final WasmerWasiEnvReadStdoutFn _wasi_env_read_stdout;
late final WasmerWasiEnvSetMemoryFn _wasi_env_set_memory;
late final WasmerWasiGetImportsFn _wasi_get_imports;
late final WasmerByteVecDeleteFn _byte_vec_delete;
late final WasmerByteVecNewFn _byte_vec_new;
late final WasmerByteVecNewEmptyFn _byte_vec_new_empty;
late final WasmerByteVecNewUninitializedFn _byte_vec_new_uninitialized;
late final WasmerEngineDeleteFn _engine_delete;
late final WasmerEngineNewFn _engine_new;
late final WasmerExporttypeNameFn _exporttype_name;
late final WasmerExporttypeTypeFn _exporttype_type;
late final WasmerExporttypeVecDeleteFn _exporttype_vec_delete;
late final WasmerExporttypeVecNewFn _exporttype_vec_new;
late final WasmerExporttypeVecNewEmptyFn _exporttype_vec_new_empty;
late final WasmerExporttypeVecNewUninitializedFn
_exporttype_vec_new_uninitialized;
late final WasmerExternAsFuncFn _extern_as_func;
late final WasmerExternAsMemoryFn _extern_as_memory;
late final WasmerExternDeleteFn _extern_delete;
late final WasmerExternKindFn _extern_kind;
late final WasmerExternVecDeleteFn _extern_vec_delete;
late final WasmerExternVecNewFn _extern_vec_new;
late final WasmerExternVecNewEmptyFn _extern_vec_new_empty;
late final WasmerExternVecNewUninitializedFn _extern_vec_new_uninitialized;
late final WasmerExterntypeAsFunctypeFn _externtype_as_functype;
late final WasmerExterntypeDeleteFn _externtype_delete;
late final WasmerExterntypeKindFn _externtype_kind;
late final WasmerFuncAsExternFn _func_as_extern;
late final WasmerFuncCallFn _func_call;
late final WasmerFuncDeleteFn _func_delete;
late final WasmerFuncNewWithEnvFn _func_new_with_env;
late final WasmerFunctypeDeleteFn _functype_delete;
late final WasmerFunctypeParamsFn _functype_params;
late final WasmerFunctypeResultsFn _functype_results;
late final WasmerImporttypeModuleFn _importtype_module;
late final WasmerImporttypeNameFn _importtype_name;
late final WasmerImporttypeTypeFn _importtype_type;
late final WasmerImporttypeVecDeleteFn _importtype_vec_delete;
late final WasmerImporttypeVecNewFn _importtype_vec_new;
late final WasmerImporttypeVecNewEmptyFn _importtype_vec_new_empty;
late final WasmerImporttypeVecNewUninitializedFn
_importtype_vec_new_uninitialized;
late final WasmerInstanceDeleteFn _instance_delete;
late final WasmerInstanceExportsFn _instance_exports;
late final WasmerInstanceNewFn _instance_new;
late final WasmerMemoryAsExternFn _memory_as_extern;
late final WasmerMemoryDataFn _memory_data;
late final WasmerMemoryDataSizeFn _memory_data_size;
late final WasmerMemoryDeleteFn _memory_delete;
late final WasmerMemoryGrowFn _memory_grow;
late final WasmerMemoryNewFn _memory_new;
late final WasmerMemorySizeFn _memory_size;
late final WasmerMemorytypeDeleteFn _memorytype_delete;
late final WasmerMemorytypeNewFn _memorytype_new;
late final WasmerModuleDeleteFn _module_delete;
late final WasmerModuleExportsFn _module_exports;
late final WasmerModuleImportsFn _module_imports;
late final WasmerModuleNewFn _module_new;
late final WasmerStoreDeleteFn _store_delete;
late final WasmerStoreNewFn _store_new;
late final WasmerTrapDeleteFn _trap_delete;
late final WasmerTrapMessageFn _trap_message;
late final WasmerTrapNewFn _trap_new;
late final WasmerValtypeDeleteFn _valtype_delete;
late final WasmerValtypeKindFn _valtype_kind;
late final WasmerValtypeVecDeleteFn _valtype_vec_delete;
late final WasmerValtypeVecNewFn _valtype_vec_new;
late final WasmerValtypeVecNewEmptyFn _valtype_vec_new_empty;
late final WasmerValtypeVecNewUninitializedFn _valtype_vec_new_uninitialized;
late final WasmerWasmerLastErrorLengthFn _wasmer_last_error_length;
late final WasmerWasmerLastErrorMessageFn _wasmer_last_error_message;
factory WasmRuntime() => _inst;
WasmRuntime._init() : _lib = DynamicLibrary.open(_getLibPath()) {
_Dart_InitializeApiDL = _lib.lookupFunction<
NativeWasmerDartInitializeApiDLFn, WasmerDartInitializeApiDLFn>(
'Dart_InitializeApiDL',
);
_set_finalizer_for_engine = _lib.lookupFunction<
NativeWasmerSetFinalizerForEngineFn, WasmerSetFinalizerForEngineFn>(
'set_finalizer_for_engine',
);
_set_finalizer_for_func = _lib.lookupFunction<
NativeWasmerSetFinalizerForFuncFn, WasmerSetFinalizerForFuncFn>(
'set_finalizer_for_func',
);
_set_finalizer_for_instance = _lib.lookupFunction<
NativeWasmerSetFinalizerForInstanceFn, WasmerSetFinalizerForInstanceFn>(
'set_finalizer_for_instance',
);
_set_finalizer_for_memory = _lib.lookupFunction<
NativeWasmerSetFinalizerForMemoryFn, WasmerSetFinalizerForMemoryFn>(
'set_finalizer_for_memory',
);
_set_finalizer_for_memorytype = _lib.lookupFunction<
NativeWasmerSetFinalizerForMemorytypeFn,
WasmerSetFinalizerForMemorytypeFn>(
'set_finalizer_for_memorytype',
);
_set_finalizer_for_module = _lib.lookupFunction<
NativeWasmerSetFinalizerForModuleFn, WasmerSetFinalizerForModuleFn>(
'set_finalizer_for_module',
);
_set_finalizer_for_store = _lib.lookupFunction<
NativeWasmerSetFinalizerForStoreFn, WasmerSetFinalizerForStoreFn>(
'set_finalizer_for_store',
);
_set_finalizer_for_trap = _lib.lookupFunction<
NativeWasmerSetFinalizerForTrapFn, WasmerSetFinalizerForTrapFn>(
'set_finalizer_for_trap',
);
_wasi_config_inherit_stderr = _lib.lookupFunction<
NativeWasmerWasiConfigInheritStderrFn, WasmerWasiConfigInheritStderrFn>(
'wasi_config_inherit_stderr',
);
_wasi_config_inherit_stdout = _lib.lookupFunction<
NativeWasmerWasiConfigInheritStdoutFn, WasmerWasiConfigInheritStdoutFn>(
'wasi_config_inherit_stdout',
);
_wasi_config_new =
_lib.lookupFunction<NativeWasmerWasiConfigNewFn, WasmerWasiConfigNewFn>(
'wasi_config_new',
);
_wasi_env_delete =
_lib.lookupFunction<NativeWasmerWasiEnvDeleteFn, WasmerWasiEnvDeleteFn>(
'wasi_env_delete',
);
_wasi_env_new =
_lib.lookupFunction<NativeWasmerWasiEnvNewFn, WasmerWasiEnvNewFn>(
'wasi_env_new',
);
_wasi_env_read_stderr = _lib.lookupFunction<NativeWasmerWasiEnvReadStderrFn,
WasmerWasiEnvReadStderrFn>(
'wasi_env_read_stderr',
);
_wasi_env_read_stdout = _lib.lookupFunction<NativeWasmerWasiEnvReadStdoutFn,
WasmerWasiEnvReadStdoutFn>(
'wasi_env_read_stdout',
);
_wasi_env_set_memory = _lib.lookupFunction<NativeWasmerWasiEnvSetMemoryFn,
WasmerWasiEnvSetMemoryFn>(
'wasi_env_set_memory',
);
_wasi_get_imports = _lib
.lookupFunction<NativeWasmerWasiGetImportsFn, WasmerWasiGetImportsFn>(
'wasi_get_imports',
);
_byte_vec_delete =
_lib.lookupFunction<NativeWasmerByteVecDeleteFn, WasmerByteVecDeleteFn>(
'wasm_byte_vec_delete',
);
_byte_vec_new =
_lib.lookupFunction<NativeWasmerByteVecNewFn, WasmerByteVecNewFn>(
'wasm_byte_vec_new',
);
_byte_vec_new_empty = _lib
.lookupFunction<NativeWasmerByteVecNewEmptyFn, WasmerByteVecNewEmptyFn>(
'wasm_byte_vec_new_empty',
);
_byte_vec_new_uninitialized = _lib.lookupFunction<
NativeWasmerByteVecNewUninitializedFn, WasmerByteVecNewUninitializedFn>(
'wasm_byte_vec_new_uninitialized',
);
_engine_delete =
_lib.lookupFunction<NativeWasmerEngineDeleteFn, WasmerEngineDeleteFn>(
'wasm_engine_delete',
);
_engine_new =
_lib.lookupFunction<NativeWasmerEngineNewFn, WasmerEngineNewFn>(
'wasm_engine_new',
);
_exporttype_name = _lib
.lookupFunction<NativeWasmerExporttypeNameFn, WasmerExporttypeNameFn>(
'wasm_exporttype_name',
);
_exporttype_type = _lib
.lookupFunction<NativeWasmerExporttypeTypeFn, WasmerExporttypeTypeFn>(
'wasm_exporttype_type',
);
_exporttype_vec_delete = _lib.lookupFunction<
NativeWasmerExporttypeVecDeleteFn, WasmerExporttypeVecDeleteFn>(
'wasm_exporttype_vec_delete',
);
_exporttype_vec_new = _lib.lookupFunction<NativeWasmerExporttypeVecNewFn,
WasmerExporttypeVecNewFn>(
'wasm_exporttype_vec_new',
);
_exporttype_vec_new_empty = _lib.lookupFunction<
NativeWasmerExporttypeVecNewEmptyFn, WasmerExporttypeVecNewEmptyFn>(
'wasm_exporttype_vec_new_empty',
);
_exporttype_vec_new_uninitialized = _lib.lookupFunction<
NativeWasmerExporttypeVecNewUninitializedFn,
WasmerExporttypeVecNewUninitializedFn>(
'wasm_exporttype_vec_new_uninitialized',
);
_extern_as_func =
_lib.lookupFunction<NativeWasmerExternAsFuncFn, WasmerExternAsFuncFn>(
'wasm_extern_as_func',
);
_extern_as_memory = _lib
.lookupFunction<NativeWasmerExternAsMemoryFn, WasmerExternAsMemoryFn>(
'wasm_extern_as_memory',
);
_extern_delete =
_lib.lookupFunction<NativeWasmerExternDeleteFn, WasmerExternDeleteFn>(
'wasm_extern_delete',
);
_extern_kind =
_lib.lookupFunction<NativeWasmerExternKindFn, WasmerExternKindFn>(
'wasm_extern_kind',
);
_extern_vec_delete = _lib
.lookupFunction<NativeWasmerExternVecDeleteFn, WasmerExternVecDeleteFn>(
'wasm_extern_vec_delete',
);
_extern_vec_new =
_lib.lookupFunction<NativeWasmerExternVecNewFn, WasmerExternVecNewFn>(
'wasm_extern_vec_new',
);
_extern_vec_new_empty = _lib.lookupFunction<NativeWasmerExternVecNewEmptyFn,
WasmerExternVecNewEmptyFn>(
'wasm_extern_vec_new_empty',
);
_extern_vec_new_uninitialized = _lib.lookupFunction<
NativeWasmerExternVecNewUninitializedFn,
WasmerExternVecNewUninitializedFn>(
'wasm_extern_vec_new_uninitialized',
);
_externtype_as_functype = _lib.lookupFunction<
NativeWasmerExterntypeAsFunctypeFn, WasmerExterntypeAsFunctypeFn>(
'wasm_externtype_as_functype',
);
_externtype_delete = _lib.lookupFunction<NativeWasmerExterntypeDeleteFn,
WasmerExterntypeDeleteFn>(
'wasm_externtype_delete',
);
_externtype_kind = _lib
.lookupFunction<NativeWasmerExterntypeKindFn, WasmerExterntypeKindFn>(
'wasm_externtype_kind',
);
_func_as_extern =
_lib.lookupFunction<NativeWasmerFuncAsExternFn, WasmerFuncAsExternFn>(
'wasm_func_as_extern',
);
_func_call = _lib.lookupFunction<NativeWasmerFuncCallFn, WasmerFuncCallFn>(
'wasm_func_call',
);
_func_delete =
_lib.lookupFunction<NativeWasmerFuncDeleteFn, WasmerFuncDeleteFn>(
'wasm_func_delete',
);
_func_new_with_env = _lib
.lookupFunction<NativeWasmerFuncNewWithEnvFn, WasmerFuncNewWithEnvFn>(
'wasm_func_new_with_env',
);
_functype_delete = _lib
.lookupFunction<NativeWasmerFunctypeDeleteFn, WasmerFunctypeDeleteFn>(
'wasm_functype_delete',
);
_functype_params = _lib
.lookupFunction<NativeWasmerFunctypeParamsFn, WasmerFunctypeParamsFn>(
'wasm_functype_params',
);
_functype_results = _lib
.lookupFunction<NativeWasmerFunctypeResultsFn, WasmerFunctypeResultsFn>(
'wasm_functype_results',
);
_importtype_module = _lib.lookupFunction<NativeWasmerImporttypeModuleFn,
WasmerImporttypeModuleFn>(
'wasm_importtype_module',
);
_importtype_name = _lib
.lookupFunction<NativeWasmerImporttypeNameFn, WasmerImporttypeNameFn>(
'wasm_importtype_name',
);
_importtype_type = _lib
.lookupFunction<NativeWasmerImporttypeTypeFn, WasmerImporttypeTypeFn>(
'wasm_importtype_type',
);
_importtype_vec_delete = _lib.lookupFunction<
NativeWasmerImporttypeVecDeleteFn, WasmerImporttypeVecDeleteFn>(
'wasm_importtype_vec_delete',
);
_importtype_vec_new = _lib.lookupFunction<NativeWasmerImporttypeVecNewFn,
WasmerImporttypeVecNewFn>(
'wasm_importtype_vec_new',
);
_importtype_vec_new_empty = _lib.lookupFunction<
NativeWasmerImporttypeVecNewEmptyFn, WasmerImporttypeVecNewEmptyFn>(
'wasm_importtype_vec_new_empty',
);
_importtype_vec_new_uninitialized = _lib.lookupFunction<
NativeWasmerImporttypeVecNewUninitializedFn,
WasmerImporttypeVecNewUninitializedFn>(
'wasm_importtype_vec_new_uninitialized',
);
_instance_delete = _lib
.lookupFunction<NativeWasmerInstanceDeleteFn, WasmerInstanceDeleteFn>(
'wasm_instance_delete',
);
_instance_exports = _lib
.lookupFunction<NativeWasmerInstanceExportsFn, WasmerInstanceExportsFn>(
'wasm_instance_exports',
);
_instance_new =
_lib.lookupFunction<NativeWasmerInstanceNewFn, WasmerInstanceNewFn>(
'wasm_instance_new',
);
_memory_as_extern = _lib
.lookupFunction<NativeWasmerMemoryAsExternFn, WasmerMemoryAsExternFn>(
'wasm_memory_as_extern',
);
_memory_data =
_lib.lookupFunction<NativeWasmerMemoryDataFn, WasmerMemoryDataFn>(
'wasm_memory_data',
);
_memory_data_size = _lib
.lookupFunction<NativeWasmerMemoryDataSizeFn, WasmerMemoryDataSizeFn>(
'wasm_memory_data_size',
);
_memory_delete =
_lib.lookupFunction<NativeWasmerMemoryDeleteFn, WasmerMemoryDeleteFn>(
'wasm_memory_delete',
);
_memory_grow =
_lib.lookupFunction<NativeWasmerMemoryGrowFn, WasmerMemoryGrowFn>(
'wasm_memory_grow',
);
_memory_new =
_lib.lookupFunction<NativeWasmerMemoryNewFn, WasmerMemoryNewFn>(
'wasm_memory_new',
);
_memory_size =
_lib.lookupFunction<NativeWasmerMemorySizeFn, WasmerMemorySizeFn>(
'wasm_memory_size',
);
_memorytype_delete = _lib.lookupFunction<NativeWasmerMemorytypeDeleteFn,
WasmerMemorytypeDeleteFn>(
'wasm_memorytype_delete',
);
_memorytype_new =
_lib.lookupFunction<NativeWasmerMemorytypeNewFn, WasmerMemorytypeNewFn>(
'wasm_memorytype_new',
);
_module_delete =
_lib.lookupFunction<NativeWasmerModuleDeleteFn, WasmerModuleDeleteFn>(
'wasm_module_delete',
);
_module_exports =
_lib.lookupFunction<NativeWasmerModuleExportsFn, WasmerModuleExportsFn>(
'wasm_module_exports',
);
_module_imports =
_lib.lookupFunction<NativeWasmerModuleImportsFn, WasmerModuleImportsFn>(
'wasm_module_imports',
);
_module_new =
_lib.lookupFunction<NativeWasmerModuleNewFn, WasmerModuleNewFn>(
'wasm_module_new',
);
_store_delete =
_lib.lookupFunction<NativeWasmerStoreDeleteFn, WasmerStoreDeleteFn>(
'wasm_store_delete',
);
_store_new = _lib.lookupFunction<NativeWasmerStoreNewFn, WasmerStoreNewFn>(
'wasm_store_new',
);
_trap_delete =
_lib.lookupFunction<NativeWasmerTrapDeleteFn, WasmerTrapDeleteFn>(
'wasm_trap_delete',
);
_trap_message =
_lib.lookupFunction<NativeWasmerTrapMessageFn, WasmerTrapMessageFn>(
'wasm_trap_message',
);
_trap_new = _lib.lookupFunction<NativeWasmerTrapNewFn, WasmerTrapNewFn>(
'wasm_trap_new',
);
_valtype_delete =
_lib.lookupFunction<NativeWasmerValtypeDeleteFn, WasmerValtypeDeleteFn>(
'wasm_valtype_delete',
);
_valtype_kind =
_lib.lookupFunction<NativeWasmerValtypeKindFn, WasmerValtypeKindFn>(
'wasm_valtype_kind',
);
_valtype_vec_delete = _lib.lookupFunction<NativeWasmerValtypeVecDeleteFn,
WasmerValtypeVecDeleteFn>(
'wasm_valtype_vec_delete',
);
_valtype_vec_new =
_lib.lookupFunction<NativeWasmerValtypeVecNewFn, WasmerValtypeVecNewFn>(
'wasm_valtype_vec_new',
);
_valtype_vec_new_empty = _lib.lookupFunction<
NativeWasmerValtypeVecNewEmptyFn, WasmerValtypeVecNewEmptyFn>(
'wasm_valtype_vec_new_empty',
);
_valtype_vec_new_uninitialized = _lib.lookupFunction<
NativeWasmerValtypeVecNewUninitializedFn,
WasmerValtypeVecNewUninitializedFn>(
'wasm_valtype_vec_new_uninitialized',
);
_wasmer_last_error_length = _lib.lookupFunction<
NativeWasmerWasmerLastErrorLengthFn, WasmerWasmerLastErrorLengthFn>(
'wasmer_last_error_length',
);
_wasmer_last_error_message = _lib.lookupFunction<
NativeWasmerWasmerLastErrorMessageFn, WasmerWasmerLastErrorMessageFn>(
'wasmer_last_error_message',
);
if (_Dart_InitializeApiDL(NativeApi.initializeApiDLData) != 0) {
throw WasmError('Failed to initialize Dart API');
}
_engine = _engine_new();
_checkNotEqual(_engine, nullptr, 'Failed to initialize Wasm engine.');
_set_finalizer_for_engine(this, _engine);
}
Pointer<WasmerStore> newStore(Object owner) {
var store = _checkNotEqual(
_store_new(_engine),
nullptr,
'Failed to create Wasm store.',
);
_set_finalizer_for_store(owner, store);
return store;
}
Pointer<WasmerModule> compile(
Object owner,
Pointer<WasmerStore> store,
Uint8List data,
) {
var dataPtr = calloc<Uint8>(data.length);
for (var i = 0; i < data.length; ++i) {
dataPtr[i] = data[i];
}
var dataVec = calloc<WasmerByteVec>();
dataVec.ref.data = dataPtr;
dataVec.ref.length = data.length;
var modulePtr = _module_new(store, dataVec);
calloc.free(dataPtr);
calloc.free(dataVec);
_checkNotEqual(modulePtr, nullptr, 'Wasm module compile failed.');
_set_finalizer_for_module(owner, modulePtr);
return modulePtr;
}
List<WasmExportDescriptor> exportDescriptors(Pointer<WasmerModule> module) {
var exportsVec = calloc<WasmerExporttypeVec>();
_module_exports(module, exportsVec);
var exps = <WasmExportDescriptor>[];
for (var i = 0; i < exportsVec.ref.length; ++i) {
var exp = exportsVec.ref.data[i];
var extern = _exporttype_type(exp);
var kind = _externtype_kind(extern);
var fnType = kind == wasmerExternKindFunction
? _externtype_as_functype(extern)
: nullptr;
exps.add(
WasmExportDescriptor._(
kind,
_exporttype_name(exp).ref.toString(),
fnType,
),
);
}
calloc.free(exportsVec);
return exps;
}
List<WasmImportDescriptor> importDescriptors(Pointer<WasmerModule> module) {
var importsVec = calloc<WasmerImporttypeVec>();
_module_imports(module, importsVec);
var imps = <WasmImportDescriptor>[];
for (var i = 0; i < importsVec.ref.length; ++i) {
var imp = importsVec.ref.data[i];
var extern = _importtype_type(imp);
var kind = _externtype_kind(extern);
var fnType = kind == wasmerExternKindFunction
? _externtype_as_functype(extern)
: nullptr;
imps.add(
WasmImportDescriptor._(
kind,
_importtype_module(imp).ref.toString(),
_importtype_name(imp).ref.toString(),
fnType,
),
);
}
calloc.free(importsVec);
return imps;
}
void maybeThrowTrap(Pointer<WasmerTrap> trap, String source) {
if (trap != nullptr) {
// There are 2 kinds of trap, and their memory is managed differently.
// Traps created in the newTrap method below are stored in the traps map
// with a corresponding exception, and their memory is managed using a
// finalizer on the _WasmTrapsEntry. Traps can also be created by WASM
// code, and in that case we delete them in this function.
var entry = _traps.remove(trap.address);
if (entry == null) {
throw WasmError(
'This case is not (yet) supported. Please file an issue on pkg:wasm.',
);
}
// ignore: only_throw_errors
throw entry.exception;
}
}
Pointer<WasmerInstance> instantiate(
Object owner,
Pointer<WasmerStore> store,
Pointer<WasmerModule> module,
Pointer<WasmerExternVec> imports,
) {
var trap = calloc<Pointer<WasmerTrap>>();
trap.value = nullptr;
var inst = _instance_new(store, module, imports, trap);
maybeThrowTrap(trap.value, 'module initialization function');
calloc.free(trap);
_checkNotEqual(inst, nullptr, 'Wasm module instantiation failed.');
_set_finalizer_for_instance(owner, inst);
return inst;
}
// Clean up the exports after use, with deleteExports.
Pointer<WasmerExternVec> exports(Pointer<WasmerInstance> instancePtr) {
var exports = calloc<WasmerExternVec>();
_instance_exports(instancePtr, exports);
return exports;
}
void deleteExports(Pointer<WasmerExternVec> exports) {
_extern_vec_delete(exports);
calloc.free(exports);
}
int externKind(Pointer<WasmerExtern> extern) => _extern_kind(extern);
Pointer<WasmerFunc> externToFunction(Pointer<WasmerExtern> extern) =>
_extern_as_func(extern);
Pointer<WasmerExtern> functionToExtern(Pointer<WasmerFunc> func) =>
_func_as_extern(func);
List<int> getArgTypes(Pointer<WasmerFunctype> funcType) {
var types = <int>[];
var args = _functype_params(funcType);
for (var i = 0; i < args.ref.length; ++i) {
types.add(_valtype_kind(args.ref.data[i]));
}
return types;
}
int getReturnType(Pointer<WasmerFunctype> funcType) {
var rets = _functype_results(funcType);
if (rets.ref.length == 0) {
return wasmerValKindVoid;
} else if (rets.ref.length > 1) {
throw WasmError('Multiple return values are not supported');
}
return _valtype_kind(rets.ref.data[0]);
}
void call(
Pointer<WasmerFunc> func,
Pointer<WasmerValVec> args,
Pointer<WasmerValVec> results,
String source,
) {
maybeThrowTrap(_func_call(func, args, results), source);
}
Pointer<WasmerMemory> externToMemory(Pointer<WasmerExtern> extern) =>
_extern_as_memory(extern);
Pointer<WasmerExtern> memoryToExtern(Pointer<WasmerMemory> memory) =>
_memory_as_extern(memory);
Pointer<WasmerMemory> newMemory(
Object owner,
Pointer<WasmerStore> store,
int pages,
int? maxPages,
) {
var limPtr = calloc<WasmerLimits>();
limPtr.ref.min = pages;
limPtr.ref.max = maxPages ?? wasmLimitsMaxDefault;
var memType = _memorytype_new(limPtr);
calloc.free(limPtr);
_checkNotEqual(memType, nullptr, 'Failed to create memory type.');
_set_finalizer_for_memorytype(owner, memType);
var memory = _checkNotEqual(
_memory_new(store, memType),
nullptr,
'Failed to create memory.',
);
_set_finalizer_for_memory(owner, memory);
return memory;
}
void growMemory(Pointer<WasmerMemory> memory, int deltaPages) {
_checkNotEqual(
_memory_grow(memory, deltaPages),
0,
'Failed to grow memory.',
);
}
int memoryLength(Pointer<WasmerMemory> memory) => _memory_size(memory);
Uint8List memoryView(Pointer<WasmerMemory> memory) =>
_memory_data(memory).asTypedList(_memory_data_size(memory));
Pointer<WasmerFunc> newFunc(
Object owner,
Pointer<WasmerStore> store,
Pointer<WasmerFunctype> funcType,
Pointer func,
Pointer env,
Pointer finalizer,
) {
var f = _func_new_with_env(
store,
funcType,
func.cast(),
env.cast(),
finalizer.cast(),
);
_checkNotEqual(f, nullptr, 'Failed to create function.');
_set_finalizer_for_func(owner, f);
return f;
}
Pointer<WasmerTrap> newTrap(Pointer<WasmerStore> store, Object exception) {
var msg = calloc<WasmerByteVec>();
msg.ref.data = calloc<Uint8>();
msg.ref.data[0] = 0;
msg.ref.length = 0;
var trap = _trap_new(store, msg);
calloc.free(msg.ref.data);
calloc.free(msg);
_checkNotEqual(trap, nullptr, 'Failed to create trap.');
var entry = _WasmTrapsEntry(exception);
_set_finalizer_for_trap(entry, trap);
_traps[trap.address] = entry;
return trap;
}
Pointer<WasmerWasiConfig> newWasiConfig() {
var name = calloc<Uint8>();
name[0] = 0;
var config = _wasi_config_new(name);
calloc.free(name);
return _checkNotEqual(config, nullptr, 'Failed to create WASI config.');
}
void captureWasiStdout(Pointer<WasmerWasiConfig> config) {
_wasi_config_inherit_stdout(config);
}
void captureWasiStderr(Pointer<WasmerWasiConfig> config) {
_wasi_config_inherit_stderr(config);
}
Pointer<WasmerWasiEnv> newWasiEnv(Pointer<WasmerWasiConfig> config) =>
_checkNotEqual(
_wasi_env_new(config),
nullptr,
'Failed to create WASI environment.',
);
void wasiEnvSetMemory(
Pointer<WasmerWasiEnv> env,
Pointer<WasmerMemory> memory,
) {
_wasi_env_set_memory(env, memory);
}
void getWasiImports(
Pointer<WasmerStore> store,
Pointer<WasmerModule> mod,
Pointer<WasmerWasiEnv> env,
Pointer<WasmerExternVec> imports,
) {
_checkNotEqual(
_wasi_get_imports(store, mod, env, imports),
0,
'Failed to fill WASI imports.',
);
}
Stream<List<int>> getWasiStdoutStream(Pointer<WasmerWasiEnv> env) =>
Stream.fromIterable(_WasiStreamIterable(env, _wasi_env_read_stdout));
Stream<List<int>> getWasiStderrStream(Pointer<WasmerWasiEnv> env) =>
Stream.fromIterable(_WasiStreamIterable(env, _wasi_env_read_stderr));
String _getLastError() {
var length = _wasmer_last_error_length();
var buf = calloc<Uint8>(length);
_wasmer_last_error_message(buf, length);
var message = utf8.decode(buf.asTypedList(length));
calloc.free(buf);
return message;
}
T _checkNotEqual<T>(T x, T y, String errorMessage) {
if (x == y) {
throw WasmError('$errorMessage\n${_getLastError()}'.trim());
}
return x;
}
static String getSignatureString(
String name,
List<int> argTypes,
int returnType,
) =>
'${wasmerValKindName(returnType)} '
"$name(${argTypes.map(wasmerValKindName).join(", ")})";
}

View file

@ -1,22 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
const invocationString = 'dart run wasm:setup';
const pkgConfigFile = '.dart_tool/package_config.json';
const wasmToolDir = '.dart_tool/wasm/';
const appleLib = 'libwasmer.dylib';
const linuxLib = 'libwasmer.so';
Uri? packageRootUri(Uri root) {
do {
if (FileSystemEntity.isFileSync(root.resolve(pkgConfigFile).path)) {
return root;
}
} while (root != (root = root.resolve('..')));
return null;
}

View file

@ -1,14 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// Error specific to unexpected behavior or incorrect usage of this package.
class WasmError extends Error {
/// Describes the nature of the error.
final String message;
WasmError(this.message) : assert(message.trim() == message);
@override
String toString() => 'WasmError:$message';
}

View file

@ -1,130 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use the following command
// "generate_ffi_boilerplate.py".
import 'dart:convert';
import 'dart:ffi';
import 'dart:typed_data';
part 'wasmer_api.g.dart';
// wasm_valkind_enum
const int wasmerValKindI32 = 0;
const int wasmerValKindI64 = 1;
const int wasmerValKindF32 = 2;
const int wasmerValKindF64 = 3;
// The void tag is not part of the C API. It's used to represent the return type
// of a void function.
const int wasmerValKindVoid = -1;
// wasm_externkind_enum
const int wasmerExternKindFunction = 0;
const int wasmerExternKindGlobal = 1;
const int wasmerExternKindTable = 2;
const int wasmerExternKindMemory = 3;
String wasmerExternKindName(int kind) {
switch (kind) {
case wasmerExternKindFunction:
return 'function';
case wasmerExternKindGlobal:
return 'global';
case wasmerExternKindTable:
return 'table';
case wasmerExternKindMemory:
return 'memory';
default:
return 'unknown';
}
}
String wasmerValKindName(int kind) {
switch (kind) {
case wasmerValKindI32:
return 'int32';
case wasmerValKindI64:
return 'int64';
case wasmerValKindF32:
return 'float32';
case wasmerValKindF64:
return 'float64';
case wasmerValKindVoid:
return 'void';
default:
return 'unknown';
}
}
// wasm_val_t
class WasmerVal extends Struct {
// wasm_valkind_t
@Uint8()
external int kind;
// This is a union of int32_t, int64_t, float, and double. The kind determines
// which type it is. It's declared as an int64_t because that's large enough
// to hold all the types. We use ByteData to get the other types.
@Int64()
external int value;
int get _off32 => Endian.host == Endian.little ? 0 : 4;
int get i64 => value;
ByteData get _getterBytes => ByteData(8)..setInt64(0, value, Endian.host);
int get i32 => _getterBytes.getInt32(_off32, Endian.host);
double get f32 => _getterBytes.getFloat32(_off32, Endian.host);
double get f64 => _getterBytes.getFloat64(0, Endian.host);
set i64(int val) => value = val;
set _val(ByteData bytes) => value = bytes.getInt64(0, Endian.host);
set i32(int val) => _val = ByteData(8)..setInt32(_off32, val, Endian.host);
set f32(num val) =>
_val = ByteData(8)..setFloat32(_off32, val as double, Endian.host);
set f64(num val) =>
_val = ByteData(8)..setFloat64(0, val as double, Endian.host);
bool get isI32 => kind == wasmerValKindI32;
bool get isI64 => kind == wasmerValKindI64;
bool get isF32 => kind == wasmerValKindF32;
bool get isF64 => kind == wasmerValKindF64;
dynamic get toDynamic {
switch (kind) {
case wasmerValKindI32:
return i32;
case wasmerValKindI64:
return i64;
case wasmerValKindF32:
return f32;
case wasmerValKindF64:
return f64;
}
}
}
// wasmer_limits_t
class WasmerLimits extends Struct {
@Uint32()
external int min;
@Uint32()
external int max;
}
// Default maximum, which indicates no upper limit.
const int wasmLimitsMaxDefault = 0xffffffff;

View file

@ -1,577 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use the following command
// "generate_ffi_boilerplate.py".
// ignore_for_file: require_trailing_commas
part of 'wasmer_api.dart';
// wasm_engine_t
class WasmerEngine extends Opaque {}
// wasm_exporttype_t
class WasmerExporttype extends Opaque {}
// wasm_extern_t
class WasmerExtern extends Opaque {}
// wasm_externtype_t
class WasmerExterntype extends Opaque {}
// wasm_func_t
class WasmerFunc extends Opaque {}
// wasm_functype_t
class WasmerFunctype extends Opaque {}
// wasm_importtype_t
class WasmerImporttype extends Opaque {}
// wasm_instance_t
class WasmerInstance extends Opaque {}
// wasm_memory_t
class WasmerMemory extends Opaque {}
// wasm_memorytype_t
class WasmerMemorytype extends Opaque {}
// wasm_module_t
class WasmerModule extends Opaque {}
// wasm_store_t
class WasmerStore extends Opaque {}
// wasm_trap_t
class WasmerTrap extends Opaque {}
// wasm_valtype_t
class WasmerValtype extends Opaque {}
// wasi_config_t
class WasmerWasiConfig extends Opaque {}
// wasi_env_t
class WasmerWasiEnv extends Opaque {}
// wasm_byte_vec_t
class WasmerByteVec extends Struct {
@Uint64()
external int length;
external Pointer<Uint8> data;
Uint8List get list => data.asTypedList(length);
@override
String toString() => utf8.decode(list);
}
// wasm_exporttype_vec_t
class WasmerExporttypeVec extends Struct {
@Uint64()
external int length;
external Pointer<Pointer<WasmerExporttype>> data;
}
// wasm_extern_vec_t
class WasmerExternVec extends Struct {
@Uint64()
external int length;
external Pointer<Pointer<WasmerExtern>> data;
}
// wasm_importtype_vec_t
class WasmerImporttypeVec extends Struct {
@Uint64()
external int length;
external Pointer<Pointer<WasmerImporttype>> data;
}
// wasm_val_vec_t
class WasmerValVec extends Struct {
@Uint64()
external int length;
external Pointer<WasmerVal> data;
}
// wasm_valtype_vec_t
class WasmerValtypeVec extends Struct {
@Uint64()
external int length;
external Pointer<Pointer<WasmerValtype>> data;
}
// Dart_InitializeApiDL
typedef NativeWasmerDartInitializeApiDLFn = Int64 Function(Pointer<Void>);
typedef WasmerDartInitializeApiDLFn = int Function(Pointer<Void>);
// set_finalizer_for_engine
typedef NativeWasmerSetFinalizerForEngineFn = Void Function(
Handle, Pointer<WasmerEngine>);
typedef WasmerSetFinalizerForEngineFn = void Function(
Object, Pointer<WasmerEngine>);
// set_finalizer_for_func
typedef NativeWasmerSetFinalizerForFuncFn = Void Function(
Handle, Pointer<WasmerFunc>);
typedef WasmerSetFinalizerForFuncFn = void Function(
Object, Pointer<WasmerFunc>);
// set_finalizer_for_instance
typedef NativeWasmerSetFinalizerForInstanceFn = Void Function(
Handle, Pointer<WasmerInstance>);
typedef WasmerSetFinalizerForInstanceFn = void Function(
Object, Pointer<WasmerInstance>);
// set_finalizer_for_memory
typedef NativeWasmerSetFinalizerForMemoryFn = Void Function(
Handle, Pointer<WasmerMemory>);
typedef WasmerSetFinalizerForMemoryFn = void Function(
Object, Pointer<WasmerMemory>);
// set_finalizer_for_memorytype
typedef NativeWasmerSetFinalizerForMemorytypeFn = Void Function(
Handle, Pointer<WasmerMemorytype>);
typedef WasmerSetFinalizerForMemorytypeFn = void Function(
Object, Pointer<WasmerMemorytype>);
// set_finalizer_for_module
typedef NativeWasmerSetFinalizerForModuleFn = Void Function(
Handle, Pointer<WasmerModule>);
typedef WasmerSetFinalizerForModuleFn = void Function(
Object, Pointer<WasmerModule>);
// set_finalizer_for_store
typedef NativeWasmerSetFinalizerForStoreFn = Void Function(
Handle, Pointer<WasmerStore>);
typedef WasmerSetFinalizerForStoreFn = void Function(
Object, Pointer<WasmerStore>);
// set_finalizer_for_trap
typedef NativeWasmerSetFinalizerForTrapFn = Void Function(
Handle, Pointer<WasmerTrap>);
typedef WasmerSetFinalizerForTrapFn = void Function(
Object, Pointer<WasmerTrap>);
// wasi_config_inherit_stderr
typedef NativeWasmerWasiConfigInheritStderrFn = Void Function(
Pointer<WasmerWasiConfig>);
typedef WasmerWasiConfigInheritStderrFn = void Function(
Pointer<WasmerWasiConfig>);
// wasi_config_inherit_stdout
typedef NativeWasmerWasiConfigInheritStdoutFn = Void Function(
Pointer<WasmerWasiConfig>);
typedef WasmerWasiConfigInheritStdoutFn = void Function(
Pointer<WasmerWasiConfig>);
// wasi_config_new
typedef NativeWasmerWasiConfigNewFn = Pointer<WasmerWasiConfig> Function(
Pointer<Uint8>);
typedef WasmerWasiConfigNewFn = Pointer<WasmerWasiConfig> Function(
Pointer<Uint8>);
// wasi_env_delete
typedef NativeWasmerWasiEnvDeleteFn = Void Function(Pointer<WasmerWasiEnv>);
typedef WasmerWasiEnvDeleteFn = void Function(Pointer<WasmerWasiEnv>);
// wasi_env_new
typedef NativeWasmerWasiEnvNewFn = Pointer<WasmerWasiEnv> Function(
Pointer<WasmerWasiConfig>);
typedef WasmerWasiEnvNewFn = Pointer<WasmerWasiEnv> Function(
Pointer<WasmerWasiConfig>);
// wasi_env_read_stderr
typedef NativeWasmerWasiEnvReadStderrFn = Int64 Function(
Pointer<WasmerWasiEnv>, Pointer<Uint8>, Uint64);
typedef WasmerWasiEnvReadStderrFn = int Function(
Pointer<WasmerWasiEnv>, Pointer<Uint8>, int);
// wasi_env_read_stdout
typedef NativeWasmerWasiEnvReadStdoutFn = Int64 Function(
Pointer<WasmerWasiEnv>, Pointer<Uint8>, Uint64);
typedef WasmerWasiEnvReadStdoutFn = int Function(
Pointer<WasmerWasiEnv>, Pointer<Uint8>, int);
// wasi_env_set_memory
typedef NativeWasmerWasiEnvSetMemoryFn = Void Function(
Pointer<WasmerWasiEnv>, Pointer<WasmerMemory>);
typedef WasmerWasiEnvSetMemoryFn = void Function(
Pointer<WasmerWasiEnv>, Pointer<WasmerMemory>);
// wasi_get_imports
typedef NativeWasmerWasiGetImportsFn = Uint8 Function(Pointer<WasmerStore>,
Pointer<WasmerModule>, Pointer<WasmerWasiEnv>, Pointer<WasmerExternVec>);
typedef WasmerWasiGetImportsFn = int Function(Pointer<WasmerStore>,
Pointer<WasmerModule>, Pointer<WasmerWasiEnv>, Pointer<WasmerExternVec>);
// wasm_byte_vec_delete
typedef NativeWasmerByteVecDeleteFn = Void Function(Pointer<WasmerByteVec>);
typedef WasmerByteVecDeleteFn = void Function(Pointer<WasmerByteVec>);
// wasm_byte_vec_new
typedef NativeWasmerByteVecNewFn = Void Function(
Pointer<WasmerByteVec>, Uint64, Pointer<Uint8>);
typedef WasmerByteVecNewFn = void Function(
Pointer<WasmerByteVec>, int, Pointer<Uint8>);
// wasm_byte_vec_new_empty
typedef NativeWasmerByteVecNewEmptyFn = Void Function(Pointer<WasmerByteVec>);
typedef WasmerByteVecNewEmptyFn = void Function(Pointer<WasmerByteVec>);
// wasm_byte_vec_new_uninitialized
typedef NativeWasmerByteVecNewUninitializedFn = Void Function(
Pointer<WasmerByteVec>, Uint64);
typedef WasmerByteVecNewUninitializedFn = void Function(
Pointer<WasmerByteVec>, int);
// wasm_engine_delete
typedef NativeWasmerEngineDeleteFn = Void Function(Pointer<WasmerEngine>);
typedef WasmerEngineDeleteFn = void Function(Pointer<WasmerEngine>);
// wasm_engine_new
typedef NativeWasmerEngineNewFn = Pointer<WasmerEngine> Function();
typedef WasmerEngineNewFn = Pointer<WasmerEngine> Function();
// wasm_exporttype_name
typedef NativeWasmerExporttypeNameFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerExporttype>);
typedef WasmerExporttypeNameFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerExporttype>);
// wasm_exporttype_type
typedef NativeWasmerExporttypeTypeFn = Pointer<WasmerExterntype> Function(
Pointer<WasmerExporttype>);
typedef WasmerExporttypeTypeFn = Pointer<WasmerExterntype> Function(
Pointer<WasmerExporttype>);
// wasm_exporttype_vec_delete
typedef NativeWasmerExporttypeVecDeleteFn = Void Function(
Pointer<WasmerExporttypeVec>);
typedef WasmerExporttypeVecDeleteFn = void Function(
Pointer<WasmerExporttypeVec>);
// wasm_exporttype_vec_new
typedef NativeWasmerExporttypeVecNewFn = Void Function(
Pointer<WasmerExporttypeVec>, Uint64, Pointer<Pointer<WasmerExporttype>>);
typedef WasmerExporttypeVecNewFn = void Function(
Pointer<WasmerExporttypeVec>, int, Pointer<Pointer<WasmerExporttype>>);
// wasm_exporttype_vec_new_empty
typedef NativeWasmerExporttypeVecNewEmptyFn = Void Function(
Pointer<WasmerExporttypeVec>);
typedef WasmerExporttypeVecNewEmptyFn = void Function(
Pointer<WasmerExporttypeVec>);
// wasm_exporttype_vec_new_uninitialized
typedef NativeWasmerExporttypeVecNewUninitializedFn = Void Function(
Pointer<WasmerExporttypeVec>, Uint64);
typedef WasmerExporttypeVecNewUninitializedFn = void Function(
Pointer<WasmerExporttypeVec>, int);
// wasm_extern_as_func
typedef NativeWasmerExternAsFuncFn = Pointer<WasmerFunc> Function(
Pointer<WasmerExtern>);
typedef WasmerExternAsFuncFn = Pointer<WasmerFunc> Function(
Pointer<WasmerExtern>);
// wasm_extern_as_memory
typedef NativeWasmerExternAsMemoryFn = Pointer<WasmerMemory> Function(
Pointer<WasmerExtern>);
typedef WasmerExternAsMemoryFn = Pointer<WasmerMemory> Function(
Pointer<WasmerExtern>);
// wasm_extern_delete
typedef NativeWasmerExternDeleteFn = Void Function(Pointer<WasmerExtern>);
typedef WasmerExternDeleteFn = void Function(Pointer<WasmerExtern>);
// wasm_extern_kind
typedef NativeWasmerExternKindFn = Uint8 Function(Pointer<WasmerExtern>);
typedef WasmerExternKindFn = int Function(Pointer<WasmerExtern>);
// wasm_extern_vec_delete
typedef NativeWasmerExternVecDeleteFn = Void Function(Pointer<WasmerExternVec>);
typedef WasmerExternVecDeleteFn = void Function(Pointer<WasmerExternVec>);
// wasm_extern_vec_new
typedef NativeWasmerExternVecNewFn = Void Function(
Pointer<WasmerExternVec>, Uint64, Pointer<Pointer<WasmerExtern>>);
typedef WasmerExternVecNewFn = void Function(
Pointer<WasmerExternVec>, int, Pointer<Pointer<WasmerExtern>>);
// wasm_extern_vec_new_empty
typedef NativeWasmerExternVecNewEmptyFn = Void Function(
Pointer<WasmerExternVec>);
typedef WasmerExternVecNewEmptyFn = void Function(Pointer<WasmerExternVec>);
// wasm_extern_vec_new_uninitialized
typedef NativeWasmerExternVecNewUninitializedFn = Void Function(
Pointer<WasmerExternVec>, Uint64);
typedef WasmerExternVecNewUninitializedFn = void Function(
Pointer<WasmerExternVec>, int);
// wasm_externtype_as_functype
typedef NativeWasmerExterntypeAsFunctypeFn = Pointer<WasmerFunctype> Function(
Pointer<WasmerExterntype>);
typedef WasmerExterntypeAsFunctypeFn = Pointer<WasmerFunctype> Function(
Pointer<WasmerExterntype>);
// wasm_externtype_delete
typedef NativeWasmerExterntypeDeleteFn = Void Function(
Pointer<WasmerExterntype>);
typedef WasmerExterntypeDeleteFn = void Function(Pointer<WasmerExterntype>);
// wasm_externtype_kind
typedef NativeWasmerExterntypeKindFn = Uint8 Function(
Pointer<WasmerExterntype>);
typedef WasmerExterntypeKindFn = int Function(Pointer<WasmerExterntype>);
// wasm_func_as_extern
typedef NativeWasmerFuncAsExternFn = Pointer<WasmerExtern> Function(
Pointer<WasmerFunc>);
typedef WasmerFuncAsExternFn = Pointer<WasmerExtern> Function(
Pointer<WasmerFunc>);
// wasm_func_call
typedef NativeWasmerFuncCallFn = Pointer<WasmerTrap> Function(
Pointer<WasmerFunc>, Pointer<WasmerValVec>, Pointer<WasmerValVec>);
typedef WasmerFuncCallFn = Pointer<WasmerTrap> Function(
Pointer<WasmerFunc>, Pointer<WasmerValVec>, Pointer<WasmerValVec>);
// wasm_func_delete
typedef NativeWasmerFuncDeleteFn = Void Function(Pointer<WasmerFunc>);
typedef WasmerFuncDeleteFn = void Function(Pointer<WasmerFunc>);
// wasm_func_new_with_env
typedef NativeWasmerFuncNewWithEnvFn = Pointer<WasmerFunc> Function(
Pointer<WasmerStore>,
Pointer<WasmerFunctype>,
Pointer<Void>,
Pointer<Void>,
Pointer<Void>);
typedef WasmerFuncNewWithEnvFn = Pointer<WasmerFunc> Function(
Pointer<WasmerStore>,
Pointer<WasmerFunctype>,
Pointer<Void>,
Pointer<Void>,
Pointer<Void>);
// wasm_functype_delete
typedef NativeWasmerFunctypeDeleteFn = Void Function(Pointer<WasmerFunctype>);
typedef WasmerFunctypeDeleteFn = void Function(Pointer<WasmerFunctype>);
// wasm_functype_params
typedef NativeWasmerFunctypeParamsFn = Pointer<WasmerValtypeVec> Function(
Pointer<WasmerFunctype>);
typedef WasmerFunctypeParamsFn = Pointer<WasmerValtypeVec> Function(
Pointer<WasmerFunctype>);
// wasm_functype_results
typedef NativeWasmerFunctypeResultsFn = Pointer<WasmerValtypeVec> Function(
Pointer<WasmerFunctype>);
typedef WasmerFunctypeResultsFn = Pointer<WasmerValtypeVec> Function(
Pointer<WasmerFunctype>);
// wasm_importtype_module
typedef NativeWasmerImporttypeModuleFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerImporttype>);
typedef WasmerImporttypeModuleFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerImporttype>);
// wasm_importtype_name
typedef NativeWasmerImporttypeNameFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerImporttype>);
typedef WasmerImporttypeNameFn = Pointer<WasmerByteVec> Function(
Pointer<WasmerImporttype>);
// wasm_importtype_type
typedef NativeWasmerImporttypeTypeFn = Pointer<WasmerExterntype> Function(
Pointer<WasmerImporttype>);
typedef WasmerImporttypeTypeFn = Pointer<WasmerExterntype> Function(
Pointer<WasmerImporttype>);
// wasm_importtype_vec_delete
typedef NativeWasmerImporttypeVecDeleteFn = Void Function(
Pointer<WasmerImporttypeVec>);
typedef WasmerImporttypeVecDeleteFn = void Function(
Pointer<WasmerImporttypeVec>);
// wasm_importtype_vec_new
typedef NativeWasmerImporttypeVecNewFn = Void Function(
Pointer<WasmerImporttypeVec>, Uint64, Pointer<Pointer<WasmerImporttype>>);
typedef WasmerImporttypeVecNewFn = void Function(
Pointer<WasmerImporttypeVec>, int, Pointer<Pointer<WasmerImporttype>>);
// wasm_importtype_vec_new_empty
typedef NativeWasmerImporttypeVecNewEmptyFn = Void Function(
Pointer<WasmerImporttypeVec>);
typedef WasmerImporttypeVecNewEmptyFn = void Function(
Pointer<WasmerImporttypeVec>);
// wasm_importtype_vec_new_uninitialized
typedef NativeWasmerImporttypeVecNewUninitializedFn = Void Function(
Pointer<WasmerImporttypeVec>, Uint64);
typedef WasmerImporttypeVecNewUninitializedFn = void Function(
Pointer<WasmerImporttypeVec>, int);
// wasm_instance_delete
typedef NativeWasmerInstanceDeleteFn = Void Function(Pointer<WasmerInstance>);
typedef WasmerInstanceDeleteFn = void Function(Pointer<WasmerInstance>);
// wasm_instance_exports
typedef NativeWasmerInstanceExportsFn = Void Function(
Pointer<WasmerInstance>, Pointer<WasmerExternVec>);
typedef WasmerInstanceExportsFn = void Function(
Pointer<WasmerInstance>, Pointer<WasmerExternVec>);
// wasm_instance_new
typedef NativeWasmerInstanceNewFn = Pointer<WasmerInstance> Function(
Pointer<WasmerStore>,
Pointer<WasmerModule>,
Pointer<WasmerExternVec>,
Pointer<Pointer<WasmerTrap>>);
typedef WasmerInstanceNewFn = Pointer<WasmerInstance> Function(
Pointer<WasmerStore>,
Pointer<WasmerModule>,
Pointer<WasmerExternVec>,
Pointer<Pointer<WasmerTrap>>);
// wasm_memory_as_extern
typedef NativeWasmerMemoryAsExternFn = Pointer<WasmerExtern> Function(
Pointer<WasmerMemory>);
typedef WasmerMemoryAsExternFn = Pointer<WasmerExtern> Function(
Pointer<WasmerMemory>);
// wasm_memory_data
typedef NativeWasmerMemoryDataFn = Pointer<Uint8> Function(
Pointer<WasmerMemory>);
typedef WasmerMemoryDataFn = Pointer<Uint8> Function(Pointer<WasmerMemory>);
// wasm_memory_data_size
typedef NativeWasmerMemoryDataSizeFn = Uint64 Function(Pointer<WasmerMemory>);
typedef WasmerMemoryDataSizeFn = int Function(Pointer<WasmerMemory>);
// wasm_memory_delete
typedef NativeWasmerMemoryDeleteFn = Void Function(Pointer<WasmerMemory>);
typedef WasmerMemoryDeleteFn = void Function(Pointer<WasmerMemory>);
// wasm_memory_grow
typedef NativeWasmerMemoryGrowFn = Uint8 Function(
Pointer<WasmerMemory>, Uint32);
typedef WasmerMemoryGrowFn = int Function(Pointer<WasmerMemory>, int);
// wasm_memory_new
typedef NativeWasmerMemoryNewFn = Pointer<WasmerMemory> Function(
Pointer<WasmerStore>, Pointer<WasmerMemorytype>);
typedef WasmerMemoryNewFn = Pointer<WasmerMemory> Function(
Pointer<WasmerStore>, Pointer<WasmerMemorytype>);
// wasm_memory_size
typedef NativeWasmerMemorySizeFn = Uint32 Function(Pointer<WasmerMemory>);
typedef WasmerMemorySizeFn = int Function(Pointer<WasmerMemory>);
// wasm_memorytype_delete
typedef NativeWasmerMemorytypeDeleteFn = Void Function(
Pointer<WasmerMemorytype>);
typedef WasmerMemorytypeDeleteFn = void Function(Pointer<WasmerMemorytype>);
// wasm_memorytype_new
typedef NativeWasmerMemorytypeNewFn = Pointer<WasmerMemorytype> Function(
Pointer<WasmerLimits>);
typedef WasmerMemorytypeNewFn = Pointer<WasmerMemorytype> Function(
Pointer<WasmerLimits>);
// wasm_module_delete
typedef NativeWasmerModuleDeleteFn = Void Function(Pointer<WasmerModule>);
typedef WasmerModuleDeleteFn = void Function(Pointer<WasmerModule>);
// wasm_module_exports
typedef NativeWasmerModuleExportsFn = Void Function(
Pointer<WasmerModule>, Pointer<WasmerExporttypeVec>);
typedef WasmerModuleExportsFn = void Function(
Pointer<WasmerModule>, Pointer<WasmerExporttypeVec>);
// wasm_module_imports
typedef NativeWasmerModuleImportsFn = Void Function(
Pointer<WasmerModule>, Pointer<WasmerImporttypeVec>);
typedef WasmerModuleImportsFn = void Function(
Pointer<WasmerModule>, Pointer<WasmerImporttypeVec>);
// wasm_module_new
typedef NativeWasmerModuleNewFn = Pointer<WasmerModule> Function(
Pointer<WasmerStore>, Pointer<WasmerByteVec>);
typedef WasmerModuleNewFn = Pointer<WasmerModule> Function(
Pointer<WasmerStore>, Pointer<WasmerByteVec>);
// wasm_store_delete
typedef NativeWasmerStoreDeleteFn = Void Function(Pointer<WasmerStore>);
typedef WasmerStoreDeleteFn = void Function(Pointer<WasmerStore>);
// wasm_store_new
typedef NativeWasmerStoreNewFn = Pointer<WasmerStore> Function(
Pointer<WasmerEngine>);
typedef WasmerStoreNewFn = Pointer<WasmerStore> Function(Pointer<WasmerEngine>);
// wasm_trap_delete
typedef NativeWasmerTrapDeleteFn = Void Function(Pointer<WasmerTrap>);
typedef WasmerTrapDeleteFn = void Function(Pointer<WasmerTrap>);
// wasm_trap_message
typedef NativeWasmerTrapMessageFn = Void Function(
Pointer<WasmerTrap>, Pointer<WasmerByteVec>);
typedef WasmerTrapMessageFn = void Function(
Pointer<WasmerTrap>, Pointer<WasmerByteVec>);
// wasm_trap_new
typedef NativeWasmerTrapNewFn = Pointer<WasmerTrap> Function(
Pointer<WasmerStore>, Pointer<WasmerByteVec>);
typedef WasmerTrapNewFn = Pointer<WasmerTrap> Function(
Pointer<WasmerStore>, Pointer<WasmerByteVec>);
// wasm_valtype_delete
typedef NativeWasmerValtypeDeleteFn = Void Function(Pointer<WasmerValtype>);
typedef WasmerValtypeDeleteFn = void Function(Pointer<WasmerValtype>);
// wasm_valtype_kind
typedef NativeWasmerValtypeKindFn = Uint8 Function(Pointer<WasmerValtype>);
typedef WasmerValtypeKindFn = int Function(Pointer<WasmerValtype>);
// wasm_valtype_vec_delete
typedef NativeWasmerValtypeVecDeleteFn = Void Function(
Pointer<WasmerValtypeVec>);
typedef WasmerValtypeVecDeleteFn = void Function(Pointer<WasmerValtypeVec>);
// wasm_valtype_vec_new
typedef NativeWasmerValtypeVecNewFn = Void Function(
Pointer<WasmerValtypeVec>, Uint64, Pointer<Pointer<WasmerValtype>>);
typedef WasmerValtypeVecNewFn = void Function(
Pointer<WasmerValtypeVec>, int, Pointer<Pointer<WasmerValtype>>);
// wasm_valtype_vec_new_empty
typedef NativeWasmerValtypeVecNewEmptyFn = Void Function(
Pointer<WasmerValtypeVec>);
typedef WasmerValtypeVecNewEmptyFn = void Function(Pointer<WasmerValtypeVec>);
// wasm_valtype_vec_new_uninitialized
typedef NativeWasmerValtypeVecNewUninitializedFn = Void Function(
Pointer<WasmerValtypeVec>, Uint64);
typedef WasmerValtypeVecNewUninitializedFn = void Function(
Pointer<WasmerValtypeVec>, int);
// wasmer_last_error_length
typedef NativeWasmerWasmerLastErrorLengthFn = Int64 Function();
typedef WasmerWasmerLastErrorLengthFn = int Function();
// wasmer_last_error_message
typedef NativeWasmerWasmerLastErrorMessageFn = Int64 Function(
Pointer<Uint8>, Int64);
typedef WasmerWasmerLastErrorMessageFn = int Function(Pointer<Uint8>, int);

View file

@ -1,6 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
export 'src/module.dart';
export 'src/wasm_error.dart';

View file

@ -1,14 +0,0 @@
name: wasm
version: 0.1.0
description: Utilities for loading and running WASM modules from Dart code
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/wasm
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
ffi: ^1.0.0
dev_dependencies:
lints: ^1.0.0
test: ^1.16.0

View file

@ -1,32 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we can load a wasm module, find a function, and call it.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('basics', () {
// int64_t square(int64_t n) { return n * n; }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, //
0x01, 0x7e, 0x01, 0x7e, 0x03, 0x02, 0x01, 0x00, 0x04, 0x05, 0x01, 0x70,
0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x02, 0x06, 0x08, 0x01, 0x7f,
0x01, 0x41, 0x80, 0x88, 0x04, 0x0b, 0x07, 0x13, 0x02, 0x06, 0x6d, 0x65,
0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x06, 0x73, 0x71, 0x75, 0x61, 0x72,
0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x20, 0x00,
0x7e, 0x0b,
]);
var inst = WasmModule(data).builder().build();
var fn = inst.lookupFunction('square');
var n = fn(1234) as int;
expect(n, 1234 * 1234);
expect(inst.lookupFunction('not_a_function'), isNull);
});
}

View file

@ -1,32 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test error thrown when the wasm module is corrupted.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
import 'test_shared.dart';
void main() {
test('corrupted module', () {
var data = Uint8List.fromList([
0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, 0x01, 0x7e, 0x01, 0x7e, //
0x07, 0x13, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,
0x06, 0x73, 0x71, 0x75, 0x61, 0x72, 0x65, 0x00, 0x00, 0x00, 0x20, 0x00,
0x7e, 0x0b,
]);
expect(
() => WasmModule(data),
throwsWasmError(
allOf(
contains('Wasm module compile failed.'),
contains('Validation error: Bad magic number (at offset 0)'),
),
),
);
});
}

View file

@ -1,32 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
// Test error thrown when a function is called with the wrong args.
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('function with wrong arguments', () {
// int64_t square(int64_t n) { return n * n; }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60, //
0x01, 0x7e, 0x01, 0x7e, 0x03, 0x02, 0x01, 0x00, 0x04, 0x05, 0x01, 0x70,
0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x02, 0x06, 0x08, 0x01, 0x7f,
0x01, 0x41, 0x80, 0x88, 0x04, 0x0b, 0x07, 0x13, 0x02, 0x06, 0x6d, 0x65,
0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x06, 0x73, 0x71, 0x75, 0x61, 0x72,
0x65, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, 0x00, 0x20, 0x00,
0x7e, 0x0b,
]);
var inst = WasmModule(data).builder().build();
var fn = inst.lookupFunction('square');
expect(() => fn(), throwsA(isArgumentError));
expect(() => fn(1, 2, 3), throwsA(isArgumentError));
expect(() => fn(1.23), throwsA(isArgumentError));
});
}

View file

@ -1,95 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
// Test errors thrown by function imports.
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
import 'test_shared.dart';
void main() {
test('bad function imports', () {
// This module expects a function import like:
// int64_t someFn(int32_t a, int64_t b, float c, double d);
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x02, 0x60, //
0x04, 0x7f, 0x7e, 0x7d, 0x7c, 0x01, 0x7e, 0x60, 0x00, 0x00, 0x02, 0x0e,
0x01, 0x03, 0x65, 0x6e, 0x76, 0x06, 0x73, 0x6f, 0x6d, 0x65, 0x46, 0x6e,
0x00, 0x00, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01,
0x01, 0x05, 0x03, 0x01, 0x00, 0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41,
0x80, 0x88, 0x04, 0x0b, 0x07, 0x11, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f,
0x72, 0x79, 0x02, 0x00, 0x04, 0x62, 0x6c, 0x61, 0x68, 0x00, 0x01, 0x0a,
0x1d, 0x01, 0x1b, 0x00, 0x41, 0x01, 0x42, 0x02, 0x43, 0x00, 0x00, 0x40,
0x40, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x40, 0x10, 0x80,
0x80, 0x80, 0x80, 0x00, 0x1a, 0x0b,
]);
var mod = WasmModule(data);
// Valid instantiation.
(mod.builder()
..addFunction(
'env',
'someFn',
(int a, int b, num c, double d) => 123,
))
.build();
// Missing imports.
expect(
() => mod.builder().build(),
throwsWasmError(startsWith('Missing import')),
);
// Wrong kind of import.
expect(
() => mod.builder().addMemory('env', 'someFn', mod.createMemory(10)),
throwsWasmError(startsWith('Import is not a memory:')),
);
// Wrong namespace.
expect(
() => (mod.builder()
..addFunction(
'foo',
'someFn',
(int a, int b, num c, double d) => 123,
))
.build(),
throwsWasmError(startsWith('Import not found:')),
);
// Wrong name.
expect(
() => (mod.builder()
..addFunction(
'env',
'otherFn',
(int a, int b, num c, double d) => 123,
))
.build(),
throwsWasmError(startsWith('Import not found:')),
);
// Already filled.
expect(
() => (mod.builder()
..addFunction(
'env',
'someFn',
(int a, int b, num c, double d) => 123,
)
..addFunction(
'env',
'someFn',
(int a, int b, num c, double d) => 456,
))
.build(),
throwsWasmError(startsWith('Import already filled: env::someFn')),
);
});
}

View file

@ -1,48 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test throwing exceptions from an imported function.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('exception thrown from imported function', () {
// void fn() {
// a();
// b();
// }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x04, 0x01, 0x60, //
0x00, 0x00, 0x02, 0x11, 0x02, 0x03, 0x65, 0x6e, 0x76, 0x01, 0x61, 0x00,
0x00, 0x03, 0x65, 0x6e, 0x76, 0x01, 0x62, 0x00, 0x00, 0x03, 0x02, 0x01,
0x00, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00,
0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41, 0x80, 0x88, 0x04, 0x0b, 0x07,
0x0f, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x02,
0x66, 0x6e, 0x00, 0x02, 0x0a, 0x10, 0x01, 0x0e, 0x00, 0x10, 0x80, 0x80,
0x80, 0x80, 0x00, 0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x0b,
]);
var thrownException = Exception('Hello exception!');
var inst = (WasmModule(data).builder()
..addFunction('env', 'a', () {
throw thrownException;
})
..addFunction('env', 'b', () {
fail('should not get here!');
}))
.build();
var fn = inst.lookupFunction('fn');
expect(() => fn(), throwsA(thrownException));
inst = (WasmModule(data).builder()
..addFunction('env', 'a', expectAsync0(() => null))
..addFunction('env', 'b', expectAsync0(() => null)))
.build();
fn = inst.lookupFunction('fn');
fn();
});
}

View file

@ -1,40 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we can load a wasm module, find a function, and call it.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('function import', () {
// void reportStuff() { report(123, 456); }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x09, 0x02, 0x60, //
0x02, 0x7e, 0x7e, 0x00, 0x60, 0x00, 0x00, 0x02, 0x0e, 0x01, 0x03, 0x65,
0x6e, 0x76, 0x06, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x00, 0x00, 0x03,
0x02, 0x01, 0x01, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01, 0x01, 0x05, 0x03,
0x01, 0x00, 0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41, 0x80, 0x88, 0x04,
0x0b, 0x07, 0x18, 0x02, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02,
0x00, 0x0b, 0x72, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x53, 0x74, 0x75, 0x66,
0x66, 0x00, 0x01, 0x0a, 0x10, 0x01, 0x0e, 0x00, 0x42, 0xfb, 0x00, 0x42,
0xc8, 0x03, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x0b,
]);
var reportX = -1;
var reportY = -1;
var inst = (WasmModule(data).builder()
..addFunction('env', 'report', (int x, int y) {
reportX = x;
reportY = y;
}))
.build();
var fn = inst.lookupFunction('reportStuff');
fn();
expect(123, reportX);
expect(456, reportY);
});
}

View file

@ -1,183 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Variant of hello_world_test that uses the default WASI imports.
import 'dart:convert';
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('hello wasi', () async {
// Hello world module generated by emscripten+WASI. Exports a function like
// `void _start()`, and prints using `int fd_write(int, int, int, int)`.
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x09, 0x60, //
0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f,
0x01, 0x7f, 0x60, 0x00, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x60,
0x01, 0x7f, 0x01, 0x7f, 0x60, 0x03, 0x7f, 0x7e, 0x7f, 0x01, 0x7e, 0x60,
0x00, 0x01, 0x7f, 0x60, 0x01, 0x7f, 0x00, 0x60, 0x03, 0x7f, 0x7f, 0x7f,
0x00, 0x02, 0x1a, 0x01, 0x0d, 0x77, 0x61, 0x73, 0x69, 0x5f, 0x75, 0x6e,
0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x08, 0x66, 0x64, 0x5f, 0x77, 0x72,
0x69, 0x74, 0x65, 0x00, 0x01, 0x03, 0x0f, 0x0e, 0x03, 0x04, 0x00, 0x03,
0x02, 0x07, 0x05, 0x04, 0x03, 0x06, 0x02, 0x02, 0x08, 0x00, 0x04, 0x05,
0x01, 0x70, 0x01, 0x04, 0x04, 0x05, 0x06, 0x01, 0x01, 0x80, 0x02, 0x80,
0x02, 0x06, 0x09, 0x01, 0x7f, 0x01, 0x41, 0xc0, 0x95, 0xc0, 0x02, 0x0b,
0x07, 0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,
0x11, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x6c,
0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x05, 0x04, 0x6d, 0x61, 0x69,
0x6e, 0x00, 0x04, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x0b,
0x09, 0x09, 0x01, 0x00, 0x41, 0x01, 0x0b, 0x03, 0x08, 0x0e, 0x07, 0x0a,
0xae, 0x0c, 0x0e, 0xbf, 0x01, 0x01, 0x05, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x04, 0x02, 0x40, 0x20, 0x01, 0x28, 0x02, 0x10, 0x22, 0x02, 0x04, 0x7f,
0x20, 0x02, 0x05, 0x20, 0x01, 0x10, 0x02, 0x0d, 0x01, 0x20, 0x01, 0x28,
0x02, 0x10, 0x0b, 0x20, 0x01, 0x28, 0x02, 0x14, 0x22, 0x05, 0x6b, 0x20,
0x00, 0x49, 0x04, 0x40, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20, 0x00, 0x20,
0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x0f, 0x0b, 0x02, 0x40, 0x20,
0x01, 0x2c, 0x00, 0x4b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x20, 0x00, 0x21,
0x03, 0x03, 0x40, 0x20, 0x03, 0x22, 0x02, 0x45, 0x0d, 0x01, 0x20, 0x02,
0x41, 0x7f, 0x6a, 0x22, 0x03, 0x41, 0x80, 0x08, 0x6a, 0x2d, 0x00, 0x00,
0x41, 0x0a, 0x47, 0x0d, 0x00, 0x0b, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20,
0x02, 0x20, 0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x22, 0x03, 0x20,
0x02, 0x49, 0x0d, 0x01, 0x20, 0x00, 0x20, 0x02, 0x6b, 0x21, 0x00, 0x20,
0x02, 0x41, 0x80, 0x08, 0x6a, 0x21, 0x04, 0x20, 0x01, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x02, 0x21, 0x06, 0x0b, 0x20, 0x05, 0x20, 0x04, 0x20,
0x00, 0x10, 0x03, 0x1a, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x14, 0x20,
0x00, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x06, 0x6a, 0x21, 0x03,
0x0b, 0x20, 0x03, 0x0b, 0x59, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x20, 0x00,
0x2d, 0x00, 0x4a, 0x22, 0x01, 0x41, 0x7f, 0x6a, 0x20, 0x01, 0x72, 0x3a,
0x00, 0x4a, 0x20, 0x00, 0x28, 0x02, 0x00, 0x22, 0x01, 0x41, 0x08, 0x71,
0x04, 0x40, 0x20, 0x00, 0x20, 0x01, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x7f, 0x0f, 0x0b, 0x20, 0x00, 0x42, 0x00, 0x37, 0x02, 0x04, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02, 0x1c, 0x20,
0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01, 0x20, 0x00,
0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x41, 0x00, 0x0b, 0x82, 0x04,
0x01, 0x03, 0x7f, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x4f, 0x04, 0x40,
0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x0d, 0x20, 0x00, 0x0f, 0x0b,
0x20, 0x00, 0x20, 0x02, 0x6a, 0x21, 0x03, 0x02, 0x40, 0x20, 0x00, 0x20,
0x01, 0x73, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x02, 0x40, 0x20, 0x02,
0x41, 0x01, 0x48, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b,
0x20, 0x00, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02, 0x03, 0x40, 0x20, 0x02, 0x20,
0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a,
0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02, 0x20, 0x03, 0x4f,
0x0d, 0x01, 0x20, 0x02, 0x41, 0x03, 0x71, 0x0d, 0x00, 0x0b, 0x0b, 0x02,
0x40, 0x20, 0x03, 0x41, 0x7c, 0x71, 0x22, 0x04, 0x41, 0xc0, 0x00, 0x49,
0x0d, 0x00, 0x20, 0x02, 0x20, 0x04, 0x41, 0x40, 0x6a, 0x22, 0x05, 0x4b,
0x0d, 0x00, 0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36,
0x02, 0x00, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x04, 0x36, 0x02, 0x04,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x08, 0x36, 0x02, 0x08, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x0c, 0x36, 0x02, 0x0c, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x10, 0x36, 0x02, 0x10, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x14, 0x36, 0x02, 0x14, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x18, 0x36,
0x02, 0x18, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x1c, 0x36, 0x02, 0x1c,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x20, 0x36, 0x02, 0x20, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x24, 0x36, 0x02, 0x24, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x28, 0x36, 0x02, 0x28, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x2c, 0x36, 0x02, 0x2c, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x30, 0x36,
0x02, 0x30, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x34, 0x36, 0x02, 0x34,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x38, 0x36, 0x02, 0x38, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x3c, 0x36, 0x02, 0x3c, 0x20, 0x01, 0x41, 0x40,
0x6b, 0x21, 0x01, 0x20, 0x02, 0x41, 0x40, 0x6b, 0x22, 0x02, 0x20, 0x05,
0x4d, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x04, 0x4f, 0x0d, 0x01,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36, 0x02, 0x00,
0x20, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x04, 0x6a,
0x22, 0x02, 0x20, 0x04, 0x49, 0x0d, 0x00, 0x0b, 0x0c, 0x01, 0x0b, 0x20,
0x03, 0x41, 0x04, 0x49, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01,
0x0b, 0x20, 0x03, 0x41, 0x7c, 0x6a, 0x22, 0x04, 0x20, 0x00, 0x49, 0x04,
0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x3a, 0x00, 0x01, 0x20, 0x02,
0x20, 0x01, 0x2d, 0x00, 0x02, 0x3a, 0x00, 0x02, 0x20, 0x02, 0x20, 0x01,
0x2d, 0x00, 0x03, 0x3a, 0x00, 0x03, 0x20, 0x01, 0x41, 0x04, 0x6a, 0x21,
0x01, 0x20, 0x02, 0x41, 0x04, 0x6a, 0x22, 0x02, 0x20, 0x04, 0x4d, 0x0d,
0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x03, 0x49, 0x04, 0x40, 0x03, 0x40,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01,
0x41, 0x01, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02,
0x20, 0x03, 0x47, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x00, 0x0b, 0x06, 0x00,
0x10, 0x0c, 0x41, 0x00, 0x0b, 0x03, 0x00, 0x01, 0x0b, 0x7e, 0x01, 0x03,
0x7f, 0x23, 0x00, 0x41, 0x10, 0x6b, 0x22, 0x01, 0x24, 0x00, 0x20, 0x01,
0x41, 0x0a, 0x3a, 0x00, 0x0f, 0x02, 0x40, 0x20, 0x00, 0x28, 0x02, 0x10,
0x22, 0x02, 0x45, 0x04, 0x40, 0x20, 0x00, 0x10, 0x02, 0x0d, 0x01, 0x20,
0x00, 0x28, 0x02, 0x10, 0x21, 0x02, 0x0b, 0x02, 0x40, 0x20, 0x00, 0x28,
0x02, 0x14, 0x22, 0x03, 0x20, 0x02, 0x4f, 0x0d, 0x00, 0x20, 0x00, 0x2c,
0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00, 0x20, 0x03, 0x41,
0x01, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x03, 0x41, 0x0a, 0x3a, 0x00, 0x00,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x20, 0x01, 0x41, 0x0f, 0x6a, 0x41, 0x01,
0x20, 0x00, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x41, 0x01, 0x47, 0x0d,
0x00, 0x20, 0x01, 0x2d, 0x00, 0x0f, 0x1a, 0x0b, 0x20, 0x01, 0x41, 0x10,
0x6a, 0x24, 0x00, 0x0b, 0x04, 0x00, 0x42, 0x00, 0x0b, 0x04, 0x00, 0x41,
0x00, 0x0b, 0x31, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x21, 0x02, 0x20, 0x02,
0x02, 0x7f, 0x20, 0x01, 0x28, 0x02, 0x4c, 0x41, 0x7f, 0x4c, 0x04, 0x40,
0x20, 0x02, 0x20, 0x01, 0x10, 0x01, 0x0c, 0x01, 0x0b, 0x20, 0x02, 0x20,
0x01, 0x10, 0x01, 0x0b, 0x22, 0x01, 0x46, 0x04, 0x40, 0x20, 0x00, 0x0f,
0x0b, 0x20, 0x01, 0x0b, 0x62, 0x01, 0x03, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x00, 0x03, 0x40, 0x20, 0x00, 0x22, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x00,
0x20, 0x01, 0x28, 0x02, 0x00, 0x22, 0x02, 0x41, 0x7f, 0x73, 0x20, 0x02,
0x41, 0xff, 0xfd, 0xfb, 0x77, 0x6a, 0x71, 0x41, 0x80, 0x81, 0x82, 0x84,
0x78, 0x71, 0x45, 0x0d, 0x00, 0x0b, 0x02, 0x40, 0x20, 0x02, 0x41, 0xff,
0x01, 0x71, 0x45, 0x04, 0x40, 0x20, 0x01, 0x21, 0x00, 0x0c, 0x01, 0x0b,
0x03, 0x40, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x21, 0x02, 0x20, 0x01, 0x41,
0x01, 0x6a, 0x22, 0x00, 0x21, 0x01, 0x20, 0x02, 0x0d, 0x00, 0x0b, 0x0b,
0x20, 0x00, 0x41, 0x80, 0x08, 0x6b, 0x0b, 0x0c, 0x00, 0x02, 0x7f, 0x41,
0x00, 0x41, 0x00, 0x10, 0x04, 0x0b, 0x1a, 0x0b, 0x66, 0x01, 0x02, 0x7f,
0x41, 0x90, 0x08, 0x28, 0x02, 0x00, 0x22, 0x00, 0x28, 0x02, 0x4c, 0x41,
0x00, 0x4e, 0x04, 0x7f, 0x41, 0x01, 0x05, 0x20, 0x01, 0x0b, 0x1a, 0x02,
0x40, 0x41, 0x7f, 0x41, 0x00, 0x10, 0x0a, 0x22, 0x01, 0x20, 0x01, 0x20,
0x00, 0x10, 0x09, 0x47, 0x1b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x02, 0x40,
0x20, 0x00, 0x2d, 0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00,
0x28, 0x02, 0x14, 0x22, 0x01, 0x20, 0x00, 0x28, 0x02, 0x10, 0x4f, 0x0d,
0x00, 0x20, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x36, 0x02, 0x14, 0x20,
0x01, 0x41, 0x0a, 0x3a, 0x00, 0x00, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x10,
0x06, 0x0b, 0x0b, 0x3d, 0x01, 0x01, 0x7f, 0x20, 0x02, 0x04, 0x40, 0x03,
0x40, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x20,
0x02, 0x41, 0x80, 0xc0, 0x00, 0x49, 0x1b, 0x22, 0x03, 0x10, 0x03, 0x21,
0x00, 0x20, 0x01, 0x41, 0x80, 0x40, 0x6b, 0x21, 0x01, 0x20, 0x00, 0x41,
0x80, 0x40, 0x6b, 0x21, 0x00, 0x20, 0x02, 0x20, 0x03, 0x6b, 0x22, 0x02,
0x0d, 0x00, 0x0b, 0x0b, 0x0b, 0xb1, 0x02, 0x01, 0x06, 0x7f, 0x23, 0x00,
0x41, 0x20, 0x6b, 0x22, 0x03, 0x24, 0x00, 0x20, 0x03, 0x20, 0x00, 0x28,
0x02, 0x1c, 0x22, 0x04, 0x36, 0x02, 0x10, 0x20, 0x00, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x03, 0x20, 0x02, 0x36, 0x02, 0x1c, 0x20, 0x03, 0x20,
0x01, 0x36, 0x02, 0x18, 0x20, 0x03, 0x20, 0x05, 0x20, 0x04, 0x6b, 0x22,
0x01, 0x36, 0x02, 0x14, 0x20, 0x01, 0x20, 0x02, 0x6a, 0x21, 0x06, 0x41,
0x02, 0x21, 0x05, 0x20, 0x03, 0x41, 0x10, 0x6a, 0x21, 0x01, 0x03, 0x40,
0x02, 0x40, 0x02, 0x7f, 0x20, 0x06, 0x02, 0x7f, 0x20, 0x00, 0x28, 0x02,
0x3c, 0x20, 0x01, 0x20, 0x05, 0x20, 0x03, 0x41, 0x0c, 0x6a, 0x10, 0x00,
0x04, 0x40, 0x20, 0x03, 0x41, 0x7f, 0x36, 0x02, 0x0c, 0x41, 0x7f, 0x0c,
0x01, 0x0b, 0x20, 0x03, 0x28, 0x02, 0x0c, 0x0b, 0x22, 0x04, 0x46, 0x04,
0x40, 0x20, 0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02,
0x1c, 0x20, 0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01,
0x20, 0x00, 0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x20, 0x02, 0x0c,
0x01, 0x0b, 0x20, 0x04, 0x41, 0x7f, 0x4a, 0x0d, 0x01, 0x20, 0x00, 0x41,
0x00, 0x36, 0x02, 0x1c, 0x20, 0x00, 0x42, 0x00, 0x37, 0x03, 0x10, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x00, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x00, 0x20, 0x05, 0x41, 0x02, 0x46, 0x0d, 0x00, 0x1a, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x04, 0x6b, 0x0b, 0x21, 0x04, 0x20, 0x03, 0x41,
0x20, 0x6a, 0x24, 0x00, 0x20, 0x04, 0x0f, 0x0b, 0x20, 0x01, 0x41, 0x08,
0x6a, 0x20, 0x01, 0x20, 0x04, 0x20, 0x01, 0x28, 0x02, 0x04, 0x22, 0x07,
0x4b, 0x22, 0x08, 0x1b, 0x22, 0x01, 0x20, 0x04, 0x20, 0x07, 0x41, 0x00,
0x20, 0x08, 0x1b, 0x6b, 0x22, 0x07, 0x20, 0x01, 0x28, 0x02, 0x00, 0x6a,
0x36, 0x02, 0x00, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x04, 0x20, 0x07,
0x6b, 0x36, 0x02, 0x04, 0x20, 0x06, 0x20, 0x04, 0x6b, 0x21, 0x06, 0x20,
0x05, 0x20, 0x08, 0x6b, 0x21, 0x05, 0x0c, 0x00, 0x00, 0x0b, 0x00, 0x0b,
0x0b, 0x4d, 0x06, 0x00, 0x41, 0x80, 0x08, 0x0b, 0x12, 0x68, 0x65, 0x6c,
0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00, 0x00,
0x00, 0x18, 0x04, 0x00, 0x41, 0x98, 0x08, 0x0b, 0x01, 0x05, 0x00, 0x41,
0xa4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xbc, 0x08, 0x0b, 0x0e, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb8, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x41, 0xd4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xe3, 0x08,
0x0b, 0x05, 0x0a, 0xff, 0xff, 0xff, 0xff,
]);
var inst =
(WasmModule(data).builder()..enableWasi(captureStdout: true)).build();
var fn = inst.lookupFunction('_start');
fn();
// TODO: failing on mac https://github.com/dart-lang/sdk/issues/46222
var out = utf8.decode(await inst.stdout.first);
expect(out, 'hello, world!\n');
});
}

View file

@ -1,211 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.12
// Test for hello world built using emscripten with WASI.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('hello world', () {
// Hello world module generated by emscripten+WASI. Exports a function like
// `void _start()`, and prints using `int fd_write(int, int, int, int)`.
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x09, 0x60, //
0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f,
0x01, 0x7f, 0x60, 0x00, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x60,
0x01, 0x7f, 0x01, 0x7f, 0x60, 0x03, 0x7f, 0x7e, 0x7f, 0x01, 0x7e, 0x60,
0x00, 0x01, 0x7f, 0x60, 0x01, 0x7f, 0x00, 0x60, 0x03, 0x7f, 0x7f, 0x7f,
0x00, 0x02, 0x1a, 0x01, 0x0d, 0x77, 0x61, 0x73, 0x69, 0x5f, 0x75, 0x6e,
0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x08, 0x66, 0x64, 0x5f, 0x77, 0x72,
0x69, 0x74, 0x65, 0x00, 0x01, 0x03, 0x0f, 0x0e, 0x03, 0x04, 0x00, 0x03,
0x02, 0x07, 0x05, 0x04, 0x03, 0x06, 0x02, 0x02, 0x08, 0x00, 0x04, 0x05,
0x01, 0x70, 0x01, 0x04, 0x04, 0x05, 0x06, 0x01, 0x01, 0x80, 0x02, 0x80,
0x02, 0x06, 0x09, 0x01, 0x7f, 0x01, 0x41, 0xc0, 0x95, 0xc0, 0x02, 0x0b,
0x07, 0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,
0x11, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x6c,
0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x05, 0x04, 0x6d, 0x61, 0x69,
0x6e, 0x00, 0x04, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x0b,
0x09, 0x09, 0x01, 0x00, 0x41, 0x01, 0x0b, 0x03, 0x08, 0x0e, 0x07, 0x0a,
0xae, 0x0c, 0x0e, 0xbf, 0x01, 0x01, 0x05, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x04, 0x02, 0x40, 0x20, 0x01, 0x28, 0x02, 0x10, 0x22, 0x02, 0x04, 0x7f,
0x20, 0x02, 0x05, 0x20, 0x01, 0x10, 0x02, 0x0d, 0x01, 0x20, 0x01, 0x28,
0x02, 0x10, 0x0b, 0x20, 0x01, 0x28, 0x02, 0x14, 0x22, 0x05, 0x6b, 0x20,
0x00, 0x49, 0x04, 0x40, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20, 0x00, 0x20,
0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x0f, 0x0b, 0x02, 0x40, 0x20,
0x01, 0x2c, 0x00, 0x4b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x20, 0x00, 0x21,
0x03, 0x03, 0x40, 0x20, 0x03, 0x22, 0x02, 0x45, 0x0d, 0x01, 0x20, 0x02,
0x41, 0x7f, 0x6a, 0x22, 0x03, 0x41, 0x80, 0x08, 0x6a, 0x2d, 0x00, 0x00,
0x41, 0x0a, 0x47, 0x0d, 0x00, 0x0b, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20,
0x02, 0x20, 0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x22, 0x03, 0x20,
0x02, 0x49, 0x0d, 0x01, 0x20, 0x00, 0x20, 0x02, 0x6b, 0x21, 0x00, 0x20,
0x02, 0x41, 0x80, 0x08, 0x6a, 0x21, 0x04, 0x20, 0x01, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x02, 0x21, 0x06, 0x0b, 0x20, 0x05, 0x20, 0x04, 0x20,
0x00, 0x10, 0x03, 0x1a, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x14, 0x20,
0x00, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x06, 0x6a, 0x21, 0x03,
0x0b, 0x20, 0x03, 0x0b, 0x59, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x20, 0x00,
0x2d, 0x00, 0x4a, 0x22, 0x01, 0x41, 0x7f, 0x6a, 0x20, 0x01, 0x72, 0x3a,
0x00, 0x4a, 0x20, 0x00, 0x28, 0x02, 0x00, 0x22, 0x01, 0x41, 0x08, 0x71,
0x04, 0x40, 0x20, 0x00, 0x20, 0x01, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x7f, 0x0f, 0x0b, 0x20, 0x00, 0x42, 0x00, 0x37, 0x02, 0x04, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02, 0x1c, 0x20,
0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01, 0x20, 0x00,
0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x41, 0x00, 0x0b, 0x82, 0x04,
0x01, 0x03, 0x7f, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x4f, 0x04, 0x40,
0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x0d, 0x20, 0x00, 0x0f, 0x0b,
0x20, 0x00, 0x20, 0x02, 0x6a, 0x21, 0x03, 0x02, 0x40, 0x20, 0x00, 0x20,
0x01, 0x73, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x02, 0x40, 0x20, 0x02,
0x41, 0x01, 0x48, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b,
0x20, 0x00, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02, 0x03, 0x40, 0x20, 0x02, 0x20,
0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a,
0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02, 0x20, 0x03, 0x4f,
0x0d, 0x01, 0x20, 0x02, 0x41, 0x03, 0x71, 0x0d, 0x00, 0x0b, 0x0b, 0x02,
0x40, 0x20, 0x03, 0x41, 0x7c, 0x71, 0x22, 0x04, 0x41, 0xc0, 0x00, 0x49,
0x0d, 0x00, 0x20, 0x02, 0x20, 0x04, 0x41, 0x40, 0x6a, 0x22, 0x05, 0x4b,
0x0d, 0x00, 0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36,
0x02, 0x00, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x04, 0x36, 0x02, 0x04,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x08, 0x36, 0x02, 0x08, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x0c, 0x36, 0x02, 0x0c, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x10, 0x36, 0x02, 0x10, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x14, 0x36, 0x02, 0x14, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x18, 0x36,
0x02, 0x18, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x1c, 0x36, 0x02, 0x1c,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x20, 0x36, 0x02, 0x20, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x24, 0x36, 0x02, 0x24, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x28, 0x36, 0x02, 0x28, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x2c, 0x36, 0x02, 0x2c, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x30, 0x36,
0x02, 0x30, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x34, 0x36, 0x02, 0x34,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x38, 0x36, 0x02, 0x38, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x3c, 0x36, 0x02, 0x3c, 0x20, 0x01, 0x41, 0x40,
0x6b, 0x21, 0x01, 0x20, 0x02, 0x41, 0x40, 0x6b, 0x22, 0x02, 0x20, 0x05,
0x4d, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x04, 0x4f, 0x0d, 0x01,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36, 0x02, 0x00,
0x20, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x04, 0x6a,
0x22, 0x02, 0x20, 0x04, 0x49, 0x0d, 0x00, 0x0b, 0x0c, 0x01, 0x0b, 0x20,
0x03, 0x41, 0x04, 0x49, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01,
0x0b, 0x20, 0x03, 0x41, 0x7c, 0x6a, 0x22, 0x04, 0x20, 0x00, 0x49, 0x04,
0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x3a, 0x00, 0x01, 0x20, 0x02,
0x20, 0x01, 0x2d, 0x00, 0x02, 0x3a, 0x00, 0x02, 0x20, 0x02, 0x20, 0x01,
0x2d, 0x00, 0x03, 0x3a, 0x00, 0x03, 0x20, 0x01, 0x41, 0x04, 0x6a, 0x21,
0x01, 0x20, 0x02, 0x41, 0x04, 0x6a, 0x22, 0x02, 0x20, 0x04, 0x4d, 0x0d,
0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x03, 0x49, 0x04, 0x40, 0x03, 0x40,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01,
0x41, 0x01, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02,
0x20, 0x03, 0x47, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x00, 0x0b, 0x06, 0x00,
0x10, 0x0c, 0x41, 0x00, 0x0b, 0x03, 0x00, 0x01, 0x0b, 0x7e, 0x01, 0x03,
0x7f, 0x23, 0x00, 0x41, 0x10, 0x6b, 0x22, 0x01, 0x24, 0x00, 0x20, 0x01,
0x41, 0x0a, 0x3a, 0x00, 0x0f, 0x02, 0x40, 0x20, 0x00, 0x28, 0x02, 0x10,
0x22, 0x02, 0x45, 0x04, 0x40, 0x20, 0x00, 0x10, 0x02, 0x0d, 0x01, 0x20,
0x00, 0x28, 0x02, 0x10, 0x21, 0x02, 0x0b, 0x02, 0x40, 0x20, 0x00, 0x28,
0x02, 0x14, 0x22, 0x03, 0x20, 0x02, 0x4f, 0x0d, 0x00, 0x20, 0x00, 0x2c,
0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00, 0x20, 0x03, 0x41,
0x01, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x03, 0x41, 0x0a, 0x3a, 0x00, 0x00,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x20, 0x01, 0x41, 0x0f, 0x6a, 0x41, 0x01,
0x20, 0x00, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x41, 0x01, 0x47, 0x0d,
0x00, 0x20, 0x01, 0x2d, 0x00, 0x0f, 0x1a, 0x0b, 0x20, 0x01, 0x41, 0x10,
0x6a, 0x24, 0x00, 0x0b, 0x04, 0x00, 0x42, 0x00, 0x0b, 0x04, 0x00, 0x41,
0x00, 0x0b, 0x31, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x21, 0x02, 0x20, 0x02,
0x02, 0x7f, 0x20, 0x01, 0x28, 0x02, 0x4c, 0x41, 0x7f, 0x4c, 0x04, 0x40,
0x20, 0x02, 0x20, 0x01, 0x10, 0x01, 0x0c, 0x01, 0x0b, 0x20, 0x02, 0x20,
0x01, 0x10, 0x01, 0x0b, 0x22, 0x01, 0x46, 0x04, 0x40, 0x20, 0x00, 0x0f,
0x0b, 0x20, 0x01, 0x0b, 0x62, 0x01, 0x03, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x00, 0x03, 0x40, 0x20, 0x00, 0x22, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x00,
0x20, 0x01, 0x28, 0x02, 0x00, 0x22, 0x02, 0x41, 0x7f, 0x73, 0x20, 0x02,
0x41, 0xff, 0xfd, 0xfb, 0x77, 0x6a, 0x71, 0x41, 0x80, 0x81, 0x82, 0x84,
0x78, 0x71, 0x45, 0x0d, 0x00, 0x0b, 0x02, 0x40, 0x20, 0x02, 0x41, 0xff,
0x01, 0x71, 0x45, 0x04, 0x40, 0x20, 0x01, 0x21, 0x00, 0x0c, 0x01, 0x0b,
0x03, 0x40, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x21, 0x02, 0x20, 0x01, 0x41,
0x01, 0x6a, 0x22, 0x00, 0x21, 0x01, 0x20, 0x02, 0x0d, 0x00, 0x0b, 0x0b,
0x20, 0x00, 0x41, 0x80, 0x08, 0x6b, 0x0b, 0x0c, 0x00, 0x02, 0x7f, 0x41,
0x00, 0x41, 0x00, 0x10, 0x04, 0x0b, 0x1a, 0x0b, 0x66, 0x01, 0x02, 0x7f,
0x41, 0x90, 0x08, 0x28, 0x02, 0x00, 0x22, 0x00, 0x28, 0x02, 0x4c, 0x41,
0x00, 0x4e, 0x04, 0x7f, 0x41, 0x01, 0x05, 0x20, 0x01, 0x0b, 0x1a, 0x02,
0x40, 0x41, 0x7f, 0x41, 0x00, 0x10, 0x0a, 0x22, 0x01, 0x20, 0x01, 0x20,
0x00, 0x10, 0x09, 0x47, 0x1b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x02, 0x40,
0x20, 0x00, 0x2d, 0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00,
0x28, 0x02, 0x14, 0x22, 0x01, 0x20, 0x00, 0x28, 0x02, 0x10, 0x4f, 0x0d,
0x00, 0x20, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x36, 0x02, 0x14, 0x20,
0x01, 0x41, 0x0a, 0x3a, 0x00, 0x00, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x10,
0x06, 0x0b, 0x0b, 0x3d, 0x01, 0x01, 0x7f, 0x20, 0x02, 0x04, 0x40, 0x03,
0x40, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x20,
0x02, 0x41, 0x80, 0xc0, 0x00, 0x49, 0x1b, 0x22, 0x03, 0x10, 0x03, 0x21,
0x00, 0x20, 0x01, 0x41, 0x80, 0x40, 0x6b, 0x21, 0x01, 0x20, 0x00, 0x41,
0x80, 0x40, 0x6b, 0x21, 0x00, 0x20, 0x02, 0x20, 0x03, 0x6b, 0x22, 0x02,
0x0d, 0x00, 0x0b, 0x0b, 0x0b, 0xb1, 0x02, 0x01, 0x06, 0x7f, 0x23, 0x00,
0x41, 0x20, 0x6b, 0x22, 0x03, 0x24, 0x00, 0x20, 0x03, 0x20, 0x00, 0x28,
0x02, 0x1c, 0x22, 0x04, 0x36, 0x02, 0x10, 0x20, 0x00, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x03, 0x20, 0x02, 0x36, 0x02, 0x1c, 0x20, 0x03, 0x20,
0x01, 0x36, 0x02, 0x18, 0x20, 0x03, 0x20, 0x05, 0x20, 0x04, 0x6b, 0x22,
0x01, 0x36, 0x02, 0x14, 0x20, 0x01, 0x20, 0x02, 0x6a, 0x21, 0x06, 0x41,
0x02, 0x21, 0x05, 0x20, 0x03, 0x41, 0x10, 0x6a, 0x21, 0x01, 0x03, 0x40,
0x02, 0x40, 0x02, 0x7f, 0x20, 0x06, 0x02, 0x7f, 0x20, 0x00, 0x28, 0x02,
0x3c, 0x20, 0x01, 0x20, 0x05, 0x20, 0x03, 0x41, 0x0c, 0x6a, 0x10, 0x00,
0x04, 0x40, 0x20, 0x03, 0x41, 0x7f, 0x36, 0x02, 0x0c, 0x41, 0x7f, 0x0c,
0x01, 0x0b, 0x20, 0x03, 0x28, 0x02, 0x0c, 0x0b, 0x22, 0x04, 0x46, 0x04,
0x40, 0x20, 0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02,
0x1c, 0x20, 0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01,
0x20, 0x00, 0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x20, 0x02, 0x0c,
0x01, 0x0b, 0x20, 0x04, 0x41, 0x7f, 0x4a, 0x0d, 0x01, 0x20, 0x00, 0x41,
0x00, 0x36, 0x02, 0x1c, 0x20, 0x00, 0x42, 0x00, 0x37, 0x03, 0x10, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x00, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x00, 0x20, 0x05, 0x41, 0x02, 0x46, 0x0d, 0x00, 0x1a, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x04, 0x6b, 0x0b, 0x21, 0x04, 0x20, 0x03, 0x41,
0x20, 0x6a, 0x24, 0x00, 0x20, 0x04, 0x0f, 0x0b, 0x20, 0x01, 0x41, 0x08,
0x6a, 0x20, 0x01, 0x20, 0x04, 0x20, 0x01, 0x28, 0x02, 0x04, 0x22, 0x07,
0x4b, 0x22, 0x08, 0x1b, 0x22, 0x01, 0x20, 0x04, 0x20, 0x07, 0x41, 0x00,
0x20, 0x08, 0x1b, 0x6b, 0x22, 0x07, 0x20, 0x01, 0x28, 0x02, 0x00, 0x6a,
0x36, 0x02, 0x00, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x04, 0x20, 0x07,
0x6b, 0x36, 0x02, 0x04, 0x20, 0x06, 0x20, 0x04, 0x6b, 0x21, 0x06, 0x20,
0x05, 0x20, 0x08, 0x6b, 0x21, 0x05, 0x0c, 0x00, 0x00, 0x0b, 0x00, 0x0b,
0x0b, 0x4d, 0x06, 0x00, 0x41, 0x80, 0x08, 0x0b, 0x12, 0x68, 0x65, 0x6c,
0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00, 0x00,
0x00, 0x18, 0x04, 0x00, 0x41, 0x98, 0x08, 0x0b, 0x01, 0x05, 0x00, 0x41,
0xa4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xbc, 0x08, 0x0b, 0x0e, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb8, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x41, 0xd4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xe3, 0x08,
0x0b, 0x05, 0x0a, 0xff, 0xff, 0xff, 0xff,
]);
late WasmMemory mem;
var out = StringBuffer();
int getI32(int p) {
// Read a little-endian I32.
var n = 0;
for (var i = p + 3; i >= p; --i) {
n *= 256;
n += mem[i];
}
return n;
}
var builder = WasmModule(data).builder()
..addFunction('wasi_unstable', 'fd_write',
(int fd, int iovs, int iovsLen, int unused) {
// iovs points to an array of length iovs_len. Each element is two I32s,
// a char* and a length.
var o = StringBuffer();
for (var i = 0; i < iovsLen; ++i) {
var str = getI32(iovs + 8 * i);
var len = getI32(iovs + 4 + 8 * i);
for (var j = 0; j < len; ++j) {
o.write(String.fromCharCode(mem[str + j]));
}
}
out.write(o.toString());
return o.length;
});
var inst = builder.build();
mem = inst.memory;
var fn = inst.lookupFunction('_start');
fn();
expect(out.toString(), 'hello, world!\n');
});
}

View file

@ -1,36 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test errors thrown by WasmMemory.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
import 'test_shared.dart';
void main() {
test('memory errors', () {
// Empty wasm module.
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x06, 0x81, 0x00, 0x00, //
]);
var module = WasmModule(data);
expect(
() => module.createMemory(1000000000),
throwsWasmError(startsWith('Failed to create memory.')),
);
var mem = module.createMemory(100);
expect(
() => mem.grow(1000000000),
throwsWasmError('Failed to grow memory.'),
);
mem = module.createMemory(100, 200);
expect(
() => mem.grow(300),
throwsWasmError('Failed to grow memory.'),
);
});
}

View file

@ -1,31 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we can create a WasmMemory, edit it, and grow it.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('memory', () {
// Empty wasm module.
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x06, 0x81, 0x00, 0x00, //
]);
var module = WasmModule(data);
var mem = module.createMemory(100);
expect(mem.lengthInPages, 100);
expect(mem.lengthInBytes, 100 * WasmMemory.kPageSizeInBytes);
mem[123] = 45;
expect(mem[123], 45);
mem.grow(10);
expect(mem.lengthInPages, 110);
expect(mem.lengthInBytes, 110 * WasmMemory.kPageSizeInBytes);
expect(mem[123], 45);
});
}

View file

@ -1,51 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test numeric types.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('numerics', () {
// int64_t addI64(int64_t x, int64_t y) { return x + y; }
// int32_t addI32(int32_t x, int32_t y) { return x + y; }
// double addF64(double x, double y) { return x + y; }
// float addF32(float x, float y) { return x + y; }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x19, 0x04, 0x60, //
0x02, 0x7e, 0x7e, 0x01, 0x7e, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x60,
0x02, 0x7c, 0x7c, 0x01, 0x7c, 0x60, 0x02, 0x7d, 0x7d, 0x01, 0x7d, 0x03,
0x05, 0x04, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01,
0x01, 0x05, 0x03, 0x01, 0x00, 0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41,
0x80, 0x88, 0x04, 0x0b, 0x07, 0x2e, 0x05, 0x06, 0x6d, 0x65, 0x6d, 0x6f,
0x72, 0x79, 0x02, 0x00, 0x06, 0x61, 0x64, 0x64, 0x49, 0x36, 0x34, 0x00,
0x00, 0x06, 0x61, 0x64, 0x64, 0x49, 0x33, 0x32, 0x00, 0x01, 0x06, 0x61,
0x64, 0x64, 0x46, 0x36, 0x34, 0x00, 0x02, 0x06, 0x61, 0x64, 0x64, 0x46,
0x33, 0x32, 0x00, 0x03, 0x0a, 0x21, 0x04, 0x07, 0x00, 0x20, 0x01, 0x20,
0x00, 0x7c, 0x0b, 0x07, 0x00, 0x20, 0x01, 0x20, 0x00, 0x6a, 0x0b, 0x07,
0x00, 0x20, 0x00, 0x20, 0x01, 0xa0, 0x0b, 0x07, 0x00, 0x20, 0x00, 0x20,
0x01, 0x92, 0x0b,
]);
var inst = WasmModule(data).builder().build();
var addI64 = inst.lookupFunction('addI64');
var addI32 = inst.lookupFunction('addI32');
var addF64 = inst.lookupFunction('addF64');
var addF32 = inst.lookupFunction('addF32');
var i64 = addI64(0x123456789ABCDEF, 0xFEDCBA987654321) as int;
expect(i64, 0x1111111111111110);
var i32 = addI32(0xABCDEF, 0xFEDCBA) as int;
expect(i32, 0x1aaaaa9);
var f64 = addF64(1234.5678, 8765.4321) as double;
expect(f64, closeTo(9999.9999, 1e-6));
var f32 = addF32(1234.5678, 8765.4321) as double;
expect(f32, closeTo(9999.9999, 1e-3));
});
}

View file

@ -1,10 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:test/test.dart';
import 'package:wasm/src/wasm_error.dart';
Matcher throwsWasmError(Object messageMatcher) => throwsA(
isA<WasmError>().having((p0) => p0.message, 'message', messageMatcher),
);

View file

@ -1,36 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test functions with void return type, and functions that take no args.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
void main() {
test('void return type', () {
// int64_t x = 0;
// void set(int64_t a, int64_t b) { x = a + b; }
// int64_t get() { return x; }
var data = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0a, 0x02, 0x60, //
0x02, 0x7e, 0x7e, 0x00, 0x60, 0x00, 0x01, 0x7e, 0x03, 0x03, 0x02, 0x00,
0x01, 0x04, 0x05, 0x01, 0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00,
0x02, 0x06, 0x08, 0x01, 0x7f, 0x01, 0x41, 0x90, 0x88, 0x04, 0x0b, 0x07,
0x16, 0x03, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x03,
0x73, 0x65, 0x74, 0x00, 0x00, 0x03, 0x67, 0x65, 0x74, 0x00, 0x01, 0x0a,
0x1e, 0x02, 0x10, 0x00, 0x41, 0x00, 0x20, 0x01, 0x20, 0x00, 0x7c, 0x37,
0x03, 0x80, 0x88, 0x80, 0x80, 0x00, 0x0b, 0x0b, 0x00, 0x41, 0x00, 0x29,
0x03, 0x80, 0x88, 0x80, 0x80, 0x00, 0x0b, 0x0b, 0x0f, 0x01, 0x00, 0x41,
0x80, 0x08, 0x0b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);
var inst = WasmModule(data).builder().build();
var setFn = inst.lookupFunction('set');
var getFn = inst.lookupFunction('get');
expect(setFn(123, 456), isNull);
var n = getFn() as int;
expect(n, 123 + 456);
});
}

View file

@ -1,216 +0,0 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test the errors that can be thrown by WASI.
import 'dart:typed_data';
import 'package:test/test.dart';
import 'package:wasm/wasm.dart';
import 'test_shared.dart';
void main() {
test('wasi error', () {
// Empty wasm module.
var emptyModuleData = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x06, 0x81, 0x00, 0x00, //
]);
// Failed to fill WASI imports (the empty module was not built with WASI).
expect(
() => WasmModule(emptyModuleData).builder().enableWasi(),
throwsWasmError(startsWith('Failed to fill WASI imports.')),
);
// Hello world module generated by emscripten+WASI. Exports a function like
// `void _start()`, and prints using `int fd_write(int, int, int, int)`.
var helloWorldData = Uint8List.fromList([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x33, 0x09, 0x60, //
0x03, 0x7f, 0x7f, 0x7f, 0x01, 0x7f, 0x60, 0x04, 0x7f, 0x7f, 0x7f, 0x7f,
0x01, 0x7f, 0x60, 0x00, 0x00, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x60,
0x01, 0x7f, 0x01, 0x7f, 0x60, 0x03, 0x7f, 0x7e, 0x7f, 0x01, 0x7e, 0x60,
0x00, 0x01, 0x7f, 0x60, 0x01, 0x7f, 0x00, 0x60, 0x03, 0x7f, 0x7f, 0x7f,
0x00, 0x02, 0x1a, 0x01, 0x0d, 0x77, 0x61, 0x73, 0x69, 0x5f, 0x75, 0x6e,
0x73, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x08, 0x66, 0x64, 0x5f, 0x77, 0x72,
0x69, 0x74, 0x65, 0x00, 0x01, 0x03, 0x0f, 0x0e, 0x03, 0x04, 0x00, 0x03,
0x02, 0x07, 0x05, 0x04, 0x03, 0x06, 0x02, 0x02, 0x08, 0x00, 0x04, 0x05,
0x01, 0x70, 0x01, 0x04, 0x04, 0x05, 0x06, 0x01, 0x01, 0x80, 0x02, 0x80,
0x02, 0x06, 0x09, 0x01, 0x7f, 0x01, 0x41, 0xc0, 0x95, 0xc0, 0x02, 0x0b,
0x07, 0x2e, 0x04, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00,
0x11, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x6c,
0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x05, 0x04, 0x6d, 0x61, 0x69,
0x6e, 0x00, 0x04, 0x06, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x00, 0x0b,
0x09, 0x09, 0x01, 0x00, 0x41, 0x01, 0x0b, 0x03, 0x08, 0x0e, 0x07, 0x0a,
0xae, 0x0c, 0x0e, 0xbf, 0x01, 0x01, 0x05, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x04, 0x02, 0x40, 0x20, 0x01, 0x28, 0x02, 0x10, 0x22, 0x02, 0x04, 0x7f,
0x20, 0x02, 0x05, 0x20, 0x01, 0x10, 0x02, 0x0d, 0x01, 0x20, 0x01, 0x28,
0x02, 0x10, 0x0b, 0x20, 0x01, 0x28, 0x02, 0x14, 0x22, 0x05, 0x6b, 0x20,
0x00, 0x49, 0x04, 0x40, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20, 0x00, 0x20,
0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x0f, 0x0b, 0x02, 0x40, 0x20,
0x01, 0x2c, 0x00, 0x4b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x20, 0x00, 0x21,
0x03, 0x03, 0x40, 0x20, 0x03, 0x22, 0x02, 0x45, 0x0d, 0x01, 0x20, 0x02,
0x41, 0x7f, 0x6a, 0x22, 0x03, 0x41, 0x80, 0x08, 0x6a, 0x2d, 0x00, 0x00,
0x41, 0x0a, 0x47, 0x0d, 0x00, 0x0b, 0x20, 0x01, 0x41, 0x80, 0x08, 0x20,
0x02, 0x20, 0x01, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x22, 0x03, 0x20,
0x02, 0x49, 0x0d, 0x01, 0x20, 0x00, 0x20, 0x02, 0x6b, 0x21, 0x00, 0x20,
0x02, 0x41, 0x80, 0x08, 0x6a, 0x21, 0x04, 0x20, 0x01, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x02, 0x21, 0x06, 0x0b, 0x20, 0x05, 0x20, 0x04, 0x20,
0x00, 0x10, 0x03, 0x1a, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x14, 0x20,
0x00, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x06, 0x6a, 0x21, 0x03,
0x0b, 0x20, 0x03, 0x0b, 0x59, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x20, 0x00,
0x2d, 0x00, 0x4a, 0x22, 0x01, 0x41, 0x7f, 0x6a, 0x20, 0x01, 0x72, 0x3a,
0x00, 0x4a, 0x20, 0x00, 0x28, 0x02, 0x00, 0x22, 0x01, 0x41, 0x08, 0x71,
0x04, 0x40, 0x20, 0x00, 0x20, 0x01, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x7f, 0x0f, 0x0b, 0x20, 0x00, 0x42, 0x00, 0x37, 0x02, 0x04, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02, 0x1c, 0x20,
0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01, 0x20, 0x00,
0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x41, 0x00, 0x0b, 0x82, 0x04,
0x01, 0x03, 0x7f, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x4f, 0x04, 0x40,
0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x10, 0x0d, 0x20, 0x00, 0x0f, 0x0b,
0x20, 0x00, 0x20, 0x02, 0x6a, 0x21, 0x03, 0x02, 0x40, 0x20, 0x00, 0x20,
0x01, 0x73, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x02, 0x40, 0x20, 0x02,
0x41, 0x01, 0x48, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b,
0x20, 0x00, 0x41, 0x03, 0x71, 0x45, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02, 0x03, 0x40, 0x20, 0x02, 0x20,
0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a,
0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02, 0x20, 0x03, 0x4f,
0x0d, 0x01, 0x20, 0x02, 0x41, 0x03, 0x71, 0x0d, 0x00, 0x0b, 0x0b, 0x02,
0x40, 0x20, 0x03, 0x41, 0x7c, 0x71, 0x22, 0x04, 0x41, 0xc0, 0x00, 0x49,
0x0d, 0x00, 0x20, 0x02, 0x20, 0x04, 0x41, 0x40, 0x6a, 0x22, 0x05, 0x4b,
0x0d, 0x00, 0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36,
0x02, 0x00, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x04, 0x36, 0x02, 0x04,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x08, 0x36, 0x02, 0x08, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x0c, 0x36, 0x02, 0x0c, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x10, 0x36, 0x02, 0x10, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x14, 0x36, 0x02, 0x14, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x18, 0x36,
0x02, 0x18, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x1c, 0x36, 0x02, 0x1c,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x20, 0x36, 0x02, 0x20, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x24, 0x36, 0x02, 0x24, 0x20, 0x02, 0x20, 0x01,
0x28, 0x02, 0x28, 0x36, 0x02, 0x28, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02,
0x2c, 0x36, 0x02, 0x2c, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x30, 0x36,
0x02, 0x30, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x34, 0x36, 0x02, 0x34,
0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x38, 0x36, 0x02, 0x38, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x3c, 0x36, 0x02, 0x3c, 0x20, 0x01, 0x41, 0x40,
0x6b, 0x21, 0x01, 0x20, 0x02, 0x41, 0x40, 0x6b, 0x22, 0x02, 0x20, 0x05,
0x4d, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x04, 0x4f, 0x0d, 0x01,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x28, 0x02, 0x00, 0x36, 0x02, 0x00,
0x20, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x04, 0x6a,
0x22, 0x02, 0x20, 0x04, 0x49, 0x0d, 0x00, 0x0b, 0x0c, 0x01, 0x0b, 0x20,
0x03, 0x41, 0x04, 0x49, 0x04, 0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01,
0x0b, 0x20, 0x03, 0x41, 0x7c, 0x6a, 0x22, 0x04, 0x20, 0x00, 0x49, 0x04,
0x40, 0x20, 0x00, 0x21, 0x02, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x21, 0x02,
0x03, 0x40, 0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x3a, 0x00, 0x01, 0x20, 0x02,
0x20, 0x01, 0x2d, 0x00, 0x02, 0x3a, 0x00, 0x02, 0x20, 0x02, 0x20, 0x01,
0x2d, 0x00, 0x03, 0x3a, 0x00, 0x03, 0x20, 0x01, 0x41, 0x04, 0x6a, 0x21,
0x01, 0x20, 0x02, 0x41, 0x04, 0x6a, 0x22, 0x02, 0x20, 0x04, 0x4d, 0x0d,
0x00, 0x0b, 0x0b, 0x20, 0x02, 0x20, 0x03, 0x49, 0x04, 0x40, 0x03, 0x40,
0x20, 0x02, 0x20, 0x01, 0x2d, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x20, 0x01,
0x41, 0x01, 0x6a, 0x21, 0x01, 0x20, 0x02, 0x41, 0x01, 0x6a, 0x22, 0x02,
0x20, 0x03, 0x47, 0x0d, 0x00, 0x0b, 0x0b, 0x20, 0x00, 0x0b, 0x06, 0x00,
0x10, 0x0c, 0x41, 0x00, 0x0b, 0x03, 0x00, 0x01, 0x0b, 0x7e, 0x01, 0x03,
0x7f, 0x23, 0x00, 0x41, 0x10, 0x6b, 0x22, 0x01, 0x24, 0x00, 0x20, 0x01,
0x41, 0x0a, 0x3a, 0x00, 0x0f, 0x02, 0x40, 0x20, 0x00, 0x28, 0x02, 0x10,
0x22, 0x02, 0x45, 0x04, 0x40, 0x20, 0x00, 0x10, 0x02, 0x0d, 0x01, 0x20,
0x00, 0x28, 0x02, 0x10, 0x21, 0x02, 0x0b, 0x02, 0x40, 0x20, 0x00, 0x28,
0x02, 0x14, 0x22, 0x03, 0x20, 0x02, 0x4f, 0x0d, 0x00, 0x20, 0x00, 0x2c,
0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00, 0x20, 0x03, 0x41,
0x01, 0x6a, 0x36, 0x02, 0x14, 0x20, 0x03, 0x41, 0x0a, 0x3a, 0x00, 0x00,
0x0c, 0x01, 0x0b, 0x20, 0x00, 0x20, 0x01, 0x41, 0x0f, 0x6a, 0x41, 0x01,
0x20, 0x00, 0x28, 0x02, 0x24, 0x11, 0x00, 0x00, 0x41, 0x01, 0x47, 0x0d,
0x00, 0x20, 0x01, 0x2d, 0x00, 0x0f, 0x1a, 0x0b, 0x20, 0x01, 0x41, 0x10,
0x6a, 0x24, 0x00, 0x0b, 0x04, 0x00, 0x42, 0x00, 0x0b, 0x04, 0x00, 0x41,
0x00, 0x0b, 0x31, 0x01, 0x01, 0x7f, 0x20, 0x00, 0x21, 0x02, 0x20, 0x02,
0x02, 0x7f, 0x20, 0x01, 0x28, 0x02, 0x4c, 0x41, 0x7f, 0x4c, 0x04, 0x40,
0x20, 0x02, 0x20, 0x01, 0x10, 0x01, 0x0c, 0x01, 0x0b, 0x20, 0x02, 0x20,
0x01, 0x10, 0x01, 0x0b, 0x22, 0x01, 0x46, 0x04, 0x40, 0x20, 0x00, 0x0f,
0x0b, 0x20, 0x01, 0x0b, 0x62, 0x01, 0x03, 0x7f, 0x41, 0x80, 0x08, 0x21,
0x00, 0x03, 0x40, 0x20, 0x00, 0x22, 0x01, 0x41, 0x04, 0x6a, 0x21, 0x00,
0x20, 0x01, 0x28, 0x02, 0x00, 0x22, 0x02, 0x41, 0x7f, 0x73, 0x20, 0x02,
0x41, 0xff, 0xfd, 0xfb, 0x77, 0x6a, 0x71, 0x41, 0x80, 0x81, 0x82, 0x84,
0x78, 0x71, 0x45, 0x0d, 0x00, 0x0b, 0x02, 0x40, 0x20, 0x02, 0x41, 0xff,
0x01, 0x71, 0x45, 0x04, 0x40, 0x20, 0x01, 0x21, 0x00, 0x0c, 0x01, 0x0b,
0x03, 0x40, 0x20, 0x01, 0x2d, 0x00, 0x01, 0x21, 0x02, 0x20, 0x01, 0x41,
0x01, 0x6a, 0x22, 0x00, 0x21, 0x01, 0x20, 0x02, 0x0d, 0x00, 0x0b, 0x0b,
0x20, 0x00, 0x41, 0x80, 0x08, 0x6b, 0x0b, 0x0c, 0x00, 0x02, 0x7f, 0x41,
0x00, 0x41, 0x00, 0x10, 0x04, 0x0b, 0x1a, 0x0b, 0x66, 0x01, 0x02, 0x7f,
0x41, 0x90, 0x08, 0x28, 0x02, 0x00, 0x22, 0x00, 0x28, 0x02, 0x4c, 0x41,
0x00, 0x4e, 0x04, 0x7f, 0x41, 0x01, 0x05, 0x20, 0x01, 0x0b, 0x1a, 0x02,
0x40, 0x41, 0x7f, 0x41, 0x00, 0x10, 0x0a, 0x22, 0x01, 0x20, 0x01, 0x20,
0x00, 0x10, 0x09, 0x47, 0x1b, 0x41, 0x00, 0x48, 0x0d, 0x00, 0x02, 0x40,
0x20, 0x00, 0x2d, 0x00, 0x4b, 0x41, 0x0a, 0x46, 0x0d, 0x00, 0x20, 0x00,
0x28, 0x02, 0x14, 0x22, 0x01, 0x20, 0x00, 0x28, 0x02, 0x10, 0x4f, 0x0d,
0x00, 0x20, 0x00, 0x20, 0x01, 0x41, 0x01, 0x6a, 0x36, 0x02, 0x14, 0x20,
0x01, 0x41, 0x0a, 0x3a, 0x00, 0x00, 0x0c, 0x01, 0x0b, 0x20, 0x00, 0x10,
0x06, 0x0b, 0x0b, 0x3d, 0x01, 0x01, 0x7f, 0x20, 0x02, 0x04, 0x40, 0x03,
0x40, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02, 0x41, 0x80, 0xc0, 0x00, 0x20,
0x02, 0x41, 0x80, 0xc0, 0x00, 0x49, 0x1b, 0x22, 0x03, 0x10, 0x03, 0x21,
0x00, 0x20, 0x01, 0x41, 0x80, 0x40, 0x6b, 0x21, 0x01, 0x20, 0x00, 0x41,
0x80, 0x40, 0x6b, 0x21, 0x00, 0x20, 0x02, 0x20, 0x03, 0x6b, 0x22, 0x02,
0x0d, 0x00, 0x0b, 0x0b, 0x0b, 0xb1, 0x02, 0x01, 0x06, 0x7f, 0x23, 0x00,
0x41, 0x20, 0x6b, 0x22, 0x03, 0x24, 0x00, 0x20, 0x03, 0x20, 0x00, 0x28,
0x02, 0x1c, 0x22, 0x04, 0x36, 0x02, 0x10, 0x20, 0x00, 0x28, 0x02, 0x14,
0x21, 0x05, 0x20, 0x03, 0x20, 0x02, 0x36, 0x02, 0x1c, 0x20, 0x03, 0x20,
0x01, 0x36, 0x02, 0x18, 0x20, 0x03, 0x20, 0x05, 0x20, 0x04, 0x6b, 0x22,
0x01, 0x36, 0x02, 0x14, 0x20, 0x01, 0x20, 0x02, 0x6a, 0x21, 0x06, 0x41,
0x02, 0x21, 0x05, 0x20, 0x03, 0x41, 0x10, 0x6a, 0x21, 0x01, 0x03, 0x40,
0x02, 0x40, 0x02, 0x7f, 0x20, 0x06, 0x02, 0x7f, 0x20, 0x00, 0x28, 0x02,
0x3c, 0x20, 0x01, 0x20, 0x05, 0x20, 0x03, 0x41, 0x0c, 0x6a, 0x10, 0x00,
0x04, 0x40, 0x20, 0x03, 0x41, 0x7f, 0x36, 0x02, 0x0c, 0x41, 0x7f, 0x0c,
0x01, 0x0b, 0x20, 0x03, 0x28, 0x02, 0x0c, 0x0b, 0x22, 0x04, 0x46, 0x04,
0x40, 0x20, 0x00, 0x20, 0x00, 0x28, 0x02, 0x2c, 0x22, 0x01, 0x36, 0x02,
0x1c, 0x20, 0x00, 0x20, 0x01, 0x36, 0x02, 0x14, 0x20, 0x00, 0x20, 0x01,
0x20, 0x00, 0x28, 0x02, 0x30, 0x6a, 0x36, 0x02, 0x10, 0x20, 0x02, 0x0c,
0x01, 0x0b, 0x20, 0x04, 0x41, 0x7f, 0x4a, 0x0d, 0x01, 0x20, 0x00, 0x41,
0x00, 0x36, 0x02, 0x1c, 0x20, 0x00, 0x42, 0x00, 0x37, 0x03, 0x10, 0x20,
0x00, 0x20, 0x00, 0x28, 0x02, 0x00, 0x41, 0x20, 0x72, 0x36, 0x02, 0x00,
0x41, 0x00, 0x20, 0x05, 0x41, 0x02, 0x46, 0x0d, 0x00, 0x1a, 0x20, 0x02,
0x20, 0x01, 0x28, 0x02, 0x04, 0x6b, 0x0b, 0x21, 0x04, 0x20, 0x03, 0x41,
0x20, 0x6a, 0x24, 0x00, 0x20, 0x04, 0x0f, 0x0b, 0x20, 0x01, 0x41, 0x08,
0x6a, 0x20, 0x01, 0x20, 0x04, 0x20, 0x01, 0x28, 0x02, 0x04, 0x22, 0x07,
0x4b, 0x22, 0x08, 0x1b, 0x22, 0x01, 0x20, 0x04, 0x20, 0x07, 0x41, 0x00,
0x20, 0x08, 0x1b, 0x6b, 0x22, 0x07, 0x20, 0x01, 0x28, 0x02, 0x00, 0x6a,
0x36, 0x02, 0x00, 0x20, 0x01, 0x20, 0x01, 0x28, 0x02, 0x04, 0x20, 0x07,
0x6b, 0x36, 0x02, 0x04, 0x20, 0x06, 0x20, 0x04, 0x6b, 0x21, 0x06, 0x20,
0x05, 0x20, 0x08, 0x6b, 0x21, 0x05, 0x0c, 0x00, 0x00, 0x0b, 0x00, 0x0b,
0x0b, 0x4d, 0x06, 0x00, 0x41, 0x80, 0x08, 0x0b, 0x12, 0x68, 0x65, 0x6c,
0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x00, 0x00,
0x00, 0x18, 0x04, 0x00, 0x41, 0x98, 0x08, 0x0b, 0x01, 0x05, 0x00, 0x41,
0xa4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xbc, 0x08, 0x0b, 0x0e, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb8, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x41, 0xd4, 0x08, 0x0b, 0x01, 0x01, 0x00, 0x41, 0xe3, 0x08,
0x0b, 0x05, 0x0a, 0xff, 0xff, 0xff, 0xff,
]);
// Trying to import WASI twice.
expect(
() => WasmModule(helloWorldData).builder()..enableWasi()..enableWasi(),
throwsWasmError(startsWith('WASI is already enabled')),
);
// Missing imports due to not enabling WASI.
expect(
() => WasmModule(helloWorldData).builder().build(),
throwsWasmError(startsWith('Missing import: ')),
);
// Trying to get stdout/stderr without WASI enabled (WASI function import has
// been manually filled).
var inst = (WasmModule(helloWorldData).builder()
..addFunction(
'wasi_unstable',
'fd_write',
(int fd, int iovs, int iovsLen, int unused) => 0,
))
.build();
expect(
() => inst.stdout,
throwsWasmError("Can't capture stdout without WASI enabled."),
);
expect(
() => inst.stderr,
throwsWasmError("Can't capture stderr without WASI enabled."),
);
});
}

View file

@ -1,389 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
# This is an ad-hoc script that generates FFI boilderplate for the Wasmer API.
# The relevant functions from wasm.h have been copied below, and are parsed to
# figure out the FFI boilerplate. The results are inserted into
# wasmer_api_template.dart and runtime_template.dart to generate wasmer_api.dart
# and runtime.dart.
# Usage:
# ./generate_ffi_boilerplate.py && dart format -owrite ../lib/
import os
import re
predefTypes = {}
opaqueTypes = set()
vecTypes = {}
fns = []
unusedFns = set()
def camel(t):
return ''.join([s[0].upper() + s[1:] for s in t.split('_')])
def ptrWrap(t, n):
for i in range(n):
t = 'Pointer<%s>' % t
return t
def removePrefix(t):
assert (t.startswith('wasm_') or t.startswith('wasi_') or
t.startswith('wasmer_') or t.startswith('Dart_') or
t.startswith('set_finalizer_'))
return t[(5 if t.startswith('wasm_') else 0):]
def addPrefix(t):
if t.startswith('wasi_') or t.startswith('wasmer_') or t.startswith(
'Dart_') or t.startswith('set_finalizer_'):
return t
return 'wasm_' + t
def getDartType(t, i):
if t in predefTypes:
return predefTypes[t][i]
assert (t.endswith('_t'))
return 'Wasmer' + camel(removePrefix(t[:-2]))
def dartArgType(a, i):
n, t = a
j = i if n == 0 else 0
return ptrWrap(getDartType(t, j), n)
def dartFnType(r, a, i):
return '%s Function(%s)' % (dartArgType(r, i), ', '.join(
[dartArgType(t, i) for t in a]))
def dartFnTypeName(n):
return camel(removePrefix(n))
def dartFnMembName(n):
return '_' + removePrefix(n)
def nativeTypeToFfi(n):
return getDartType(n, 0)
def nativeTypeToDart(n):
return getDartType(n, 1)
def getFns():
for name, retType, args in sorted(fns):
if name not in unusedFns:
yield name, retType, args
opaqueTypeTemplate = '''// %s_t
class Wasmer%s extends Opaque {}'''
vecTypeTemplate = '''// %s_vec_t
class Wasmer%sVec extends Struct {
@Uint64()
external int length;
external Pointer<%s> data;
%s
}'''
byteVecToStringTemplate = '''
Uint8List get list => data.asTypedList(length);
@override
String toString() => utf8.decode(list);
'''
fnApiTemplate = '''
// %s
typedef NativeWasmer%sFn = %s;
typedef Wasmer%sFn = %s;'''
def getWasmerApi():
return ('\n\n'.join([
opaqueTypeTemplate % (addPrefix(t), camel(t))
for t in sorted(opaqueTypes)
]) + '\n\n' + '\n\n'.join([
vecTypeTemplate % (addPrefix(t), camel(t),
('Pointer<%s>' if ptr else '%s') %
nativeTypeToFfi('%s_t' % addPrefix(t)),
(byteVecToStringTemplate if t == 'byte' else ''))
for t, ptr in sorted(vecTypes.items())
]) + '\n' + '\n'.join([
fnApiTemplate %
(name, dartFnTypeName(name), dartFnType(retType, args, 0),
dartFnTypeName(name), dartFnType(retType, args, 1))
for name, retType, args in getFns()
]))
def getRuntimeMemb():
return '\n'.join([
" late final Wasmer%sFn %s;" %
(dartFnTypeName(name), dartFnMembName(name)) for name, _, _ in getFns()
])
def getRuntimeLoad():
return '\n'.join([
" %s = _lib.lookupFunction<NativeWasmer%sFn, Wasmer%sFn>('%s',);" %
(dartFnMembName(name), dartFnTypeName(name), dartFnTypeName(name), name)
for name, _, _ in getFns()
])
def predefinedType(nativeType, ffiType, dartType):
predefTypes[nativeType] = (ffiType, dartType)
def match(r, s):
return r.fullmatch(s).groups()
reReplace = [(re.compile('\\b%s\\b' % k), v) for k, v in [
('const', ''),
('own', ''),
('WASM_API_EXTERN', ''),
('wasm_name_t', 'wasm_byte_vec_t'),
('wasm_message_t', 'wasm_byte_vec_t'),
('wasm_memory_pages_t', 'uint32_t'),
('wasm_externkind_t', 'uint8_t'),
('wasm_valkind_t', 'uint8_t'),
]]
reWord = re.compile(r'\b\w+\b')
def parseType(s):
for r, t in reReplace:
s = r.sub(t, s)
s = s.strip()
numWords = len(reWord.findall(s))
assert (numWords == 1 or numWords == 2)
if numWords == 2:
i = 0
def lastWordRepl(m):
nonlocal i
i += 1
return '' if i == numWords else m.group(0)
s = reWord.sub(lastWordRepl, s)
numPtr = 0
while True:
s = s.strip()
if s.endswith('*'):
s = s[:-1]
elif s.endswith('[]'):
s = s[:-2]
else:
break
numPtr += 1
return (numPtr, s)
reFnSig = re.compile(r'(.*) ([^ ]*)\((.*)\);?')
def addFn(sig):
ret, name, argpack = match(reFnSig, sig)
retType = parseType(ret)
args = [parseType(a) for a in argpack.split(',') if len(a.strip()) > 0]
for _, t in args + [retType]:
if t not in predefTypes and removePrefix(
t[:-2]) not in opaqueTypes and removePrefix(
t[:-6]) not in vecTypes:
print('Missing type: ' + t)
fns.append((name, retType, args))
def declareOwn(name):
opaqueTypes.add(name)
n = addPrefix(name)
addFn('void %s_delete(%s_t*)' % (n, n))
def declareVec(name, storePtr):
vecTypes[name] = storePtr
n = addPrefix(name)
addFn('void %s_vec_new_empty(%s_vec_t* out)' % (n, n))
addFn('void %s_vec_new_uninitialized(%s_vec_t* out, size_t)' % (n, n))
addFn('void %s_vec_new(%s_vec_t* out, size_t, %s_t %s[])' %
(n, n, n, '*' if storePtr else ''))
addFn('void %s_vec_copy(%s_vec_t* out, const %s_vec_t*)' % (n, n, n))
addFn('void %s_vec_delete(%s_vec_t*)' % (n, n))
def declareType(name, withCopy=True):
declareOwn(name)
declareVec(name, True)
if withCopy:
n = addPrefix(name)
addFn('%s_t* %s_copy(%s_t*)' % (n, n, n))
predefinedType('void', 'Void', 'void')
predefinedType('bool', 'Uint8', 'int')
predefinedType('int', 'Int64', 'int')
predefinedType('byte_t', 'Uint8', 'int')
predefinedType('wasm_byte_t', 'Uint8', 'int')
predefinedType('uint8_t', 'Uint8', 'int')
predefinedType('uint16_t', 'Uint16', 'int')
predefinedType('uint32_t', 'Uint32', 'int')
predefinedType('uint64_t', 'Uint64', 'int')
predefinedType('size_t', 'Uint64', 'int')
predefinedType('uintptr_t', 'Uint64', 'int')
predefinedType('intptr_t', 'Int64', 'int')
predefinedType('int8_t', 'Int8', 'int')
predefinedType('int16_t', 'Int16', 'int')
predefinedType('int32_t', 'Int32', 'int')
predefinedType('int64_t', 'Int64', 'int')
predefinedType('float32_t', 'Float32', 'double')
predefinedType('float64_t', 'Float64', 'double')
predefinedType('wasm_limits_t', 'WasmerLimits', 'WasmerLimits')
predefinedType('wasm_val_t', 'WasmerVal', 'WasmerVal')
predefinedType('Dart_Handle', 'Handle', 'Object')
declareOwn('engine')
declareOwn('store')
declareOwn('wasi_config')
declareOwn('wasi_env')
declareVec('byte', False)
declareVec('val', False)
declareType('importtype')
declareType('exporttype')
declareType('valtype')
declareType('extern', False)
# These are actually DECLARE_TYPE, but we don't need the vec or copy stuff.
declareOwn('memorytype')
declareOwn('externtype')
declareOwn('functype')
# These are actually DECLARE_SHARABLE_REF, but we don't need the ref stuff.
declareOwn('module')
# These are actually DECLARE_REF, but we don't need the ref stuff.
declareOwn('memory')
declareOwn('trap')
declareOwn('instance')
declareOwn('func')
rawFns = '''
WASM_API_EXTERN own wasm_engine_t* wasm_engine_new();
WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
WASM_API_EXTERN own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t*);
WASM_API_EXTERN own wasm_module_t* wasm_module_new(wasm_store_t*, const wasm_byte_vec_t* binary);
WASM_API_EXTERN void wasm_module_imports(const wasm_module_t*, own wasm_importtype_vec_t* out);
WASM_API_EXTERN const wasm_name_t* wasm_importtype_module(const wasm_importtype_t*);
WASM_API_EXTERN const wasm_name_t* wasm_importtype_name(const wasm_importtype_t*);
WASM_API_EXTERN const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t*);
WASM_API_EXTERN wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t*);
WASM_API_EXTERN void wasm_module_exports(const wasm_module_t*, own wasm_exporttype_vec_t* out);
WASM_API_EXTERN const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t*);
WASM_API_EXTERN const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t*);
WASM_API_EXTERN wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t*);
WASM_API_EXTERN own wasm_instance_t* wasm_instance_new(wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports, own wasm_trap_t**);
WASM_API_EXTERN void wasm_instance_exports(const wasm_instance_t*, own wasm_extern_vec_t* out);
WASM_API_EXTERN own wasm_memory_t* wasm_memory_new(wasm_store_t*, const wasm_memorytype_t*);
WASM_API_EXTERN byte_t* wasm_memory_data(wasm_memory_t*);
WASM_API_EXTERN size_t wasm_memory_data_size(const wasm_memory_t*);
WASM_API_EXTERN wasm_memory_pages_t wasm_memory_size(const wasm_memory_t*);
WASM_API_EXTERN bool wasm_memory_grow(wasm_memory_t*, wasm_memory_pages_t delta);
WASM_API_EXTERN wasm_externkind_t wasm_extern_kind(const wasm_extern_t*);
WASM_API_EXTERN wasm_func_t* wasm_extern_as_func(wasm_extern_t*);
WASM_API_EXTERN wasm_extern_t* wasm_func_as_extern(wasm_func_t*);
WASM_API_EXTERN wasm_memory_t* wasm_extern_as_memory(wasm_extern_t*);
WASM_API_EXTERN wasm_extern_t* wasm_memory_as_extern(wasm_memory_t*);
WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t*);
WASM_API_EXTERN const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t*);
WASM_API_EXTERN own wasm_func_t* wasm_func_new_with_env( wasm_store_t*, const wasm_functype_t* type, void* fn, void* env, void *finalizer);
WASM_API_EXTERN own wasm_trap_t* wasm_func_call(const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results);
WASM_API_EXTERN own wasm_trap_t* wasm_trap_new(wasm_store_t* store, const wasm_message_t*);
WASM_API_EXTERN void wasm_trap_message(const wasm_trap_t*, own wasm_message_t* out);
WASM_API_EXTERN wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t*);
wasi_config_t* wasi_config_new(const uint8_t* program_name);
wasi_env_t* wasi_env_new(wasi_config_t* config);
bool wasi_get_imports(const wasm_store_t* store, const wasm_module_t* module, const wasi_env_t* wasi_env, wasm_extern_vec_t* imports);
int wasmer_last_error_message(uint8_t* buffer, int length);
int wasmer_last_error_length();
void wasi_env_set_memory(wasi_env_t* env, const wasm_memory_t* memory);
void wasi_config_inherit_stdout(wasi_config_t* config);
void wasi_config_inherit_stderr(wasi_config_t* config);
intptr_t wasi_env_read_stderr(wasi_env_t* env, uint8_t* buffer, uintptr_t buffer_len);
intptr_t wasi_env_read_stdout(wasi_env_t* env, uint8_t* buffer, uintptr_t buffer_len);
intptr_t Dart_InitializeApiDL(void* data);
void set_finalizer_for_engine(Dart_Handle, wasm_engine_t*);
void set_finalizer_for_store(Dart_Handle, wasm_store_t*);
void set_finalizer_for_module(Dart_Handle, wasm_module_t*);
void set_finalizer_for_instance(Dart_Handle, wasm_instance_t*);
void set_finalizer_for_trap(Dart_Handle, wasm_trap_t*);
void set_finalizer_for_memorytype(Dart_Handle, wasm_memorytype_t*);
void set_finalizer_for_memory(Dart_Handle, wasm_memory_t*);
void set_finalizer_for_func(Dart_Handle, wasm_func_t*);
'''
for f in rawFns.split('\n'):
if len(f.strip()) > 0:
addFn(f)
unusedFns = {
'wasm_byte_vec_copy',
'wasm_exporttype_delete',
'wasm_exporttype_copy',
'wasm_exporttype_vec_copy',
'wasm_extern_vec_copy',
'wasm_importtype_delete',
'wasm_importtype_copy',
'wasm_importtype_vec_copy',
'wasm_val_vec_copy',
'wasm_val_vec_delete',
'wasm_val_vec_new',
'wasm_val_vec_new_empty',
'wasm_val_vec_new_uninitialized',
'wasm_valtype_copy',
'wasm_valtype_vec_copy',
'wasi_config_delete',
}
genDoc = '''// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use the following command
// "generate_ffi_boilerplate.py".'''
thisDir = os.path.dirname(os.path.abspath(__file__))
def readFile(filename):
with open(os.path.abspath(os.path.join(thisDir, filename)), 'r') as f:
return f.read()
def writeFile(filename, content):
with open(os.path.abspath(os.path.join(thisDir, '../lib/src', filename)),
'w') as f:
f.write(content)
wasmerApiText = readFile('wasmer_api_template.dart.t')
wasmerApiText = wasmerApiText.replace('/* <WASMER_API> */', getWasmerApi())
wasmerApiText = wasmerApiText.replace('/* <GEN_DOC> */', genDoc)
writeFile('wasmer_api.g.dart', wasmerApiText)
runtimeText = readFile('runtime_template.dart.t')
runtimeText = runtimeText.replace('/* <RUNTIME_MEMB> */', getRuntimeMemb())
runtimeText = runtimeText.replace('/* <RUNTIME_LOAD> */', getRuntimeLoad())
runtimeText = runtimeText.replace('/* <GEN_DOC> */', genDoc)
writeFile('runtime.g.dart', runtimeText)

View file

@ -1,350 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/* <GEN_DOC> */
// ignore_for_file: cascade_invocations
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: unused_field
part of 'runtime.dart';
class WasmRuntime {
static final WasmRuntime _inst = WasmRuntime._init();
final DynamicLibrary _lib;
final _traps = <int, _WasmTrapsEntry>{};
late final Pointer<WasmerEngine> _engine;
/* <RUNTIME_MEMB> */
factory WasmRuntime() => _inst;
WasmRuntime._init() : _lib = DynamicLibrary.open(_getLibPath()) {
/* <RUNTIME_LOAD> */
if (_Dart_InitializeApiDL(NativeApi.initializeApiDLData) != 0) {
throw WasmError('Failed to initialize Dart API');
}
_engine = _engine_new();
_checkNotEqual(_engine, nullptr, 'Failed to initialize Wasm engine.');
_set_finalizer_for_engine(this, _engine);
}
Pointer<WasmerStore> newStore(Object owner) {
var store = _checkNotEqual(
_store_new(_engine),
nullptr,
'Failed to create Wasm store.',
);
_set_finalizer_for_store(owner, store);
return store;
}
Pointer<WasmerModule> compile(
Object owner,
Pointer<WasmerStore> store,
Uint8List data,
) {
var dataPtr = calloc<Uint8>(data.length);
for (var i = 0; i < data.length; ++i) {
dataPtr[i] = data[i];
}
var dataVec = calloc<WasmerByteVec>();
dataVec.ref.data = dataPtr;
dataVec.ref.length = data.length;
var modulePtr = _module_new(store, dataVec);
calloc.free(dataPtr);
calloc.free(dataVec);
_checkNotEqual(modulePtr, nullptr, 'Wasm module compile failed.');
_set_finalizer_for_module(owner, modulePtr);
return modulePtr;
}
List<WasmExportDescriptor> exportDescriptors(Pointer<WasmerModule> module) {
var exportsVec = calloc<WasmerExporttypeVec>();
_module_exports(module, exportsVec);
var exps = <WasmExportDescriptor>[];
for (var i = 0; i < exportsVec.ref.length; ++i) {
var exp = exportsVec.ref.data[i];
var extern = _exporttype_type(exp);
var kind = _externtype_kind(extern);
var fnType = kind == wasmerExternKindFunction
? _externtype_as_functype(extern)
: nullptr;
exps.add(
WasmExportDescriptor._(
kind,
_exporttype_name(exp).ref.toString(),
fnType,
),
);
}
calloc.free(exportsVec);
return exps;
}
List<WasmImportDescriptor> importDescriptors(Pointer<WasmerModule> module) {
var importsVec = calloc<WasmerImporttypeVec>();
_module_imports(module, importsVec);
var imps = <WasmImportDescriptor>[];
for (var i = 0; i < importsVec.ref.length; ++i) {
var imp = importsVec.ref.data[i];
var extern = _importtype_type(imp);
var kind = _externtype_kind(extern);
var fnType = kind == wasmerExternKindFunction
? _externtype_as_functype(extern)
: nullptr;
imps.add(
WasmImportDescriptor._(
kind,
_importtype_module(imp).ref.toString(),
_importtype_name(imp).ref.toString(),
fnType,
),
);
}
calloc.free(importsVec);
return imps;
}
void maybeThrowTrap(Pointer<WasmerTrap> trap, String source) {
if (trap != nullptr) {
// There are 2 kinds of trap, and their memory is managed differently.
// Traps created in the newTrap method below are stored in the traps map
// with a corresponding exception, and their memory is managed using a
// finalizer on the _WasmTrapsEntry. Traps can also be created by WASM
// code, and in that case we delete them in this function.
var entry = _traps.remove(trap.address);
if (entry != null) {
// ignore: only_throw_errors
throw entry.exception;
} else {
// TODO: code path not hit in tests!
var trapMessage = calloc<WasmerByteVec>();
_trap_message(trap, trapMessage);
var message = 'Wasm trap when calling $source: ${trapMessage.ref}';
_byte_vec_delete(trapMessage);
calloc.free(trapMessage);
_trap_delete(trap);
throw WasmError(message);
}
}
}
Pointer<WasmerInstance> instantiate(
Object owner,
Pointer<WasmerStore> store,
Pointer<WasmerModule> module,
Pointer<WasmerExternVec> imports,
) {
var trap = calloc<Pointer<WasmerTrap>>();
trap.value = nullptr;
var inst = _instance_new(store, module, imports, trap);
maybeThrowTrap(trap.value, 'module initialization function');
calloc.free(trap);
_checkNotEqual(inst, nullptr, 'Wasm module instantiation failed.');
_set_finalizer_for_instance(owner, inst);
return inst;
}
// Clean up the exports after use, with deleteExports.
Pointer<WasmerExternVec> exports(Pointer<WasmerInstance> instancePtr) {
var exports = calloc<WasmerExternVec>();
_instance_exports(instancePtr, exports);
return exports;
}
void deleteExports(Pointer<WasmerExternVec> exports) {
_extern_vec_delete(exports);
calloc.free(exports);
}
int externKind(Pointer<WasmerExtern> extern) => _extern_kind(extern);
Pointer<WasmerFunc> externToFunction(Pointer<WasmerExtern> extern) =>
_extern_as_func(extern);
Pointer<WasmerExtern> functionToExtern(Pointer<WasmerFunc> func) =>
_func_as_extern(func);
List<int> getArgTypes(Pointer<WasmerFunctype> funcType) {
var types = <int>[];
var args = _functype_params(funcType);
for (var i = 0; i < args.ref.length; ++i) {
types.add(_valtype_kind(args.ref.data[i]));
}
return types;
}
int getReturnType(Pointer<WasmerFunctype> funcType) {
var rets = _functype_results(funcType);
if (rets.ref.length == 0) {
return wasmerValKindVoid;
} else if (rets.ref.length > 1) {
throw WasmError('Multiple return values are not supported');
}
return _valtype_kind(rets.ref.data[0]);
}
void call(
Pointer<WasmerFunc> func,
Pointer<WasmerValVec> args,
Pointer<WasmerValVec> results,
String source,
) {
maybeThrowTrap(_func_call(func, args, results), source);
}
Pointer<WasmerMemory> externToMemory(Pointer<WasmerExtern> extern) =>
_extern_as_memory(extern);
Pointer<WasmerExtern> memoryToExtern(Pointer<WasmerMemory> memory) =>
_memory_as_extern(memory);
Pointer<WasmerMemory> newMemory(
Object owner,
Pointer<WasmerStore> store,
int pages,
int? maxPages,
) {
var limPtr = calloc<WasmerLimits>();
limPtr.ref.min = pages;
limPtr.ref.max = maxPages ?? wasmLimitsMaxDefault;
var memType = _memorytype_new(limPtr);
calloc.free(limPtr);
_checkNotEqual(memType, nullptr, 'Failed to create memory type.');
_set_finalizer_for_memorytype(owner, memType);
var memory = _checkNotEqual(
_memory_new(store, memType),
nullptr,
'Failed to create memory.',
);
_set_finalizer_for_memory(owner, memory);
return memory;
}
void growMemory(Pointer<WasmerMemory> memory, int deltaPages) {
_checkNotEqual(
_memory_grow(memory, deltaPages),
0,
'Failed to grow memory.',
);
}
int memoryLength(Pointer<WasmerMemory> memory) => _memory_size(memory);
Uint8List memoryView(Pointer<WasmerMemory> memory) =>
_memory_data(memory).asTypedList(_memory_data_size(memory));
Pointer<WasmerFunc> newFunc(
Object owner,
Pointer<WasmerStore> store,
Pointer<WasmerFunctype> funcType,
Pointer func,
Pointer env,
Pointer finalizer,
) {
var f = _func_new_with_env(
store,
funcType,
func.cast(),
env.cast(),
finalizer.cast(),
);
_checkNotEqual(f, nullptr, 'Failed to create function.');
_set_finalizer_for_func(owner, f);
return f;
}
Pointer<WasmerTrap> newTrap(Pointer<WasmerStore> store, Object exception) {
var msg = calloc<WasmerByteVec>();
msg.ref.data = calloc<Uint8>();
msg.ref.data[0] = 0;
msg.ref.length = 0;
var trap = _trap_new(store, msg);
calloc.free(msg.ref.data);
calloc.free(msg);
_checkNotEqual(trap, nullptr, 'Failed to create trap.');
var entry = _WasmTrapsEntry(exception);
_set_finalizer_for_trap(entry, trap);
_traps[trap.address] = entry;
return trap;
}
Pointer<WasmerWasiConfig> newWasiConfig() {
var name = calloc<Uint8>();
name[0] = 0;
var config = _wasi_config_new(name);
calloc.free(name);
return _checkNotEqual(config, nullptr, 'Failed to create WASI config.');
}
void captureWasiStdout(Pointer<WasmerWasiConfig> config) {
_wasi_config_inherit_stdout(config);
}
void captureWasiStderr(Pointer<WasmerWasiConfig> config) {
_wasi_config_inherit_stderr(config);
}
Pointer<WasmerWasiEnv> newWasiEnv(Pointer<WasmerWasiConfig> config) =>
_checkNotEqual(
_wasi_env_new(config),
nullptr,
'Failed to create WASI environment.',
);
void wasiEnvSetMemory(
Pointer<WasmerWasiEnv> env,
Pointer<WasmerMemory> memory,
) {
_wasi_env_set_memory(env, memory);
}
void getWasiImports(
Pointer<WasmerStore> store,
Pointer<WasmerModule> mod,
Pointer<WasmerWasiEnv> env,
Pointer<WasmerExternVec> imports,
) {
_checkNotEqual(
_wasi_get_imports(store, mod, env, imports),
0,
'Failed to fill WASI imports.',
);
}
Stream<List<int>> getWasiStdoutStream(Pointer<WasmerWasiEnv> env) =>
Stream.fromIterable(_WasiStreamIterable(env, _wasi_env_read_stdout));
Stream<List<int>> getWasiStderrStream(Pointer<WasmerWasiEnv> env) =>
Stream.fromIterable(_WasiStreamIterable(env, _wasi_env_read_stderr));
String _getLastError() {
var length = _wasmer_last_error_length();
var buf = calloc<Uint8>(length);
_wasmer_last_error_message(buf, length);
var message = utf8.decode(buf.asTypedList(length));
calloc.free(buf);
return message;
}
T _checkNotEqual<T>(T x, T y, String errorMessage) {
if (x == y) {
throw WasmError('$errorMessage\n${_getLastError()}'.trim());
}
return x;
}
static String getSignatureString(
String name,
List<int> argTypes,
int returnType,
) =>
'${wasmerValKindName(returnType)} '
"$name(${argTypes.map(wasmerValKindName).join(", ")})";
}

View file

@ -1,11 +0,0 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/* <GEN_DOC> */
// ignore_for_file: require_trailing_commas
part of 'wasmer_api.dart';
/* <WASMER_API> */

View file

@ -3356,14 +3356,6 @@
"pkg/vm_snapshot_analysis"
]
},
{
"name": "analyze pkg/wasm",
"script": "out/ReleaseX64/dart-sdk/bin/dart",
"arguments": [
"analyze",
"pkg/wasm"
]
},
{
"name": "analyze pkg/dds",
"script": "out/ReleaseX64/dart-sdk/bin/dart",