Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WASM API and Embedder Builtins to V8 #1

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deps/v8/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1970,13 +1970,16 @@ v8_source_set("v8_base_without_compiler") {
"include/v8-testing.h",
"include/v8-util.h",
"include/v8-wasm-trap-handler-posix.h",
"include/v8-wasm.h"
"include/v8.h",
"include/v8config.h",
"src/api/api-arguments-inl.h",
"src/api/api-arguments.cc",
"src/api/api-arguments.h",
"src/api/api-natives.cc",
"src/api/api-natives.h",
"src/api/api-wasm.cc",
"src/api/api-wasm.h",
"src/api/api.cc",
"src/api/api.h",
"src/asmjs/asm-js.cc",
Expand Down
123 changes: 123 additions & 0 deletions deps/v8/include/v8-wasm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef INCLUDE_V8_WASM_H_
#define INCLUDE_V8_WASM_H_

#include <cassert>
#include <cstdint>
#include <cstddef>
#include "v8.h"

namespace v8 {
namespace wasm {

#define PAGE_SIZE 0x10000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggstion: use a different name for this macro, or better, make this a const static field of Memory. This avoids potential confusion with the PAGE_SIZE of host memory pages. (it is possible that you're following this pattern from elsewhere in V8 source code, in which case, you can ignore this suggestion)


class V8_EXPORT Memory {
private:
size_t pages_;
uint8_t* data_;
public:
Memory(size_t pages, uint8_t* data);
Memory(const Memory& memory);
size_t size();
size_t pages();
uint8_t* data();
};

class V8_EXPORT Table {
private:
void* tableObject_;
public:
Table(void* tableObject);
Table(const Table& table);
~Table();
MaybeLocal<Function> get(int index) const;
};

class V8_EXPORT Context {
public:
Context(Memory* memory, Table* table);
Context(Memory* memory, Table* table, v8::Isolate* isolate);
Context(const Context& context);
~Context();
Memory* memory;
Table* table;
v8::Isolate* isolate;
};

enum V8_EXPORT ValKind : uint8_t {
I32,
I64,
F32,
F64,
ANYREF = 128,
FUNCREF
};

// TODO(ohadrau): Should we enforce Ref ownership like the C API?
class V8_EXPORT Val {
private:
ValKind kind_;
union value {
int32_t i32;
int64_t i64;
float f32;
double f64;
void* ref;
} value_;

Val(ValKind kind, value value);

public:
Val();
Val(Val&& val);
explicit Val(int32_t i);
explicit Val(int64_t i);
explicit Val(float i);
explicit Val(double i);
explicit Val(void* r);

Val& operator=(Val&&);

ValKind kind() const;
int32_t i32() const;
int64_t i64() const;
float f32() const;
double f64() const;
void* ref() const;
};

class V8_EXPORT FuncType {
private:
std::vector<ValKind> params_, results_;
public:
FuncType(std::vector<ValKind> params, std::vector<ValKind> results);

std::vector<ValKind> params() const;
std::vector<ValKind> results() const;
};

class V8_EXPORT Func {
public:
using callbackType = void (*)(const Context*, const Val[], Val[]);
Func(const FuncType, callbackType);

const FuncType type();
callbackType callback();
private:
const FuncType type_;
callbackType callback_;
};

void RegisterEmbedderBuiltin(Isolate* isolate,
const char* module_name,
const char* name,
Func import);

} // namespace wasm
} // namespace v8

#endif // INCLUDE_V8_WASM_H_
Loading