Commit 1d32a398 authored by littledan's avatar littledan Committed by Commit bot

Revert of [wasm] Enforce that function bodies end with the \"end\" opcode....

Revert of [wasm] Enforce that function bodies end with the \"end\" opcode. (patchset #3 id:40001 of https://codereview.chromium.org/2630553002/ )

Reason for revert:
Caused tree to close by failing compilation:

https://build.chromium.org/p/client.v8/builders/V8%20Win64%20-%20clang/builds/4451

Original issue's description:
> [wasm] Enforce that function bodies end with the \"end\" opcode.
>
> R=rossberg@chromium.org
> BUG=chromium:575167
>
> Review-Url: https://codereview.chromium.org/2630553002
> Cr-Commit-Position: refs/heads/master@{#42286}
> Committed: https://chromium.googlesource.com/v8/v8/+/fcc6e85ec6b01e5367795f98aff104b1ff23f619

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

Review-Url: https://codereview.chromium.org/2628883006
Cr-Commit-Position: refs/heads/master@{#42287}
parent fcc6e85e
...@@ -101,7 +101,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -101,7 +101,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
uint32_t index = LookupOrInsertGlobal(fv->var, fv->type); uint32_t index = LookupOrInsertGlobal(fv->var, fv->type);
foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index); foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index);
} }
foreign_init_function_->Emit(kExprEnd);
} }
Handle<FixedArray> GetForeignArgs() { Handle<FixedArray> GetForeignArgs() {
...@@ -132,7 +131,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -132,7 +131,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
return false; return false;
} }
BuildForeignInitFunction(); BuildForeignInitFunction();
init_function_->Emit(kExprEnd); // finish init function.
return true; return true;
} }
...@@ -545,10 +543,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -545,10 +543,6 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
RECURSE(VisitDeclarations(scope->declarations())); RECURSE(VisitDeclarations(scope->declarations()));
if (typer_failed_) return; if (typer_failed_) return;
RECURSE(VisitStatements(expr->body())); RECURSE(VisitStatements(expr->body()));
if (scope_ == kFuncScope) {
// Finish the function-body scope block.
current_function_builder_->Emit(kExprEnd);
}
} }
void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) { void VisitNativeFunctionLiteral(NativeFunctionLiteral* expr) {
......
...@@ -39,6 +39,8 @@ namespace wasm { ...@@ -39,6 +39,8 @@ namespace wasm {
error("Invalid opcode (enable with --" #flag ")"); \ error("Invalid opcode (enable with --" #flag ")"); \
break; \ break; \
} }
// TODO(titzer): this is only for intermediate migration.
#define IMPLICIT_FUNCTION_END 1
// An SsaEnv environment carries the current local variable renaming // An SsaEnv environment carries the current local variable renaming
// as well as the current effect and control dependency in the TF graph. // as well as the current effect and control dependency in the TF graph.
...@@ -491,14 +493,41 @@ class WasmFullDecoder : public WasmDecoder { ...@@ -491,14 +493,41 @@ class WasmFullDecoder : public WasmDecoder {
if (failed()) return TraceFailed(); if (failed()) return TraceFailed();
if (!control_.empty()) { #if IMPLICIT_FUNCTION_END
// Generate a better error message whether the unterminated control // With implicit end support (old style), the function block
// structure is the function body block or an innner structure. // remains on the stack. Other control blocks are an error.
if (control_.size() > 1) { if (control_.size() > 1) {
error(pc_, control_.back().pc, "unterminated control structure"); error(pc_, control_.back().pc, "unterminated control structure");
} else { return TraceFailed();
error("function body must end with \"end\" opcode."); }
// Assume an implicit end to the function body block.
if (control_.size() == 1) {
Control* c = &control_.back();
if (ssa_env_->go()) {
FallThruTo(c);
}
if (c->end_env->go()) {
// Push the end values onto the stack.
stack_.resize(c->stack_depth);
if (c->merge.arity == 1) {
stack_.push_back(c->merge.vals.first);
} else {
for (unsigned i = 0; i < c->merge.arity; i++) {
stack_.push_back(c->merge.vals.array[i]);
}
}
TRACE(" @%-8d #xx:%-20s|", startrel(pc_), "ImplicitReturn");
SetEnv("function:end", c->end_env);
DoReturn();
TRACE("\n");
} }
}
#else
if (!control_.empty()) {
error(pc_, control_.back().pc, "unterminated control structure");
return TraceFailed(); return TraceFailed();
} }
...@@ -506,6 +535,7 @@ class WasmFullDecoder : public WasmDecoder { ...@@ -506,6 +535,7 @@ class WasmFullDecoder : public WasmDecoder {
error("function body must end with \"end\" opcode."); error("function body must end with \"end\" opcode.");
return false; return false;
} }
#endif
if (FLAG_trace_wasm_decode_time) { if (FLAG_trace_wasm_decode_time) {
double ms = decode_timer.Elapsed().InMillisecondsF(); double ms = decode_timer.Elapsed().InMillisecondsF();
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
// Control. // Control.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#define WASM_NOP kExprNop #define WASM_NOP kExprNop
#define WASM_END kExprEnd
#define ARITY_0 0 #define ARITY_0 0
#define ARITY_1 1 #define ARITY_1 1
......
...@@ -141,7 +141,7 @@ void wasm::PrintWasmText(const WasmModule *module, ...@@ -141,7 +141,7 @@ void wasm::PrintWasmText(const WasmModule *module,
AccountingAllocator allocator; AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME); Zone zone(&allocator, ZONE_NAME);
int line_nr = 0; int line_nr = 0;
int control_depth = 1; int control_depth = 0;
// Print the function signature. // Print the function signature.
os << "func"; os << "func";
......
...@@ -219,7 +219,7 @@ TEST(Breakpoint_I32Add) { ...@@ -219,7 +219,7 @@ TEST(Breakpoint_I32Add) {
} }
TEST(Step_I32Mul) { TEST(Step_I32Mul) {
static const int kTraceLength = 5; static const int kTraceLength = 4;
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted); WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
......
...@@ -63,12 +63,6 @@ void TestModuleException(Zone* zone, WasmModuleBuilder* builder) { ...@@ -63,12 +63,6 @@ void TestModuleException(Zone* zone, WasmModuleBuilder* builder) {
void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); } void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); }
#define EMIT_CODE_WITH_END(f, code) \
do { \
f->EmitCode(code, sizeof(code)); \
f->Emit(kExprEnd); \
} while (false)
} // namespace } // namespace
TEST(Run_WasmModule_Return114) { TEST(Run_WasmModule_Return114) {
...@@ -82,7 +76,7 @@ TEST(Run_WasmModule_Return114) { ...@@ -82,7 +76,7 @@ TEST(Run_WasmModule_Return114) {
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I32V_2(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kReturnValue); TestModule(&zone, builder, kReturnValue);
} }
Cleanup(); Cleanup();
...@@ -101,14 +95,14 @@ TEST(Run_WasmModule_CallAdd) { ...@@ -101,14 +95,14 @@ TEST(Run_WasmModule_CallAdd) {
uint16_t param2 = 1; uint16_t param2 = 1;
byte code1[] = { byte code1[] = {
WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))};
EMIT_CODE_WITH_END(f1, code1); f1->EmitCode(code1, sizeof(code1));
WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v());
ExportAsMain(f2); ExportAsMain(f2);
byte code2[] = { byte code2[] = {
WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))}; WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))};
EMIT_CODE_WITH_END(f2, code2); f2->EmitCode(code2, sizeof(code2));
TestModule(&zone, builder, 99); TestModule(&zone, builder, 99);
} }
Cleanup(); Cleanup();
...@@ -127,7 +121,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) { ...@@ -127,7 +121,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) {
ExportAsMain(f); ExportAsMain(f);
byte code[] = { byte code[] = {
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))}; WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0);
TestModule(&zone, builder, 0xddccbbaa); TestModule(&zone, builder, 0xddccbbaa);
...@@ -155,7 +149,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { ...@@ -155,7 +149,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) {
WASM_BRV(3, WASM_I32V_1(-1)), WASM_BRV(3, WASM_I32V_1(-1)),
WASM_INC_LOCAL_BY(localIndex, 4))), WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I32V_1(11))}; WASM_I32V_1(11))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 11); TestModule(&zone, builder, 11);
} }
Cleanup(); Cleanup();
...@@ -180,7 +174,7 @@ TEST(Run_WasmModule_CallMain_recursive) { ...@@ -180,7 +174,7 @@ TEST(Run_WasmModule_CallMain_recursive) {
WASM_INC_LOCAL(localIndex)), WASM_INC_LOCAL(localIndex)),
WASM_CALL_FUNCTION0(0)), WASM_CALL_FUNCTION0(0)),
WASM_I32V_1(55))}; WASM_I32V_1(55))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 55); TestModule(&zone, builder, 55);
} }
Cleanup(); Cleanup();
...@@ -198,13 +192,13 @@ TEST(Run_WasmModule_Global) { ...@@ -198,13 +192,13 @@ TEST(Run_WasmModule_Global) {
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
byte code1[] = { byte code1[] = {
WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
EMIT_CODE_WITH_END(f1, code1); f1->EmitCode(code1, sizeof(code1));
WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v());
ExportAsMain(f2); ExportAsMain(f2);
byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)),
WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), WASM_SET_GLOBAL(global2, WASM_I32V_1(41)),
WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))};
EMIT_CODE_WITH_END(f2, code2); f2->EmitCode(code2, sizeof(code2));
TestModule(&zone, builder, 97); TestModule(&zone, builder, 97);
} }
Cleanup(); Cleanup();
...@@ -299,7 +293,7 @@ class WasmSerializationTest { ...@@ -299,7 +293,7 @@ class WasmSerializationTest {
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
f->ExportAs(CStrVector(kFunctionName)); f->ExportAs(CStrVector(kFunctionName));
ZoneBuffer buffer(&zone_); ZoneBuffer buffer(&zone_);
...@@ -431,7 +425,7 @@ TEST(MemorySize) { ...@@ -431,7 +425,7 @@ TEST(MemorySize) {
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_MEMORY_SIZE}; byte code[] = {WASM_MEMORY_SIZE};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kExpectedValue); TestModule(&zone, builder, kExpectedValue);
} }
Cleanup(); Cleanup();
...@@ -450,7 +444,7 @@ TEST(Run_WasmModule_MemSize_GrowMem) { ...@@ -450,7 +444,7 @@ TEST(Run_WasmModule_MemSize_GrowMem) {
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP,
WASM_MEMORY_SIZE}; WASM_MEMORY_SIZE};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kExpectedValue); TestModule(&zone, builder, kExpectedValue);
} }
Cleanup(); Cleanup();
...@@ -468,7 +462,7 @@ TEST(GrowMemoryZero) { ...@@ -468,7 +462,7 @@ TEST(GrowMemoryZero) {
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kExpectedValue); TestModule(&zone, builder, kExpectedValue);
} }
Cleanup(); Cleanup();
...@@ -539,7 +533,7 @@ TEST(TestInterruptLoop) { ...@@ -539,7 +533,7 @@ TEST(TestInterruptLoop) {
WASM_I32V(InterruptThread::signal_value_)), WASM_I32V(InterruptThread::signal_value_)),
WASM_BR(1))), WASM_BR(1))),
WASM_I32V(121)}; WASM_I32V(121)};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
ZoneBuffer buffer(&zone); ZoneBuffer buffer(&zone);
builder->WriteTo(buffer); builder->WriteTo(buffer);
...@@ -578,7 +572,7 @@ TEST(Run_WasmModule_GrowMemoryInIf) { ...@@ -578,7 +572,7 @@ TEST(Run_WasmModule_GrowMemoryInIf) {
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)),
WASM_I32V(12))}; WASM_I32V(12))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 12); TestModule(&zone, builder, 12);
} }
Cleanup(); Cleanup();
...@@ -600,7 +594,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) { ...@@ -600,7 +594,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) {
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)),
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value))}; WASM_I32V(value))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
TestModuleException(&zone, builder); TestModuleException(&zone, builder);
} }
Cleanup(); Cleanup();
...@@ -623,7 +617,7 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) { ...@@ -623,7 +617,7 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) {
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value)), WASM_I32V(value)),
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
HandleScope scope(isolate); HandleScope scope(isolate);
ZoneBuffer buffer(&zone); ZoneBuffer buffer(&zone);
...@@ -671,7 +665,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) { ...@@ -671,7 +665,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0),
WASM_I32V(value)), WASM_I32V(value)),
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))};
EMIT_CODE_WITH_END(f, code); f->EmitCode(code, sizeof(code));
HandleScope scope(isolate); HandleScope scope(isolate);
ZoneBuffer buffer(&zone); ZoneBuffer buffer(&zone);
...@@ -730,7 +724,7 @@ TEST(Run_WasmModule_Global_init) { ...@@ -730,7 +724,7 @@ TEST(Run_WasmModule_Global_init) {
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v());
byte code[] = { byte code[] = {
WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))};
EMIT_CODE_WITH_END(f1, code); f1->EmitCode(code, sizeof(code));
ExportAsMain(f1); ExportAsMain(f1);
TestModule(&zone, builder, 999999); TestModule(&zone, builder, 999999);
} }
...@@ -762,7 +756,7 @@ static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) { ...@@ -762,7 +756,7 @@ static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) {
WasmFunctionBuilder* f1 = builder->AddFunction(&sig); WasmFunctionBuilder* f1 = builder->AddFunction(&sig);
byte code[] = {WASM_GET_GLOBAL(global)}; byte code[] = {WASM_GET_GLOBAL(global)};
EMIT_CODE_WITH_END(f1, code); f1->EmitCode(code, sizeof(code));
ExportAsMain(f1); ExportAsMain(f1);
TestModule(&zone, builder, expected); TestModule(&zone, builder, expected);
} }
......
...@@ -1851,19 +1851,13 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { ...@@ -1851,19 +1851,13 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
FunctionSig* sig = WasmOpcodes::Signature(opcode); FunctionSig* sig = WasmOpcodes::Signature(opcode);
if (sig->parameter_count() == 1) { if (sig->parameter_count() == 1) {
byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode), byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode)};
WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code)); code + arraysize(code));
} else { } else {
CHECK_EQ(2, sig->parameter_count()); CHECK_EQ(2, sig->parameter_count());
byte code[] = {WASM_NO_LOCALS, byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, kExprGetLocal, 1,
kExprGetLocal, static_cast<byte>(opcode)};
0,
kExprGetLocal,
1,
static_cast<byte>(opcode),
WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code)); code + arraysize(code));
} }
......
...@@ -60,11 +60,11 @@ TEST(CollectPossibleBreakpoints) { ...@@ -60,11 +60,11 @@ TEST(CollectPossibleBreakpoints) {
Handle<WasmInstanceObject> instance = runner.module().instance_object(); Handle<WasmInstanceObject> instance = runner.module().instance_object();
std::vector<debug::Location> locations; std::vector<debug::Location> locations;
CheckLocations(instance->compiled_module(), {0, 0}, {1, 0}, CheckLocations(instance->compiled_module(), {0, 0}, {1, 0},
{{0, 1}, {0, 2}, {0, 4}, {0, 6}, {0, 7}}); {{0, 1}, {0, 2}, {0, 4}, {0, 6}});
CheckLocations(instance->compiled_module(), {0, 2}, {0, 4}, {{0, 2}}); CheckLocations(instance->compiled_module(), {0, 2}, {0, 4}, {{0, 2}});
CheckLocations(instance->compiled_module(), {0, 2}, {0, 5}, {{0, 2}, {0, 4}}); CheckLocations(instance->compiled_module(), {0, 2}, {0, 5}, {{0, 2}, {0, 4}});
CheckLocations(instance->compiled_module(), {0, 7}, {0, 8}, {{0, 7}}); CheckLocations(instance->compiled_module(), {0, 6}, {0, 7}, {{0, 6}});
CheckLocations(instance->compiled_module(), {0, 7}, {1, 0}, {{0, 7}}); CheckLocations(instance->compiled_module(), {0, 6}, {1, 0}, {{0, 6}});
CheckLocations(instance->compiled_module(), {0, 8}, {1, 0}, {}); CheckLocations(instance->compiled_module(), {0, 7}, {1, 0}, {});
CheckLocationsFail(instance->compiled_module(), {0, 9}, {1, 0}); CheckLocationsFail(instance->compiled_module(), {0, 8}, {1, 0});
} }
...@@ -509,18 +509,7 @@ class WasmFunctionCompiler : private GraphAndBuilders { ...@@ -509,18 +509,7 @@ class WasmFunctionCompiler : private GraphAndBuilders {
uint32_t function_index() { return function_->func_index; } uint32_t function_index() { return function_->func_index; }
void Build(const byte* start, const byte* end) { void Build(const byte* start, const byte* end) {
size_t locals_size = local_decls.Size(); local_decls.Prepend(zone(), &start, &end);
size_t total_size = end - start + locals_size + 1;
byte* buffer = static_cast<byte*>(zone()->New(total_size));
// Prepend the local decls to the code.
local_decls.Emit(buffer);
// Emit the code.
memcpy(buffer + locals_size, start, end - start);
// Append an extra end opcode.
buffer[total_size - 1] = kExprEnd;
start = buffer;
end = buffer + total_size;
CHECK_GE(kMaxInt, end - start); CHECK_GE(kMaxInt, end - start);
int len = static_cast<int>(end - start); int len = static_cast<int>(end - start);
......
...@@ -15,8 +15,8 @@ var break_count = 0; ...@@ -15,8 +15,8 @@ var break_count = 0;
const expected_frames = [ const expected_frames = [
// func-name; wasm?; pos; line; col // func-name; wasm?; pos; line; col
['call_debugger', false], // -- ['call_debugger', false], // --
['wasm_2', true, 56, 2, 2], // -- ['wasm_2', true, 56, 2, 0], // --
['wasm_1', true, 52, 3, 2], // -- ['wasm_1', true, 52, 3, 0], // --
['testFrameInspection', false], // -- ['testFrameInspection', false], // --
['', false] ['', false]
]; ];
......
Check that inspector gets two wasm scripts at module creation time. Check that inspector gets two wasm scripts at module creation time.
Script #0 parsed. URL: v8://test/testFunction Script #0 parsed. URL: v8://test/testFunction
Script #1 parsed. URL: v8://test/runTestRunction Script #1 parsed. URL: v8://test/runTestRunction
Script #2 parsed. URL: wasm://wasm/wasm-e783515e/wasm-e783515e-0 Script #2 parsed. URL: wasm://wasm/wasm-911a065e/wasm-911a065e-0
Script #3 parsed. URL: wasm://wasm/wasm-e783515e/wasm-e783515e-1 Script #3 parsed. URL: wasm://wasm/wasm-911a065e/wasm-911a065e-1
Source for wasm://wasm/wasm-e783515e/wasm-e783515e-0: Source for wasm://wasm/wasm-911a065e/wasm-911a065e-0:
func $nopFunction func $nopFunction
nop nop
end
Source for wasm://wasm/wasm-e783515e/wasm-e783515e-1: Source for wasm://wasm/wasm-911a065e/wasm-911a065e-1:
func $main func $main
block block
i32.const 2 i32.const 2
drop drop
end
end end
...@@ -2,8 +2,8 @@ Check that inspector gets disassembled wasm code ...@@ -2,8 +2,8 @@ Check that inspector gets disassembled wasm code
Paused on debugger! Paused on debugger!
Number of frames: 5 Number of frames: 5
[0] debugger; [0] debugger;
[1] call 0 [1] call 0
[2] call_indirect 2 [2] call_indirect 2
[3] instance.exports.main(); [3] instance.exports.main();
[4] testFunction(module_bytes) [4] testFunction(module_bytes)
Finished. Finished.
...@@ -2,8 +2,8 @@ Running testFunction with generated WASM bytes... ...@@ -2,8 +2,8 @@ Running testFunction with generated WASM bytes...
Paused on 'debugger;' Paused on 'debugger;'
Number of frames: 5 Number of frames: 5
- [0] {"functionName":"call_debugger","function_lineNumber":1,"function_columnNumber":24,"lineNumber":2,"columnNumber":4} - [0] {"functionName":"call_debugger","function_lineNumber":1,"function_columnNumber":24,"lineNumber":2,"columnNumber":4}
- [1] {"functionName":"call_func","lineNumber":1,"columnNumber":2} - [1] {"functionName":"call_func","lineNumber":1,"columnNumber":0}
- [2] {"functionName":"main","lineNumber":2,"columnNumber":4} - [2] {"functionName":"main","lineNumber":2,"columnNumber":2}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":14,"columnNumber":19} - [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":14,"columnNumber":19}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0} - [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Getting v8-generated stack trace... Getting v8-generated stack trace...
......
...@@ -152,7 +152,7 @@ function assertTableIsValid(table) { ...@@ -152,7 +152,7 @@ function assertTableIsValid(table) {
(function TestSet() { (function TestSet() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([])); builder.addExport("wasm", builder.addFunction("", kSig_v_v));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
...@@ -200,7 +200,7 @@ function assertTableIsValid(table) { ...@@ -200,7 +200,7 @@ function assertTableIsValid(table) {
(function TestIndexing() { (function TestIndexing() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([])); builder.addExport("wasm", builder.addFunction("", kSig_v_v));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
...@@ -223,7 +223,7 @@ function assertTableIsValid(table) { ...@@ -223,7 +223,7 @@ function assertTableIsValid(table) {
(function TestGrow() { (function TestGrow() {
let builder = new WasmModuleBuilder; let builder = new WasmModuleBuilder;
builder.addExport("wasm", builder.addFunction("", kSig_v_v).addBody([])); builder.addExport("wasm", builder.addFunction("", kSig_v_v));
builder.addExport("host", builder.addImport("test", "f", kSig_v_v)); builder.addExport("host", builder.addImport("test", "f", kSig_v_v));
let {wasm, host} = builder.instantiate({test: {f() {}}}).exports; let {wasm, host} = builder.instantiate({test: {f() {}}}).exports;
......
...@@ -98,8 +98,6 @@ class WasmFunctionBuilder { ...@@ -98,8 +98,6 @@ class WasmFunctionBuilder {
addBody(body) { addBody(body) {
this.body = body; this.body = body;
// Automatically add the end for the function block to the body.
body.push(kExprEnd);
return this; return this;
} }
......
...@@ -2439,10 +2439,10 @@ bool ValueSerializerTestWithWasm::g_saved_flag = false; ...@@ -2439,10 +2439,10 @@ bool ValueSerializerTestWithWasm::g_saved_flag = false;
// A simple module which exports an "increment" function. // A simple module which exports an "increment" function.
// Copied from test/mjsunit/wasm/incrementer.wasm. // Copied from test/mjsunit/wasm/incrementer.wasm.
const unsigned char kIncrementerWasm[] = { const unsigned char kIncrementerWasm[] = {
0, 97, 115, 109, 13, 0, 0, 0, 1, 6, 1, 96, 1, 127, 1, 127, 0x00, 0x61, 0x73, 0x6d, 0x0d, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
3, 2, 1, 0, 7, 13, 1, 9, 105, 110, 99, 114, 101, 109, 101, 110, 0x01, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x0d, 0x01, 0x09,
116, 0, 0, 10, 9, 1, 7, 0, 32, 0, 65, 1, 106, 11, 0x69, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x00, 0x00, 0x0a,
}; 0x08, 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a};
TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) { TEST_F(ValueSerializerTestWithWasm, RoundTripWasmModule) {
RoundTripTest( RoundTripTest(
...@@ -2521,7 +2521,6 @@ const unsigned char kSerializedIncrementerWasm[] = { ...@@ -2521,7 +2521,6 @@ const unsigned char kSerializedIncrementerWasm[] = {
0x2f, 0x2f}; 0x2f, 0x2f};
TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) { TEST_F(ValueSerializerTestWithWasm, DecodeWasmModule) {
if (true) return; // TODO(mtrofin): fix this test
std::vector<uint8_t> raw( std::vector<uint8_t> raw(
kSerializedIncrementerWasm, kSerializedIncrementerWasm,
kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm)); kSerializedIncrementerWasm + sizeof(kSerializedIncrementerWasm));
...@@ -2542,7 +2541,6 @@ const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = { ...@@ -2542,7 +2541,6 @@ const unsigned char kSerializedIncrementerWasmWithInvalidCompiledData[] = {
0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00}; 0x01, 0x06, 0x00, 0x20, 0x00, 0x41, 0x01, 0x6a, 0x00};
TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) { TEST_F(ValueSerializerTestWithWasm, DecodeWasmModuleWithInvalidCompiledData) {
if (true) return; // TODO(titzer): regenerate this test
std::vector<uint8_t> raw( std::vector<uint8_t> raw(
kSerializedIncrementerWasmWithInvalidCompiledData, kSerializedIncrementerWasmWithInvalidCompiledData,
kSerializedIncrementerWasmWithInvalidCompiledData + kSerializedIncrementerWasmWithInvalidCompiledData +
......
...@@ -108,19 +108,7 @@ class FunctionBodyDecoderTest : public TestWithZone { ...@@ -108,19 +108,7 @@ class FunctionBodyDecoderTest : public TestWithZone {
// verification failures. // verification failures.
void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
const byte* end) { const byte* end) {
size_t locals_size = local_decls.Size(); local_decls.Prepend(zone(), &start, &end);
size_t total_size = end - start + locals_size + 1;
byte* buffer = static_cast<byte*>(zone()->New(total_size));
// Prepend the local decls to the code.
local_decls.Emit(buffer);
// Emit the code.
memcpy(buffer + locals_size, start, end - start);
// Append an extra end opcode.
buffer[total_size - 1] = kExprEnd;
start = buffer;
end = buffer + total_size;
// Verify the code. // Verify the code.
DecodeResult result = VerifyWasmCode( DecodeResult result = VerifyWasmCode(
zone()->allocator(), module == nullptr ? nullptr : module->module, sig, zone()->allocator(), module == nullptr ? nullptr : module->module, sig,
...@@ -473,7 +461,11 @@ TEST_F(FunctionBodyDecoderTest, Block0Block0) { ...@@ -473,7 +461,11 @@ TEST_F(FunctionBodyDecoderTest, Block0Block0) {
} }
TEST_F(FunctionBodyDecoderTest, Block0_end) { TEST_F(FunctionBodyDecoderTest, Block0_end) {
EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd); EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd);
}
TEST_F(FunctionBodyDecoderTest, Block0_end_end) {
EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd);
} }
TEST_F(FunctionBodyDecoderTest, Block1) { TEST_F(FunctionBodyDecoderTest, Block1) {
...@@ -726,13 +718,14 @@ TEST_F(FunctionBodyDecoderTest, IfNopElseNop) { ...@@ -726,13 +718,14 @@ TEST_F(FunctionBodyDecoderTest, IfNopElseNop) {
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
} }
TEST_F(FunctionBodyDecoderTest, If_end) { TEST_F(FunctionBodyDecoderTest, If_end_end) {
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd}; static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd};
EXPECT_VERIFIES_C(v_i, code); EXPECT_VERIFIES_C(v_i, code);
} }
TEST_F(FunctionBodyDecoderTest, If_end_end) { TEST_F(FunctionBodyDecoderTest, If_end_end_end) {
static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP,
kExprEnd, kExprEnd, kExprEnd};
EXPECT_FAILURE_C(v_i, code); EXPECT_FAILURE_C(v_i, code);
} }
......
...@@ -933,7 +933,7 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { ...@@ -933,7 +933,7 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) {
kLocalF32, // -- kLocalF32, // --
6, 6,
kLocalF64, // -- kLocalF64, // --
kExprEnd // body kExprNop // body
}; };
FunctionResult result = FunctionResult result =
......
...@@ -49,7 +49,6 @@ TEST_F(WasmMacroGenTest, Constants) { ...@@ -49,7 +49,6 @@ TEST_F(WasmMacroGenTest, Constants) {
TEST_F(WasmMacroGenTest, Statements) { TEST_F(WasmMacroGenTest, Statements) {
EXPECT_SIZE(1, WASM_NOP); EXPECT_SIZE(1, WASM_NOP);
EXPECT_SIZE(1, WASM_END);
EXPECT_SIZE(4, WASM_SET_LOCAL(0, WASM_ZERO)); EXPECT_SIZE(4, WASM_SET_LOCAL(0, WASM_ZERO));
......
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