[wasm] [test] Introduce enum for runtime exception support

We were using a boolean before, which makes the meaning non-obvious
when passed as a parameter. With the enum, you actually have to use
{kRuntimeExceptionSupport} or {kNoRuntimeExceptionSupport}.

R=mtrofin@chromium.org

Change-Id: Iaf5a7b6f1b446d4c3e16e044a6055d923d3b0b49
Reviewed-on: https://chromium-review.googlesource.com/660738
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47969}
This commit is contained in:
Clemens Hammacher 2017-09-12 13:00:20 +02:00 committed by Commit Bot
parent d8864701fd
commit 3c8e1598bd
7 changed files with 44 additions and 32 deletions

View File

@ -194,7 +194,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position,
Node** effect, Node** control) {
// TODO(mtrofin): "!env_" happens when we generate a wrapper.
// We should factor wrappers separately from wasm codegen.
if (FLAG_wasm_no_stack_checks || !env_ || !has_runtime_exception_support_) {
if (FLAG_wasm_no_stack_checks || !env_ || !runtime_exception_support_) {
return;
}
if (effect == nullptr) effect = effect_;
@ -830,7 +830,7 @@ Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node,
}
Builtins::Name WasmGraphBuilder::GetBuiltinIdForTrap(wasm::TrapReason reason) {
if (!has_runtime_exception_support_) {
if (runtime_exception_support_ == kNoRuntimeExceptionSupport) {
// We use Builtins::builtin_count as a marker to tell the code generator
// to generate a call to a testing c-function instead of a runtime
// function. This code should only be called from a cctest.

View File

@ -78,6 +78,11 @@ struct ModuleEnv {
const uintptr_t globals_start;
};
enum RuntimeExceptionSupport : bool {
kRuntimeExceptionSupport = true,
kNoRuntimeExceptionSupport = false
};
class WasmCompilationUnit final {
public:
// If constructing from a background thread, pass in a Counters*, and ensure
@ -317,8 +322,8 @@ class WasmGraphBuilder {
bool has_simd() const { return has_simd_; }
void SetRuntimeExceptionSupport(bool value) {
has_runtime_exception_support_ = value;
void set_runtime_exception_support(RuntimeExceptionSupport value) {
runtime_exception_support_ = value;
}
const wasm::WasmModule* module() { return env_ ? env_->module : nullptr; }
@ -345,7 +350,7 @@ class WasmGraphBuilder {
// If the runtime doesn't support exception propagation,
// we won't generate stack checks, and trap handling will also
// be generated differently.
bool has_runtime_exception_support_ = true;
RuntimeExceptionSupport runtime_exception_support_ = kRuntimeExceptionSupport;
wasm::FunctionSig* sig_;
SetOncePointer<const Operator> allocate_heap_number_operator_;

View File

@ -1951,7 +1951,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode),
WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code));
code + arraysize(code),
compiler::kNoRuntimeExceptionSupport);
} else {
CHECK_EQ(2, sig->parameter_count());
byte code[] = {WASM_NO_LOCALS,
@ -1962,7 +1963,8 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
static_cast<byte>(opcode),
WASM_END};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code));
code + arraysize(code),
compiler::kNoRuntimeExceptionSupport);
}
}

View File

@ -155,7 +155,8 @@ TEST(CollectDetailedWasmStack_WasmError) {
int unreachable_pos = 1 << (8 * pos_shift);
TestSignatures sigs;
// Create a WasmRunner with stack checks and traps enabled.
WasmRunner<int> r(kExecuteCompiled, "main", true);
WasmRunner<int> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
std::vector<byte> code(unreachable_pos + 1, kExprNop);
code[unreachable_pos] = kExprUnreachable;

View File

@ -68,7 +68,8 @@ void CheckExceptionInfos(v8::internal::Isolate* i_isolate, Handle<Object> exc,
// Trigger a trap for executing unreachable.
TEST(Unreachable) {
// Create a WasmRunner with stack checks and traps enabled.
WasmRunner<void> r(kExecuteCompiled, "main", true);
WasmRunner<void> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
TestSignatures sigs;
BUILD(r, WASM_UNREACHABLE);
@ -102,7 +103,8 @@ TEST(Unreachable) {
// Trigger a trap for loading from out-of-bounds.
TEST(IllegalLoad) {
WasmRunner<void> r(kExecuteCompiled, "main", true);
WasmRunner<void> r(kExecuteCompiled, "main",
compiler::kRuntimeExceptionSupport);
TestSignatures sigs;
r.builder().AddMemory(0L);

View File

@ -239,15 +239,15 @@ Handle<WasmInstanceObject> TestingModuleBuilder::InitInstanceObject() {
return WasmInstanceObject::New(isolate_, compiled_module);
}
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
compiler::ModuleEnv* module, FunctionSig* sig,
compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end,
bool runtime_exception_support) {
void TestBuildingGraph(
Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module,
FunctionSig* sig, compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end,
compiler::RuntimeExceptionSupport runtime_exception_support) {
compiler::WasmGraphBuilder builder(
module, zone, jsgraph, CEntryStub(jsgraph->isolate(), 1).GetCode(), sig,
source_position_table);
builder.SetRuntimeExceptionSupport(runtime_exception_support);
builder.set_runtime_exception_support(runtime_exception_support);
DecodeResult result =
BuildTFGraph(zone->allocator(), &builder, sig, start, end);
@ -420,10 +420,10 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
}
}
WasmFunctionCompiler::WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
TestingModuleBuilder* builder,
const char* name,
bool runtime_exception_support)
WasmFunctionCompiler::WasmFunctionCompiler(
Zone* zone, FunctionSig* sig, TestingModuleBuilder* builder,
const char* name,
compiler::RuntimeExceptionSupport runtime_exception_support)
: GraphAndBuilders(zone),
jsgraph(builder->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),

View File

@ -210,11 +210,11 @@ class TestingModuleBuilder {
Handle<WasmInstanceObject> InitInstanceObject();
};
void TestBuildingGraph(Zone* zone, compiler::JSGraph* jsgraph,
compiler::ModuleEnv* module, FunctionSig* sig,
compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end,
bool runtime_exception_support = false);
void TestBuildingGraph(
Zone* zone, compiler::JSGraph* jsgraph, compiler::ModuleEnv* module,
FunctionSig* sig, compiler::SourcePositionTable* source_position_table,
const byte* start, const byte* end,
compiler::RuntimeExceptionSupport runtime_exception_support);
class WasmFunctionWrapper : private compiler::GraphAndBuilders {
public:
@ -275,9 +275,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
private:
friend class WasmRunnerBase;
WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
TestingModuleBuilder* builder, const char* name,
bool runtime_exception_support);
WasmFunctionCompiler(Zone*, FunctionSig*, TestingModuleBuilder*,
const char* name, compiler::RuntimeExceptionSupport);
Handle<Code> Compile();
@ -290,7 +289,8 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
LocalDeclEncoder local_decls;
compiler::SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
bool runtime_exception_support_ = false;
compiler::RuntimeExceptionSupport runtime_exception_support_ =
compiler::kNoRuntimeExceptionSupport;
};
// A helper class to build a module around Wasm bytecode, generate machine
@ -298,7 +298,7 @@ class WasmFunctionCompiler : public compiler::GraphAndBuilders {
class WasmRunnerBase : public HandleAndZoneScope {
public:
WasmRunnerBase(WasmExecutionMode execution_mode, int num_params,
bool runtime_exception_support)
compiler::RuntimeExceptionSupport runtime_exception_support)
: zone_(&allocator_, ZONE_NAME),
builder_(&zone_, execution_mode),
wrapper_(&zone_, num_params),
@ -367,7 +367,8 @@ class WasmRunnerBase : public HandleAndZoneScope {
WasmFunctionWrapper wrapper_;
bool compiled_ = false;
bool possible_nondeterminism_ = false;
bool runtime_exception_support_ = false;
compiler::RuntimeExceptionSupport runtime_exception_support_ =
compiler::kNoRuntimeExceptionSupport;
public:
// This field has to be static. Otherwise, gcc complains about the use in
@ -380,7 +381,8 @@ class WasmRunner : public WasmRunnerBase {
public:
WasmRunner(WasmExecutionMode execution_mode,
const char* main_fn_name = "main",
bool runtime_exception_support = false)
compiler::RuntimeExceptionSupport runtime_exception_support =
compiler::kNoRuntimeExceptionSupport)
: WasmRunnerBase(execution_mode, sizeof...(ParamTypes),
runtime_exception_support) {
NewFunction<ReturnType, ParamTypes...>(main_fn_name);