Skip to content

Commit 05c28c6

Browse files
liamappelbecommit-bot@chromium.org
authored andcommitted
Reland "Scaffolding for dart:wasm"
This reverts commit 9198813. Reason for revert: Relanding with a fix Original change's description: > Revert "Scaffolding for dart:wasm" > > This reverts commit f39a3f1. > > Reason for revert: https://golem.corp.goog/BuildInfo?target=flutter-profile&machine-type=android-armv7&revision=84750 > > Original change's description: > > Scaffolding for dart:wasm > > > > This CL doesn't have any tests because it's just boilerplate. I'll > > add a test in the follow up CLs where I add actual functionality. > > > > Bug: #37882 > > Change-Id: I47c81f5f1be724f8226e756ba5d01880a45f1ac7 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112841 > > Reviewed-by: Siva Annamalai <[email protected]> > > Reviewed-by: Liam Appelbe <[email protected]> > > Commit-Queue: Liam Appelbe <[email protected]> > > [email protected],[email protected] > > Change-Id: I0fd0f29d66a07fc29e840ddaec2d4161c8d599cb > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: #37882 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114044 > Reviewed-by: Liam Appelbe <[email protected]> > Commit-Queue: Liam Appelbe <[email protected]> [email protected],[email protected] # Not skipping CQ checks because original CL landed > 1 day ago. Bug: #37882 Change-Id: Idb43cbd3a0521776ac420bfef91c8a9a4362f18e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114757 Reviewed-by: Liam Appelbe <[email protected]> Commit-Queue: Liam Appelbe <[email protected]>
1 parent d57a8f7 commit 05c28c6

File tree

20 files changed

+113
-4
lines changed

20 files changed

+113
-4
lines changed

pkg/vm/lib/target/dart_runner.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class DartRunnerTarget extends VmTarget {
3636
'dart:typed_data',
3737
'dart:nativewrappers',
3838
'dart:io',
39+
'dart:wasm',
3940

4041
// Required for dart_runner.
4142
'dart:fuchsia.builtin',

pkg/vm/lib/target/flutter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FlutterTarget extends VmTarget {
4141
'dart:typed_data',
4242
'dart:nativewrappers',
4343
'dart:io',
44+
'dart:wasm',
4445

4546
// Required for flutter.
4647
'dart:ui',

pkg/vm/lib/target/flutter_runner.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FlutterRunnerTarget extends VmTarget {
3636
'dart:typed_data',
3737
'dart:nativewrappers',
3838
'dart:io',
39+
'dart:wasm',
3940

4041
// Required for flutter_runner.
4142
'dart:fuchsia.builtin',

pkg/vm/lib/target/vm.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class VmTarget extends Target {
7777
'dart:nativewrappers',
7878
'dart:io',
7979
'dart:cli',
80+
'dart:wasm',
8081
];
8182

8283
void _patchVmConstants(CoreTypes coreTypes) {

runtime/lib/wasm.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
#include "platform/unicode.h"
6+
#include "vm/bootstrap_natives.h"
7+
#include "vm/dart_entry.h"
8+
9+
namespace dart {
10+
11+
int callWasm(const char* name, int n) {
12+
return 100 * n;
13+
}
14+
15+
// This is a temporary API for prototyping.
16+
DEFINE_NATIVE_ENTRY(Wasm_callFunction, 0, 2) {
17+
GET_NON_NULL_NATIVE_ARGUMENT(String, fn_name, arguments->NativeArgAt(0));
18+
GET_NON_NULL_NATIVE_ARGUMENT(Integer, arg, arguments->NativeArgAt(1));
19+
20+
intptr_t len = Utf8::Length(fn_name);
21+
std::unique_ptr<char> name = std::unique_ptr<char>(new char[len + 1]);
22+
fn_name.ToUTF8(reinterpret_cast<uint8_t*>(name.get()), len);
23+
name.get()[len] = 0;
24+
25+
return Smi::New(callWasm(name.get(), arg.AsInt64Value()));
26+
}
27+
28+
} // namespace dart

runtime/lib/wasm_patch.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "dart:_internal" show patch;
6+
7+
@patch
8+
int _callWasm(String name, int arg) native "Wasm_callFunction";

runtime/lib/wasm_sources.gni

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE file.
4+
5+
wasm_runtime_cc_files = [ "wasm.cc" ]
6+
7+
wasm_runtime_dart_files = [ "wasm_patch.dart" ]

runtime/vm/BUILD.gn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("../../sdk/lib/mirrors/mirrors_sources.gni")
1616
import("../../sdk/lib/profiler/profiler_sources.gni")
1717
import("../../sdk/lib/typed_data/typed_data_sources.gni")
1818
import("../../sdk/lib/vmservice/vmservice_sources.gni")
19+
import("../../sdk/lib/wasm/wasm_sources.gni")
1920
import("../../utils/compile_platform.gni")
2021
import("../bin/cli_sources.gni")
2122
import("../bin/io_sources.gni")
@@ -33,6 +34,7 @@ import("../lib/mirrors_sources.gni")
3334
import("../lib/profiler_sources.gni")
3435
import("../lib/typed_data_sources.gni")
3536
import("../lib/vmservice_sources.gni")
37+
import("../lib/wasm_sources.gni")
3638
import("../runtime_args.gni")
3739
import("compiler/compiler_sources.gni")
3840
import("heap/heap_sources.gni")
@@ -106,7 +108,7 @@ library_for_all_configs("libdart_lib") {
106108
internal_runtime_cc_files + isolate_runtime_cc_files +
107109
math_runtime_cc_files + mirrors_runtime_cc_files +
108110
typed_data_runtime_cc_files + vmservice_runtime_cc_files +
109-
ffi_runtime_cc_files
111+
ffi_runtime_cc_files + wasm_runtime_cc_files
110112
sources = [ "bootstrap.cc" ] + rebase_path(allsources, ".", "../lib")
111113
snapshot_sources = []
112114
nosnapshot_sources = []

runtime/vm/bootstrap_natives.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ void Bootstrap::SetupNativeResolver() {
141141
ASSERT(!library.IsNull());
142142
library.set_native_entry_resolver(resolver);
143143
library.set_native_entry_symbol_resolver(symbol_resolver);
144+
145+
library = Library::WasmLibrary();
146+
ASSERT(!library.IsNull());
147+
library.set_native_entry_resolver(resolver);
148+
library.set_native_entry_symbol_resolver(symbol_resolver);
144149
}
145150

146151
bool Bootstrap::IsBootstrapResolver(Dart_NativeEntryResolver resolver) {

runtime/vm/bootstrap_natives.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace dart {
1313

1414
// List of bootstrap native entry points used in the core dart library.
15+
// V(function_name, argument_count)
1516
#define BOOTSTRAP_NATIVE_LIST(V) \
1617
V(AsyncStarMoveNext_debuggerStepCheck, 1) \
1718
V(DartAsync_fatal, 1) \
@@ -392,7 +393,8 @@ namespace dart {
392393
V(Ffi_dl_processLibrary, 0) \
393394
V(Ffi_dl_executableLibrary, 0) \
394395
V(TransferableTypedData_factory, 2) \
395-
V(TransferableTypedData_materialize, 1)
396+
V(TransferableTypedData_materialize, 1) \
397+
V(Wasm_callFunction, 2)
396398

397399
// List of bootstrap native entry points used in the dart:mirror library.
398400
#define MIRRORS_BOOTSTRAP_NATIVE_LIST(V) \

0 commit comments

Comments
 (0)