Commit dea2de5c authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[cleanup][wasm-c-api] Drop custom binary reader/writer

The code to create wrapper modules on the fly was dead already.
The code to read wire bytes has been replaced with accesses to
V8's internal decoded form of the same data.

Change-Id: I736c8467df3ded9de08f2d567dbfd5e695dcfb0e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1698384
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62691}
parent c7966ad5
......@@ -37,576 +37,56 @@
#include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-serialization.h"
// BEGIN FILE wasm-bin.cc
namespace wasm {
namespace bin {
////////////////////////////////////////////////////////////////////////////////
// Encoding
void encode_header(char*& ptr) { // NOLINT(runtime/references)
std::memcpy(ptr,
"\x00"
"asm\x01\x00\x00\x00",
8);
ptr += 8;
}
void encode_size32(char*& ptr, // NOLINT(runtime/references)
size_t n) {
assert(n <= 0xffffffff);
for (int i = 0; i < 5; ++i) {
*ptr++ = (n & 0x7f) | (i == 4 ? 0x00 : 0x80);
n = n >> 7;
}
}
void encode_valtype(char*& ptr, // NOLINT(runtime/references)
const ValType* type) {
switch (type->kind()) {
case I32:
*ptr++ = 0x7f;
break;
case I64:
*ptr++ = 0x7e;
break;
case F32:
*ptr++ = 0x7d;
break;
case F64:
*ptr++ = 0x7c;
break;
case FUNCREF:
*ptr++ = 0x70;
break;
case ANYREF:
*ptr++ = 0x6f;
break;
default:
UNREACHABLE();
}
}
auto zero_size(const ValType* type) -> size_t {
switch (type->kind()) {
case I32:
return 1;
case I64:
return 1;
case F32:
return 4;
case F64:
return 8;
case FUNCREF:
return 0;
case ANYREF:
return 0;
default:
UNREACHABLE();
}
}
void encode_const_zero(char*& ptr, // NOLINT(runtime/references)
const ValType* type) {
switch (type->kind()) {
case I32:
*ptr++ = 0x41;
break;
case I64:
*ptr++ = 0x42;
break;
case F32:
*ptr++ = 0x43;
break;
case F64:
*ptr++ = 0x44;
break;
default:
UNREACHABLE();
}
for (size_t i = 0; i < zero_size(type); ++i) *ptr++ = 0;
}
auto wrapper(const FuncType* type) -> vec<byte_t> {
auto in_arity = type->params().size();
auto out_arity = type->results().size();
auto size = 39 + in_arity + out_arity;
auto binary = vec<byte_t>::make_uninitialized(size);
auto ptr = binary.get();
encode_header(ptr);
*ptr++ = i::wasm::kTypeSectionCode;
encode_size32(ptr, 12 + in_arity + out_arity); // size
*ptr++ = 1; // length
*ptr++ = i::wasm::kWasmFunctionTypeCode;
encode_size32(ptr, in_arity);
for (size_t i = 0; i < in_arity; ++i) {
encode_valtype(ptr, type->params()[i].get());
}
encode_size32(ptr, out_arity);
for (size_t i = 0; i < out_arity; ++i) {
encode_valtype(ptr, type->results()[i].get());
}
*ptr++ = i::wasm::kImportSectionCode;
*ptr++ = 5; // size
*ptr++ = 1; // length
*ptr++ = 0; // module length
*ptr++ = 0; // name length
*ptr++ = i::wasm::kExternalFunction;
*ptr++ = 0; // type index
*ptr++ = i::wasm::kExportSectionCode;
*ptr++ = 4; // size
*ptr++ = 1; // length
*ptr++ = 0; // name length
*ptr++ = i::wasm::kExternalFunction;
*ptr++ = 0; // func index
assert(ptr - binary.get() == static_cast<ptrdiff_t>(size));
return binary;
}
////////////////////////////////////////////////////////////////////////////////
// Decoding
// Numbers
auto u32(const byte_t*& pos) -> uint32_t { // NOLINT(runtime/references)
uint32_t n = 0;
uint32_t shift = 0;
byte_t b;
do {
b = *pos++;
n += (b & 0x7f) << shift;
shift += 7;
} while ((b & 0x80) != 0);
return n;
}
namespace {
auto u64(const byte_t*& pos) -> uint64_t { // NOLINT(runtime/references)
auto ReadLebU64(const byte_t** pos) -> uint64_t {
uint64_t n = 0;
uint64_t shift = 0;
byte_t b;
do {
b = *pos++;
b = **pos;
(*pos)++;
n += (b & 0x7f) << shift;
shift += 7;
} while ((b & 0x80) != 0);
return n;
}
void u32_skip(const byte_t*& pos) { // NOLINT(runtime/references)
bin::u32(pos);
}
// Names
auto name(const byte_t*& pos) -> Name { // NOLINT(runtime/references)
auto size = bin::u32(pos);
auto start = pos;
auto name = Name::make_uninitialized(size);
std::memcpy(name.get(), start, size);
pos += size;
return name;
}
// Types
auto valtype(const byte_t*& pos) // NOLINT(runtime/references)
-> own<wasm::ValType*> {
switch (*pos++) {
case i::wasm::kLocalI32:
return ValType::make(I32);
case i::wasm::kLocalI64:
return ValType::make(I64);
case i::wasm::kLocalF32:
return ValType::make(F32);
case i::wasm::kLocalF64:
return ValType::make(F64);
case i::wasm::kLocalFuncRef:
return ValType::make(FUNCREF);
case i::wasm::kLocalAnyRef:
return ValType::make(ANYREF);
default:
// TODO(wasm+): support new value types
UNREACHABLE();
}
return {};
}
auto mutability(const byte_t*& pos) // NOLINT(runtime/references)
-> Mutability {
return *pos++ ? VAR : CONST;
}
auto limits(const byte_t*& pos) -> Limits { // NOLINT(runtime/references)
auto tag = *pos++;
auto min = bin::u32(pos);
if ((tag & 0x01) == 0) {
return Limits(min);
} else {
auto max = bin::u32(pos);
return Limits(min, max);
}
}
auto stacktype(const byte_t*& pos) // NOLINT(runtime/references)
-> vec<ValType*> {
size_t size = bin::u32(pos);
auto v = vec<ValType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; ++i) v[i] = bin::valtype(pos);
return v;
}
auto functype(const byte_t*& pos) // NOLINT(runtime/references)
-> own<FuncType*> {
assert(*pos == i::wasm::kWasmFunctionTypeCode);
++pos;
auto params = bin::stacktype(pos);
auto results = bin::stacktype(pos);
return FuncType::make(std::move(params), std::move(results));
}
auto globaltype(const byte_t*& pos) // NOLINT(runtime/references)
-> own<GlobalType*> {
auto content = bin::valtype(pos);
auto mutability = bin::mutability(pos);
return GlobalType::make(std::move(content), mutability);
}
auto tabletype(const byte_t*& pos) // NOLINT(runtime/references)
-> own<TableType*> {
auto elem = bin::valtype(pos);
auto limits = bin::limits(pos);
return TableType::make(std::move(elem), limits);
}
auto memorytype(const byte_t*& pos) // NOLINT(runtime/references)
-> own<MemoryType*> {
auto limits = bin::limits(pos);
return MemoryType::make(limits);
}
// Expressions
void expr_skip(const byte_t*& pos) { // NOLINT(runtime/references)
switch (*pos++) {
case i::wasm::kExprI32Const:
case i::wasm::kExprI64Const:
case i::wasm::kExprGetGlobal: {
bin::u32_skip(pos);
} break;
case i::wasm::kExprF32Const: {
pos += 4;
} break;
case i::wasm::kExprF64Const: {
pos += 8;
} break;
default: {
// TODO(wasm+): support new expression forms
UNREACHABLE();
}
}
++pos; // end
}
// Sections
auto section(const vec<const byte_t>& binary, i::wasm::SectionCode sec)
-> const byte_t* {
const byte_t* end = binary.get() + binary.size();
const byte_t* pos = binary.get() + 8; // skip header
while (pos < end && *pos++ != sec) {
auto size = bin::u32(pos);
pos += size;
}
if (pos == end) return nullptr;
bin::u32_skip(pos);
return pos;
}
// Only for asserts/DCHECKs.
auto section_end(const vec<const byte_t>& binary, i::wasm::SectionCode sec)
-> const byte_t* {
const byte_t* end = binary.get() + binary.size();
const byte_t* pos = binary.get() + 8; // skip header
while (pos < end && *pos != sec) {
++pos;
auto size = bin::u32(pos);
pos += size;
}
if (pos == end) return nullptr;
++pos;
auto size = bin::u32(pos);
return pos + size;
}
// Type section
auto types(const vec<const byte_t>& binary) -> vec<FuncType*> {
auto pos = bin::section(binary, i::wasm::kTypeSectionCode);
if (pos == nullptr) return vec<FuncType*>::make();
size_t size = bin::u32(pos);
// TODO(wasm+): support new deftypes
auto v = vec<FuncType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; ++i) {
v[i] = bin::functype(pos);
}
assert(pos == bin::section_end(binary, i::wasm::kTypeSectionCode));
return v;
}
// Import section
auto imports(const vec<const byte_t>& binary, const vec<FuncType*>& types)
-> vec<ImportType*> {
auto pos = bin::section(binary, i::wasm::kImportSectionCode);
if (pos == nullptr) return vec<ImportType*>::make();
size_t size = bin::u32(pos);
auto v = vec<ImportType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; ++i) {
auto module = bin::name(pos);
auto name = bin::name(pos);
own<ExternType*> type;
switch (*pos++) {
case i::wasm::kExternalFunction:
type = types[bin::u32(pos)]->copy();
break;
case i::wasm::kExternalTable:
type = bin::tabletype(pos);
break;
case i::wasm::kExternalMemory:
type = bin::memorytype(pos);
break;
case i::wasm::kExternalGlobal:
type = bin::globaltype(pos);
break;
default:
UNREACHABLE();
}
v[i] =
ImportType::make(std::move(module), std::move(name), std::move(type));
}
assert(pos == bin::section_end(binary, i::wasm::kImportSectionCode));
return v;
}
auto count(const vec<ImportType*>& imports, ExternKind kind) -> uint32_t {
uint32_t n = 0;
for (uint32_t i = 0; i < imports.size(); ++i) {
if (imports[i]->type()->kind() == kind) ++n;
}
return n;
}
// Function section
auto funcs(const vec<const byte_t>& binary, const vec<ImportType*>& imports,
const vec<FuncType*>& types) -> vec<FuncType*> {
auto pos = bin::section(binary, i::wasm::kFunctionSectionCode);
size_t size = pos != nullptr ? bin::u32(pos) : 0;
auto v =
vec<FuncType*>::make_uninitialized(size + count(imports, EXTERN_FUNC));
size_t j = 0;
for (uint32_t i = 0; i < imports.size(); ++i) {
auto et = imports[i]->type();
if (et->kind() == EXTERN_FUNC) {
v[j++] = et->func()->copy();
}
}
if (pos != nullptr) {
for (; j < v.size(); ++j) {
v[j] = types[bin::u32(pos)]->copy();
}
assert(pos == bin::section_end(binary, i::wasm::kFunctionSectionCode));
}
return v;
}
// Global section
auto globals(const vec<const byte_t>& binary, const vec<ImportType*>& imports)
-> vec<GlobalType*> {
auto pos = bin::section(binary, i::wasm::kGlobalSectionCode);
size_t size = pos != nullptr ? bin::u32(pos) : 0;
auto v = vec<GlobalType*>::make_uninitialized(size +
count(imports, EXTERN_GLOBAL));
size_t j = 0;
for (uint32_t i = 0; i < imports.size(); ++i) {
auto et = imports[i]->type();
if (et->kind() == EXTERN_GLOBAL) {
v[j++] = et->global()->copy();
}
}
if (pos != nullptr) {
for (; j < v.size(); ++j) {
v[j] = bin::globaltype(pos);
expr_skip(pos);
}
assert(pos == bin::section_end(binary, i::wasm::kGlobalSectionCode));
}
return v;
}
// Table section
auto tables(const vec<const byte_t>& binary, const vec<ImportType*>& imports)
-> vec<TableType*> {
auto pos = bin::section(binary, i::wasm::kTableSectionCode);
size_t size = pos != nullptr ? bin::u32(pos) : 0;
auto v =
vec<TableType*>::make_uninitialized(size + count(imports, EXTERN_TABLE));
size_t j = 0;
for (uint32_t i = 0; i < imports.size(); ++i) {
auto et = imports[i]->type();
if (et->kind() == EXTERN_TABLE) {
v[j++] = et->table()->copy();
}
}
if (pos != nullptr) {
for (; j < v.size(); ++j) {
v[j] = bin::tabletype(pos);
}
assert(pos == bin::section_end(binary, i::wasm::kTableSectionCode));
}
return v;
}
// Memory section
auto memories(const vec<const byte_t>& binary, const vec<ImportType*>& imports)
-> vec<MemoryType*> {
auto pos = bin::section(binary, i::wasm::kMemorySectionCode);
size_t size = pos != nullptr ? bin::u32(pos) : 0;
auto v = vec<MemoryType*>::make_uninitialized(size +
count(imports, EXTERN_MEMORY));
size_t j = 0;
for (uint32_t i = 0; i < imports.size(); ++i) {
auto et = imports[i]->type();
if (et->kind() == EXTERN_MEMORY) {
v[j++] = et->memory()->copy();
}
}
if (pos != nullptr) {
for (; j < v.size(); ++j) {
v[j] = bin::memorytype(pos);
}
assert(pos == bin::section_end(binary, i::wasm::kMemorySectionCode));
}
return v;
}
// Export section
auto exports(const vec<const byte_t>& binary, const vec<FuncType*>& funcs,
const vec<GlobalType*>& globals, const vec<TableType*>& tables,
const vec<MemoryType*>& memories) -> vec<ExportType*> {
auto pos = bin::section(binary, i::wasm::kExportSectionCode);
if (pos == nullptr) return vec<ExportType*>::make();
size_t size = bin::u32(pos);
auto exports = vec<ExportType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; ++i) {
auto name = bin::name(pos);
auto tag = *pos++;
auto index = bin::u32(pos);
own<ExternType*> type;
switch (tag) {
case i::wasm::kExternalFunction:
type = funcs[index]->copy();
break;
case i::wasm::kExternalTable:
type = tables[index]->copy();
break;
case i::wasm::kExternalMemory:
type = memories[index]->copy();
break;
case i::wasm::kExternalGlobal:
type = globals[index]->copy();
break;
default:
UNREACHABLE();
}
exports[i] = ExportType::make(std::move(name), std::move(type));
}
assert(pos == bin::section_end(binary, i::wasm::kExportSectionCode));
return exports;
}
auto imports(const vec<const byte_t>& binary) -> vec<ImportType*> {
return bin::imports(binary, bin::types(binary));
}
auto exports(const vec<const byte_t>& binary) -> vec<ExportType*> {
auto types = bin::types(binary);
auto imports = bin::imports(binary, types);
auto funcs = bin::funcs(binary, imports, types);
auto globals = bin::globals(binary, imports);
auto tables = bin::tables(binary, imports);
auto memories = bin::memories(binary, imports);
return bin::exports(binary, funcs, globals, tables, memories);
}
} // namespace bin
} // namespace wasm
// BEGIN FILE wasm-v8-lowlevel.cc
namespace v8 {
namespace wasm {
// Foreign pointers
auto foreign_new(v8::Isolate* isolate, void* ptr) -> v8::Local<v8::Value> {
auto foreign = v8::FromCData(reinterpret_cast<i::Isolate*>(isolate),
reinterpret_cast<i::Address>(ptr));
return v8::Utils::ToLocal(foreign);
}
auto foreign_get(v8::Local<v8::Value> val) -> void* {
auto foreign = v8::Utils::OpenHandle(*val);
if (!foreign->IsForeign()) return nullptr;
auto addr = v8::ToCData<i::Address>(*foreign);
return reinterpret_cast<void*>(addr);
}
// Types
auto v8_valtype_to_wasm(i::wasm::ValueType v8_valtype) -> ::wasm::ValKind {
ValKind V8ValueTypeToWasm(i::wasm::ValueType v8_valtype) {
switch (v8_valtype) {
case i::wasm::kWasmI32:
return ::wasm::I32;
return I32;
case i::wasm::kWasmI64:
return ::wasm::I64;
return I64;
case i::wasm::kWasmF32:
return ::wasm::F32;
return F32;
case i::wasm::kWasmF64:
return ::wasm::F64;
return F64;
case i::wasm::kWasmFuncRef:
return ::wasm::FUNCREF;
return FUNCREF;
case i::wasm::kWasmAnyRef:
return ::wasm::ANYREF;
return ANYREF;
default:
// TODO(wasm+): support new value types
UNREACHABLE();
}
}
i::wasm::ValueType wasm_valtype_to_v8(::wasm::ValKind type) {
switch (type) {
case ::wasm::I32:
i::wasm::ValueType WasmValKindToV8(ValKind kind) {
switch (kind) {
case I32:
return i::wasm::kWasmI32;
case ::wasm::I64:
case I64:
return i::wasm::kWasmI64;
case ::wasm::F32:
case F32:
return i::wasm::kWasmF32;
case ::wasm::F64:
case F64:
return i::wasm::kWasmF64;
case ::wasm::FUNCREF:
case FUNCREF:
return i::wasm::kWasmFuncRef;
case ::wasm::ANYREF:
case ANYREF:
return i::wasm::kWasmAnyRef;
default:
// TODO(wasm+): support new value types
......@@ -614,12 +94,64 @@ i::wasm::ValueType wasm_valtype_to_v8(::wasm::ValKind type) {
}
}
} // namespace wasm
} // namespace v8
Name GetNameFromWireBytes(const i::wasm::WireBytesRef& ref,
const i::Vector<const uint8_t>& wire_bytes) {
DCHECK_LE(ref.offset(), wire_bytes.length());
DCHECK_LE(ref.end_offset(), wire_bytes.length());
Name name = Name::make_uninitialized(ref.length());
std::memcpy(name.get(), wire_bytes.begin() + ref.offset(), ref.length());
return name;
}
/// BEGIN FILE wasm-v8.cc
own<FuncType*> FunctionSigToFuncType(const i::wasm::FunctionSig* sig) {
size_t param_count = sig->parameter_count();
vec<ValType*> params = vec<ValType*>::make_uninitialized(param_count);
for (size_t i = 0; i < param_count; i++) {
params[i] = ValType::make(V8ValueTypeToWasm(sig->GetParam(i)));
}
size_t return_count = sig->return_count();
vec<ValType*> results = vec<ValType*>::make_uninitialized(return_count);
for (size_t i = 0; i < return_count; i++) {
results[i] = ValType::make(V8ValueTypeToWasm(sig->GetReturn(i)));
}
return FuncType::make(std::move(params), std::move(results));
}
namespace wasm {
own<ExternType*> GetImportExportType(const i::wasm::WasmModule* module,
const i::wasm::ImportExportKindCode kind,
const uint32_t index) {
switch (kind) {
case i::wasm::kExternalFunction: {
return FunctionSigToFuncType(module->functions[index].sig);
}
case i::wasm::kExternalTable: {
const i::wasm::WasmTable& table = module->tables[index];
own<ValType*> elem = ValType::make(V8ValueTypeToWasm(table.type));
Limits limits(table.initial_size,
table.has_maximum_size ? table.maximum_size : -1);
return TableType::make(std::move(elem), limits);
}
case i::wasm::kExternalMemory: {
DCHECK(module->has_memory);
Limits limits(module->initial_pages,
module->has_maximum_pages ? module->maximum_pages : -1);
return MemoryType::make(limits);
}
case i::wasm::kExternalGlobal: {
const i::wasm::WasmGlobal& global = module->globals[index];
own<ValType*> content = ValType::make(V8ValueTypeToWasm(global.type));
Mutability mutability = global.mutability ? VAR : CONST;
return GlobalType::make(std::move(content), mutability);
}
case i::wasm::kExternalException:
UNREACHABLE();
return {};
}
}
} // namespace
/// BEGIN FILE wasm-v8.cc
///////////////////////////////////////////////////////////////////////////////
// Auxiliaries
......@@ -1334,22 +866,37 @@ auto Module::make(Store* store_abs, const vec<byte_t>& binary) -> own<Module*> {
}
auto Module::imports() const -> vec<ImportType*> {
i::Vector<const uint8_t> wire_bytes =
impl(this)->v8_object()->native_module()->wire_bytes();
vec<const byte_t> binary = vec<const byte_t>::adopt(
wire_bytes.size(), reinterpret_cast<const byte_t*>(wire_bytes.begin()));
auto imports = wasm::bin::imports(binary);
binary.release();
const i::wasm::NativeModule* native_module =
impl(this)->v8_object()->native_module();
const i::wasm::WasmModule* module = native_module->module();
const i::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
const std::vector<i::wasm::WasmImport>& import_table = module->import_table;
size_t size = import_table.size();
vec<ImportType*> imports = vec<ImportType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; i++) {
const i::wasm::WasmImport& imp = import_table[i];
Name module_name = GetNameFromWireBytes(imp.module_name, wire_bytes);
Name name = GetNameFromWireBytes(imp.field_name, wire_bytes);
own<ExternType*> type = GetImportExportType(module, imp.kind, imp.index);
imports[i] = ImportType::make(std::move(module_name), std::move(name),
std::move(type));
}
return imports;
}
vec<ExportType*> ExportsImpl(i::Handle<i::WasmModuleObject> module_obj) {
i::Vector<const uint8_t> wire_bytes =
module_obj->native_module()->wire_bytes();
vec<const byte_t> binary = vec<const byte_t>::adopt(
wire_bytes.size(), reinterpret_cast<const byte_t*>(wire_bytes.begin()));
auto exports = wasm::bin::exports(binary);
binary.release();
const i::wasm::NativeModule* native_module = module_obj->native_module();
const i::wasm::WasmModule* module = native_module->module();
const i::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
const std::vector<i::wasm::WasmExport>& export_table = module->export_table;
size_t size = export_table.size();
vec<ExportType*> exports = vec<ExportType*>::make_uninitialized(size);
for (uint32_t i = 0; i < size; i++) {
const i::wasm::WasmExport& exp = export_table[i];
Name name = GetNameFromWireBytes(exp.name, wire_bytes);
own<ExternType*> type = GetImportExportType(module, exp.kind, exp.index);
exports[i] = ExportType::make(std::move(name), std::move(type));
}
return exports;
}
......@@ -1385,7 +932,7 @@ auto Module::deserialize(Store* store_abs, const vec<byte_t>& serialized)
i::Isolate* isolate = store->i_isolate();
i::HandleScope handle_scope(isolate);
const byte_t* ptr = serialized.get();
uint64_t binary_size = wasm::bin::u64(ptr);
uint64_t binary_size = ReadLebU64(&ptr);
ptrdiff_t size_size = ptr - serialized.get();
size_t serial_size = serialized.size() - size_size - binary_size;
i::Handle<i::WasmModuleObject> module_obj;
......@@ -1552,16 +1099,14 @@ class SignatureHelper : public i::AllStatic {
int index = 0;
// TODO(jkummerow): Consider making vec<> range-based for-iterable.
for (size_t i = 0; i < type->results().size(); i++) {
sig->set(index++,
v8::wasm::wasm_valtype_to_v8(type->results()[i]->kind()));
sig->set(index++, WasmValKindToV8(type->results()[i]->kind()));
}
// {sig->set} needs to take the address of its second parameter,
// so we can't pass in the static const kMarker directly.
i::wasm::ValueType marker = kMarker;
sig->set(index++, marker);
for (size_t i = 0; i < type->params().size(); i++) {
sig->set(index++,
v8::wasm::wasm_valtype_to_v8(type->params()[i]->kind()));
sig->set(index++, WasmValKindToV8(type->params()[i]->kind()));
}
return sig;
}
......@@ -1574,11 +1119,11 @@ class SignatureHelper : public i::AllStatic {
int i = 0;
for (; i < result_arity; ++i) {
results[i] = ValType::make(v8::wasm::v8_valtype_to_wasm(sig.get(i)));
results[i] = ValType::make(V8ValueTypeToWasm(sig.get(i)));
}
i++; // Skip marker.
for (int p = 0; i < sig.length(); ++i, ++p) {
params[p] = ValType::make(v8::wasm::v8_valtype_to_wasm(sig.get(i)));
params[p] = ValType::make(V8ValueTypeToWasm(sig.get(i)));
}
return FuncType::make(std::move(params), std::move(results));
}
......@@ -1639,22 +1184,8 @@ auto Func::type() const -> own<FuncType*> {
DCHECK(i::WasmExportedFunction::IsWasmExportedFunction(*func));
i::Handle<i::WasmExportedFunction> function =
i::Handle<i::WasmExportedFunction>::cast(func);
i::wasm::FunctionSig* sig =
function->instance().module()->functions[function->function_index()].sig;
uint32_t param_arity = static_cast<uint32_t>(sig->parameter_count());
uint32_t result_arity = static_cast<uint32_t>(sig->return_count());
auto params = vec<ValType*>::make_uninitialized(param_arity);
auto results = vec<ValType*>::make_uninitialized(result_arity);
for (size_t i = 0; i < params.size(); ++i) {
auto kind = v8::wasm::v8_valtype_to_wasm(sig->GetParam(i));
params[i] = ValType::make(kind);
}
for (size_t i = 0; i < results.size(); ++i) {
auto kind = v8::wasm::v8_valtype_to_wasm(sig->GetReturn(i));
results[i] = ValType::make(kind);
}
return FuncType::make(std::move(params), std::move(results));
return FunctionSigToFuncType(
function->instance().module()->functions[function->function_index()].sig);
}
auto Func::param_arity() const -> size_t {
......@@ -1982,8 +1513,7 @@ auto Global::make(Store* store_abs, const GlobalType* type, const Val& val)
DCHECK_EQ(type->content()->kind(), val.kind());
i::wasm::ValueType i_type =
v8::wasm::wasm_valtype_to_v8(type->content()->kind());
i::wasm::ValueType i_type = WasmValKindToV8(type->content()->kind());
bool is_mutable = (type->mutability() == VAR);
const int32_t offset = 0;
i::Handle<i::WasmGlobalObject> obj =
......@@ -2000,7 +1530,7 @@ auto Global::make(Store* store_abs, const GlobalType* type, const Val& val)
auto Global::type() const -> own<GlobalType*> {
i::Handle<i::WasmGlobalObject> v8_global = impl(this)->v8_object();
ValKind kind = v8::wasm::v8_valtype_to_wasm(v8_global->type());
ValKind kind = V8ValueTypeToWasm(v8_global->type());
Mutability mutability = v8_global->is_mutable() ? VAR : CONST;
return GlobalType::make(ValType::make(kind), mutability);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment