Commit 3b1b544c authored by hablich's avatar hablich Committed by Commit bot

Revert of [wasm] Refactor import handling for 0xC. (patchset #10 id:180001 of...

Revert of [wasm] Refactor import handling for 0xC. (patchset #10 id:180001 of https://codereview.chromium.org/2390113003/ )

Reason for revert:
Failes a few GC stress tests.https://chromegw.corp.google.com/i/client.v8/builders/V8%20Linux%20-%20gc%20stress/builds/6253

Original issue's description:
> [wasm] Refactor import handling for 0xC.
>
> Imports and exports in 0xC can be much more than functions, including
> tables, memories, and globals. This CL refactors the underlying
> organization of imports and exports to support these new import types.
>
> BUG=
>
> Committed: https://crrev.com/599f8a83420346d9cba5ff97bd2a7520468207b6
> Cr-Commit-Position: refs/heads/master@{#40033}

TBR=mtrofin@chromium.org,ahaas@chromium.org,bradnelson@chromium.org,titzer@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=

Review-Url: https://codereview.chromium.org/2395133002
Cr-Commit-Position: refs/heads/master@{#40038}
parent eeaa2398
...@@ -3151,8 +3151,8 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module, ...@@ -3151,8 +3151,8 @@ Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module,
Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
wasm::FunctionSig* sig, uint32_t index, wasm::FunctionSig* sig, uint32_t index,
Handle<String> module_name, Handle<String> import_module,
MaybeHandle<String> import_name) { MaybeHandle<String> import_function) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Create the Graph // Create the Graph
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
...@@ -3215,14 +3215,14 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, ...@@ -3215,14 +3215,14 @@ Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) { if (isolate->logger()->is_logging_code_events() || isolate->is_profiling()) {
const char* function_name = nullptr; const char* function_name = nullptr;
int function_name_size = 0; int function_name_size = 0;
if (!import_name.is_null()) { if (!import_function.is_null()) {
Handle<String> handle = import_name.ToHandleChecked(); Handle<String> handle = import_function.ToHandleChecked();
function_name = handle->ToCString().get(); function_name = handle->ToCString().get();
function_name_size = handle->length(); function_name_size = handle->length();
} }
RecordFunctionCompilation( RecordFunctionCompilation(
CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index, CodeEventListener::FUNCTION_TAG, isolate, code, "wasm-to-js", index,
{module_name->ToCString().get(), module_name->length()}, {import_module->ToCString().get(), import_module->length()},
{function_name, function_name_size}); {function_name, function_name_size});
} }
......
...@@ -84,8 +84,8 @@ class WasmCompilationUnit final { ...@@ -84,8 +84,8 @@ class WasmCompilationUnit final {
// Wraps a JS function, producing a code object that can be called from WASM. // Wraps a JS function, producing a code object that can be called from WASM.
Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target, Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, Handle<JSReceiver> target,
wasm::FunctionSig* sig, uint32_t index, wasm::FunctionSig* sig, uint32_t index,
Handle<String> module_name, Handle<String> import_module,
MaybeHandle<String> import_name); MaybeHandle<String> import_function);
// Wraps a given wasm code object, producing a code object. // Wraps a given wasm code object, producing a code object.
Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module, Handle<Code> CompileJSToWasmWrapper(Isolate* isolate, wasm::ModuleEnv* module,
......
...@@ -318,7 +318,7 @@ class ModuleDecoder : public Decoder { ...@@ -318,7 +318,7 @@ class ModuleDecoder : public Decoder {
// ===== Imported global ========================================= // ===== Imported global =========================================
import->index = static_cast<uint32_t>(module->globals.size()); import->index = static_cast<uint32_t>(module->globals.size());
module->globals.push_back( module->globals.push_back(
{kAstStmt, false, WasmInitExpr(), 0, true, false}); {kAstStmt, false, NO_INIT, 0, true, false});
WasmGlobal* global = &module->globals.back(); WasmGlobal* global = &module->globals.back();
global->type = consume_value_type(); global->type = consume_value_type();
global->mutability = consume_u8("mutability") != 0; global->mutability = consume_u8("mutability") != 0;
...@@ -399,8 +399,7 @@ class ModuleDecoder : public Decoder { ...@@ -399,8 +399,7 @@ class ModuleDecoder : public Decoder {
TRACE("DecodeGlobal[%d] module+%d\n", i, TRACE("DecodeGlobal[%d] module+%d\n", i,
static_cast<int>(pc_ - start_)); static_cast<int>(pc_ - start_));
// Add an uninitialized global and pass a pointer to it. // Add an uninitialized global and pass a pointer to it.
module->globals.push_back( module->globals.push_back({kAstStmt, false, NO_INIT, 0, false, false});
{kAstStmt, false, WasmInitExpr(), 0, false, false});
WasmGlobal* global = &module->globals.back(); WasmGlobal* global = &module->globals.back();
DecodeGlobalInModule(module, i, global); DecodeGlobalInModule(module, i, global);
} }
...@@ -546,9 +545,9 @@ class ModuleDecoder : public Decoder { ...@@ -546,9 +545,9 @@ class ModuleDecoder : public Decoder {
TRACE("DecodeDataSegment[%d] module+%d\n", i, TRACE("DecodeDataSegment[%d] module+%d\n", i,
static_cast<int>(pc_ - start_)); static_cast<int>(pc_ - start_));
module->data_segments.push_back({ module->data_segments.push_back({
WasmInitExpr(), // dest_addr NO_INIT, // dest_addr
0, // source_offset 0, // source_offset
0 // source_size 0 // source_size
}); });
WasmDataSegment* segment = &module->data_segments.back(); WasmDataSegment* segment = &module->data_segments.back();
DecodeDataSegmentInModule(module, segment); DecodeDataSegmentInModule(module, segment);
...@@ -648,19 +647,13 @@ class ModuleDecoder : public Decoder { ...@@ -648,19 +647,13 @@ class ModuleDecoder : public Decoder {
const byte* pos = pc(); const byte* pos = pc();
global->init = consume_init_expr(module, kAstStmt); global->init = consume_init_expr(module, kAstStmt);
switch (global->init.kind) { switch (global->init.kind) {
case WasmInitExpr::kGlobalIndex: { case WasmInitExpr::kGlobalIndex:
uint32_t other_index = global->init.val.global_index; if (global->init.val.global_index >= index) {
if (other_index >= index) {
error("invalid global index in init expression"); error("invalid global index in init expression");
} else if (module->globals[other_index].type != global->type) { } else if (module->globals[index].type != global->type) {
error(pos, pos, error("type mismatch in global initialization");
"type mismatch in global initialization "
"(from global #%u), expected %s, got %s",
other_index, WasmOpcodes::TypeName(global->type),
WasmOpcodes::TypeName(module->globals[other_index].type));
} }
break; break;
}
default: default:
if (global->type != TypeOf(module, global->init)) { if (global->type != TypeOf(module, global->init)) {
error(pos, pos, error(pos, pos,
......
...@@ -255,9 +255,8 @@ void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) { ...@@ -255,9 +255,8 @@ void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) {
} }
uint32_t WasmModuleBuilder::AddGlobal(LocalType type, bool exported, uint32_t WasmModuleBuilder::AddGlobal(LocalType type, bool exported,
bool mutability, bool mutability) {
const WasmInitExpr& init) { globals_.push_back({type, exported, mutability});
globals_.push_back({type, exported, mutability, init});
return static_cast<uint32_t>(globals_.size() - 1); return static_cast<uint32_t>(globals_.size() - 1);
} }
...@@ -345,64 +344,29 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const { ...@@ -345,64 +344,29 @@ void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
for (auto global : globals_) { for (auto global : globals_) {
buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(global.type)); buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(global.type));
buffer.write_u8(global.mutability ? 1 : 0); buffer.write_u8(global.mutability ? 1 : 0);
switch (global.init.kind) { switch (global.type) {
case WasmInitExpr::kI32Const: { case kAstI32: {
DCHECK_EQ(kAstI32, global.type); static const byte code[] = {WASM_I32V_1(0)};
const byte code[] = {WASM_I32V_5(global.init.val.i32_const)};
buffer.write(code, sizeof(code)); buffer.write(code, sizeof(code));
break; break;
} }
case WasmInitExpr::kI64Const: { case kAstF32: {
DCHECK_EQ(kAstI64, global.type); static const byte code[] = {WASM_F32(0)};
const byte code[] = {WASM_I64V_10(global.init.val.i64_const)};
buffer.write(code, sizeof(code)); buffer.write(code, sizeof(code));
break; break;
} }
case WasmInitExpr::kF32Const: { case kAstI64: {
DCHECK_EQ(kAstF32, global.type); static const byte code[] = {WASM_I64V_1(0)};
const byte code[] = {WASM_F32(global.init.val.f32_const)};
buffer.write(code, sizeof(code)); buffer.write(code, sizeof(code));
break; break;
} }
case WasmInitExpr::kF64Const: { case kAstF64: {
DCHECK_EQ(kAstF64, global.type); static const byte code[] = {WASM_F64(0.0)};
const byte code[] = {WASM_F64(global.init.val.f64_const)};
buffer.write(code, sizeof(code)); buffer.write(code, sizeof(code));
break; break;
} }
case WasmInitExpr::kGlobalIndex: { default:
const byte code[] = {kExprGetGlobal, UNREACHABLE();
U32V_5(global.init.val.global_index)};
buffer.write(code, sizeof(code));
break;
}
default: {
// No initializer, emit a default value.
switch (global.type) {
case kAstI32: {
const byte code[] = {WASM_I32V_1(0)};
buffer.write(code, sizeof(code));
break;
}
case kAstI64: {
const byte code[] = {WASM_I64V_1(0)};
buffer.write(code, sizeof(code));
break;
}
case kAstF32: {
const byte code[] = {WASM_F32(0.0)};
buffer.write(code, sizeof(code));
break;
}
case kAstF64: {
const byte code[] = {WASM_F64(0.0)};
buffer.write(code, sizeof(code));
break;
}
default:
UNREACHABLE();
}
}
} }
buffer.write_u8(kExprEnd); buffer.write_u8(kExprEnd);
} }
......
...@@ -212,8 +212,7 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { ...@@ -212,8 +212,7 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
imports_[index].name_length = name_length; imports_[index].name_length = name_length;
} }
WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true, uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true);
const WasmInitExpr& init = WasmInitExpr());
void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
uint32_t AddSignature(FunctionSig* sig); uint32_t AddSignature(FunctionSig* sig);
void AddIndirectFunction(uint32_t index); void AddIndirectFunction(uint32_t index);
...@@ -242,7 +241,6 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { ...@@ -242,7 +241,6 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
LocalType type; LocalType type;
bool exported; bool exported;
bool mutability; bool mutability;
WasmInitExpr init;
}; };
struct WasmDataSegment { struct WasmDataSegment {
......
This diff is collapsed.
...@@ -86,16 +86,12 @@ struct WasmInitExpr { ...@@ -86,16 +86,12 @@ struct WasmInitExpr {
double f64_const; double f64_const;
uint32_t global_index; uint32_t global_index;
} val; } val;
};
WasmInitExpr() : kind(kNone) {} #define NO_INIT \
explicit WasmInitExpr(int32_t v) : kind(kI32Const) { val.i32_const = v; } { \
explicit WasmInitExpr(int64_t v) : kind(kI64Const) { val.i64_const = v; } WasmInitExpr::kNone, { 0u } \
explicit WasmInitExpr(float v) : kind(kF32Const) { val.f32_const = v; }
explicit WasmInitExpr(double v) : kind(kF64Const) { val.f64_const = v; }
WasmInitExpr(WasmInitKind kind, uint32_t global_index) : kind(kGlobalIndex) {
val.global_index = global_index;
} }
};
// Static representation of a WASM function. // Static representation of a WASM function.
struct WasmFunction { struct WasmFunction {
...@@ -388,9 +384,8 @@ class WasmCompiledModule : public FixedArray { ...@@ -388,9 +384,8 @@ class WasmCompiledModule : public FixedArray {
#define CORE_WCM_PROPERTY_TABLE(MACRO) \ #define CORE_WCM_PROPERTY_TABLE(MACRO) \
MACRO(OBJECT, FixedArray, code_table) \ MACRO(OBJECT, FixedArray, code_table) \
MACRO(OBJECT, FixedArray, imports) \ MACRO(OBJECT, FixedArray, import_data) \
MACRO(OBJECT, FixedArray, exports) \ MACRO(OBJECT, FixedArray, exports) \
MACRO(OBJECT, FixedArray, inits) \
MACRO(OBJECT, FixedArray, startup_function) \ MACRO(OBJECT, FixedArray, startup_function) \
MACRO(OBJECT, FixedArray, indirect_function_tables) \ MACRO(OBJECT, FixedArray, indirect_function_tables) \
MACRO(OBJECT, String, module_bytes) \ MACRO(OBJECT, String, module_bytes) \
...@@ -400,6 +395,7 @@ class WasmCompiledModule : public FixedArray { ...@@ -400,6 +395,7 @@ class WasmCompiledModule : public FixedArray {
MACRO(OBJECT, ByteArray, data_segments) \ MACRO(OBJECT, ByteArray, data_segments) \
MACRO(SMALL_NUMBER, uint32_t, globals_size) \ MACRO(SMALL_NUMBER, uint32_t, globals_size) \
MACRO(OBJECT, JSArrayBuffer, heap) \ MACRO(OBJECT, JSArrayBuffer, heap) \
MACRO(SMALL_NUMBER, bool, export_memory) \
MACRO(SMALL_NUMBER, ModuleOrigin, origin) \ MACRO(SMALL_NUMBER, ModuleOrigin, origin) \
MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \ MACRO(WEAK_LINK, WasmCompiledModule, next_instance) \
MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \ MACRO(WEAK_LINK, WasmCompiledModule, prev_instance) \
...@@ -428,6 +424,7 @@ class WasmCompiledModule : public FixedArray { ...@@ -428,6 +424,7 @@ class WasmCompiledModule : public FixedArray {
static Handle<WasmCompiledModule> New(Isolate* isolate, static Handle<WasmCompiledModule> New(Isolate* isolate,
uint32_t min_memory_pages, uint32_t min_memory_pages,
uint32_t globals_size, uint32_t globals_size,
bool export_memory,
ModuleOrigin origin); ModuleOrigin origin);
static Handle<WasmCompiledModule> Clone(Isolate* isolate, static Handle<WasmCompiledModule> Clone(Isolate* isolate,
...@@ -457,6 +454,9 @@ class WasmCompiledModule : public FixedArray { ...@@ -457,6 +454,9 @@ class WasmCompiledModule : public FixedArray {
void PrintInstancesChain(); void PrintInstancesChain();
private: private:
#if DEBUG
static uint32_t instance_id_counter_;
#endif
void Init(); void Init();
DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule); DISALLOW_IMPLICIT_CONSTRUCTORS(WasmCompiledModule);
......
...@@ -429,94 +429,3 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) { ...@@ -429,94 +429,3 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
CHECK(try_catch.HasCaught()); CHECK(try_catch.HasCaught());
isolate->clear_pending_exception(); isolate->clear_pending_exception();
} }
TEST(Run_WasmModule_Global_init) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator);
TestSignatures sigs;
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
uint32_t global1 =
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(777777));
uint32_t global2 =
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(222222));
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
byte code[] = {
WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
f1->EmitCode(code, sizeof(code));
ExportAsMain(f1);
TestModule(&zone, builder, 999999);
}
template <typename CType>
static void RunWasmModuleGlobalInitTest(LocalType type, CType expected) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator);
TestSignatures sigs;
LocalType types[] = {type};
FunctionSig sig(1, 0, types);
for (int padding = 0; padding < 5; padding++) {
// Test with a simple initializer
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
for (int i = 0; i < padding; i++) { // pad global before
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 20000));
}
uint32_t global =
builder->AddGlobal(type, false, false, WasmInitExpr(expected));
for (int i = 0; i < padding; i++) { // pad global after
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 30000));
}
WasmFunctionBuilder* f1 = builder->AddFunction(&sig);
byte code[] = {WASM_GET_GLOBAL(global)};
f1->EmitCode(code, sizeof(code));
ExportAsMain(f1);
TestModule(&zone, builder, expected);
}
for (int padding = 0; padding < 5; padding++) {
// Test with a global index
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
for (int i = 0; i < padding; i++) { // pad global before
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 40000));
}
uint32_t global1 =
builder->AddGlobal(type, false, false, WasmInitExpr(expected));
for (int i = 0; i < padding; i++) { // pad global middle
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 50000));
}
uint32_t global2 = builder->AddGlobal(
type, false, false, WasmInitExpr(WasmInitExpr::kGlobalIndex, global1));
for (int i = 0; i < padding; i++) { // pad global after
builder->AddGlobal(kAstI32, false, false, WasmInitExpr(i + 60000));
}
WasmFunctionBuilder* f1 = builder->AddFunction(&sig);
byte code[] = {WASM_GET_GLOBAL(global2)};
f1->EmitCode(code, sizeof(code));
ExportAsMain(f1);
TestModule(&zone, builder, expected);
}
}
TEST(Run_WasmModule_Global_i32) {
RunWasmModuleGlobalInitTest<int32_t>(kAstI32, -983489);
RunWasmModuleGlobalInitTest<int32_t>(kAstI32, 11223344);
}
TEST(Run_WasmModule_Global_f32) {
RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f);
RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f);
}
TEST(Run_WasmModule_Global_f64) {
RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9);
RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25);
}
...@@ -268,7 +268,7 @@ class TestingModule : public ModuleEnv { ...@@ -268,7 +268,7 @@ class TestingModule : public ModuleEnv {
byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type));
global_offset = (global_offset + size - 1) & ~(size - 1); // align global_offset = (global_offset + size - 1) & ~(size - 1); // align
module_.globals.push_back( module_.globals.push_back(
{type, true, WasmInitExpr(), global_offset, false, false}); {type, true, NO_INIT, global_offset, false, false});
global_offset += size; global_offset += size;
// limit number of globals. // limit number of globals.
CHECK_LT(global_offset, kMaxGlobalsSize); CHECK_LT(global_offset, kMaxGlobalsSize);
......
...@@ -14,8 +14,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -14,8 +14,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
builder.addImport("getValue", kSig_i_v); builder.addImport("getValue", kSig_i);
builder.addFunction("f", kSig_i_v) builder.addFunction("f", kSig_i)
.addBody([ .addBody([
kExprCallFunction, 0 kExprCallFunction, 0
]).exportFunc(); ]).exportFunc();
......
...@@ -12,7 +12,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -12,7 +12,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
var kSig_v_i = makeSig([kAstI32], []); var kSig_v_i = makeSig([kAstI32], []);
var signature = builder.addType(kSig_v_i); var signature = builder.addType(kSig_v_i);
builder.addImport("some_value", kSig_i_v); builder.addImport("some_value", kSig_i);
builder.addImport("writer", signature); builder.addImport("writer", signature);
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
...@@ -65,7 +65,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -65,7 +65,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function RelationBetweenModuleAndClone() { (function RelationBetweenModuleAndClone() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([kExprI8Const, 42]) .addBody([kExprI8Const, 42])
.exportFunc(); .exportFunc();
...@@ -81,7 +81,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -81,7 +81,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function SerializeAfterInstantiation() { (function SerializeAfterInstantiation() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([kExprI8Const, 42]) .addBody([kExprI8Const, 42])
.exportFunc(); .exportFunc();
......
...@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var kReturnValue = 88; var kReturnValue = 88;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([ .addBody([
kExprI8Const, kExprI8Const,
kReturnValue, kReturnValue,
...@@ -32,7 +32,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -32,7 +32,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([ .addBody([
kExprI8Const, kExprI8Const,
kReturnValue, kReturnValue,
...@@ -57,7 +57,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -57,7 +57,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([ .addBody([
kExprI8Const, kExprI8Const,
kReturnValue, kReturnValue,
......
...@@ -94,7 +94,7 @@ print("Native function"); ...@@ -94,7 +94,7 @@ print("Native function");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var sig_index = builder.addType(kSig_d_v); var sig_index = builder.addType(kSig_d);
builder.addImport("func", sig_index); builder.addImport("func", sig_index);
builder.addFunction("main", sig_index) builder.addFunction("main", sig_index)
.addBody([ .addBody([
......
...@@ -10,7 +10,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -10,7 +10,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function TestFunctionPrototype() { (function TestFunctionPrototype() {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("nine", kSig_i_v) builder.addFunction("nine", kSig_i)
.addBody([kExprI8Const, 9]) .addBody([kExprI8Const, 9])
.exportFunc(); .exportFunc();
......
// Copyright 2016 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.
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
function TestImported(type, val, expected) {
print("TestImported " + type + "(" + val +")" + " = " + expected);
var builder = new WasmModuleBuilder();
var sig = makeSig([], [type]);
var g = builder.addImportedGlobal("foo", undefined, type);
builder.addFunction("main", sig)
.addBody([kExprGetGlobal, g.index])
.exportAs("main");
builder.addGlobal(kAstI32); // pad
var instance = builder.instantiate({foo: val});
assertEquals(expected, instance.exports.main());
}
TestImported(kAstI32, 300.1, 300);
TestImported(kAstF32, 87234.87238, Math.fround(87234.87238));
TestImported(kAstF64, 77777.88888, 77777.88888);
TestImported(kAstF64, "89", 89);
function TestExported(type, val, expected) {
print("TestExported " + type + "(" + val +")" + " = " + expected);
var builder = new WasmModuleBuilder();
var sig = makeSig([type], []);
builder.addGlobal(kAstI32); // pad
var g = builder.addGlobal(type, false)
.exportAs("foo");
g.init = val;
builder.addGlobal(kAstI32); // pad
var instance = builder.instantiate();
assertEquals(expected, instance.exports.foo);
}
TestExported(kAstI32, 455.5, 455);
TestExported(kAstF32, -999.34343, Math.fround(-999.34343));
TestExported(kAstF64, 87347.66666, 87347.66666);
function TestImportedExported(type, val, expected) {
print("TestImportedExported " + type + "(" + val +")" + " = " + expected);
var builder = new WasmModuleBuilder();
var sig = makeSig([type], []);
var i = builder.addImportedGlobal("foo", undefined, type);
builder.addGlobal(kAstI32); // pad
var o = builder.addGlobal(type, false)
.exportAs("bar");
o.init_index = i;
builder.addGlobal(kAstI32); // pad
var instance = builder.instantiate({foo: val});
assertEquals(expected, instance.exports.bar);
}
TestImportedExported(kAstI32, 415.5, 415);
TestImportedExported(kAstF32, -979.34343, Math.fround(-979.34343));
TestImportedExported(kAstF64, 81347.66666, 81347.66666);
...@@ -266,9 +266,9 @@ testCallPrint(); ...@@ -266,9 +266,9 @@ testCallPrint();
function testCallImport2(foo, bar, expected) { function testCallImport2(foo, bar, expected) {
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addImport("foo", kSig_i_v); builder.addImport("foo", kSig_i);
builder.addImport("bar", kSig_i_v); builder.addImport("bar", kSig_i);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([ .addBody([
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
kExprCallFunction, 1, // -- kExprCallFunction, 1, // --
......
...@@ -12,7 +12,7 @@ let nogc = () => {}; ...@@ -12,7 +12,7 @@ let nogc = () => {};
function newModule() { function newModule() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true); builder.addMemory(1, 1, true);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0]) .addBody([kExprI32Const, 0, kExprI32LoadMem, 0, 0])
.exportFunc(); .exportFunc();
......
...@@ -12,7 +12,7 @@ let kReturnValue = 117; ...@@ -12,7 +12,7 @@ let kReturnValue = 117;
let buffer = (() => { let buffer = (() => {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true); builder.addMemory(1, 1, true);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i)
.addBody([kExprI8Const, kReturnValue]) .addBody([kExprI8Const, kReturnValue])
.exportFunc(); .exportFunc();
...@@ -119,7 +119,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); ...@@ -119,7 +119,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
var kSig_v_i = makeSig([kAstI32], []); var kSig_v_i = makeSig([kAstI32], []);
var signature = builder.addType(kSig_v_i); var signature = builder.addType(kSig_v_i);
builder.addImport("some_value", kSig_i_v); builder.addImport("some_value", kSig_i);
builder.addImport("writer", signature); builder.addImport("writer", signature);
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
...@@ -169,7 +169,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); ...@@ -169,7 +169,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
(function GlobalsArePrivateToTheInstance() { (function GlobalsArePrivateToTheInstance() {
print("GlobalsArePrivateToTheInstance..."); print("GlobalsArePrivateToTheInstance...");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addGlobal(kAstI32, true); builder.addGlobal(kAstI32);
builder.addFunction("read", kSig_i_v) builder.addFunction("read", kSig_i_v)
.addBody([ .addBody([
kExprGetGlobal, 0]) kExprGetGlobal, 0])
...@@ -196,7 +196,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88))); ...@@ -196,7 +196,7 @@ assertFalse(WebAssembly.validate(bytes(88, 88, 88, 88, 88, 88, 88, 88)));
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addMemory(1,1, true); builder.addMemory(1,1, true);
builder.addFunction("f", kSig_i_v) builder.addFunction("f", kSig_i)
.addBody([ .addBody([
kExprI32Const, 0, kExprI32Const, 0,
kExprI32LoadMem, 0, 0 kExprI32LoadMem, 0, 0
......
...@@ -38,7 +38,7 @@ function assertVerifies(sig, body) { ...@@ -38,7 +38,7 @@ function assertVerifies(sig, body) {
} }
assertVerifies(kSig_v_v, [kExprNop]); assertVerifies(kSig_v_v, [kExprNop]);
assertVerifies(kSig_i_v, [kExprI8Const, 0]); assertVerifies(kSig_i, [kExprI8Const, 0]);
// Arguments aren't allow to start functions. // Arguments aren't allow to start functions.
assertFails(kSig_i_i, [kExprGetLocal, 0]); assertFails(kSig_i_i, [kExprGetLocal, 0]);
......
...@@ -12,7 +12,7 @@ var debug = true; ...@@ -12,7 +12,7 @@ var debug = true;
(function BasicTest() { (function BasicTest() {
var module = new WasmModuleBuilder(); var module = new WasmModuleBuilder();
module.addMemory(1, 2, false); module.addMemory(1, 2, false);
module.addFunction("foo", kSig_i_v) module.addFunction("foo", kSig_i)
.addBody([kExprI8Const, 11]) .addBody([kExprI8Const, 11])
.exportAs("blarg"); .exportAs("blarg");
...@@ -116,7 +116,7 @@ var debug = true; ...@@ -116,7 +116,7 @@ var debug = true;
(function BasicTestWithUint8Array() { (function BasicTestWithUint8Array() {
var module = new WasmModuleBuilder(); var module = new WasmModuleBuilder();
module.addMemory(1, 2, false); module.addMemory(1, 2, false);
module.addFunction("foo", kSig_i_v) module.addFunction("foo", kSig_i)
.addBody([kExprI8Const, 17]) .addBody([kExprI8Const, 17])
.exportAs("blarg"); .exportAs("blarg");
......
...@@ -89,6 +89,8 @@ var kExternalMemory = 2; ...@@ -89,6 +89,8 @@ var kExternalMemory = 2;
var kExternalGlobal = 3; var kExternalGlobal = 3;
// Useful signatures // Useful signatures
var kSig_i = makeSig([], [kAstI32]);
var kSig_d = makeSig([], [kAstF64]);
var kSig_i_i = makeSig([kAstI32], [kAstI32]); var kSig_i_i = makeSig([kAstI32], [kAstI32]);
var kSig_i_l = makeSig([kAstI64], [kAstI32]); var kSig_i_l = makeSig([kAstI64], [kAstI32]);
var kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]); var kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]);
...@@ -98,8 +100,6 @@ var kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]); ...@@ -98,8 +100,6 @@ var kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]);
var kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]); var kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]);
var kSig_v_v = makeSig([], []); var kSig_v_v = makeSig([], []);
var kSig_i_v = makeSig([], [kAstI32]); var kSig_i_v = makeSig([], [kAstI32]);
var kSig_f_v = makeSig([], [kAstF64]);
var kSig_d_v = makeSig([], [kAstF64]);
var kSig_v_i = makeSig([kAstI32], []); var kSig_v_i = makeSig([kAstI32], []);
var kSig_v_ii = makeSig([kAstI32, kAstI32], []); var kSig_v_ii = makeSig([kAstI32, kAstI32], []);
var kSig_v_iii = makeSig([kAstI32, kAstI32, kAstI32], []); var kSig_v_iii = makeSig([kAstI32, kAstI32, kAstI32], []);
......
This diff is collapsed.
...@@ -1283,7 +1283,7 @@ class TestModuleEnv : public ModuleEnv { ...@@ -1283,7 +1283,7 @@ class TestModuleEnv : public ModuleEnv {
module = &mod; module = &mod;
} }
byte AddGlobal(LocalType type, bool mutability = true) { byte AddGlobal(LocalType type, bool mutability = true) {
mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); mod.globals.push_back({type, mutability, NO_INIT, 0, false, false});
CHECK(mod.globals.size() <= 127); CHECK(mod.globals.size() <= 127);
return static_cast<byte>(mod.globals.size() - 1); return static_cast<byte>(mod.globals.size() - 1);
} }
......
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