Index: src/compiler/wasm-compiler.cc |
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc |
index b0e76e6b2daf6d2efa4d67ea5680e88edd7d404e..f114db47af496df222e8b63869556a7f767d5fd7 100644 |
--- a/src/compiler/wasm-compiler.cc |
+++ b/src/compiler/wasm-compiler.cc |
@@ -168,15 +168,50 @@ class WasmTrapHelper : public ZoneObject { |
return TrapIfEq64(reason, node, 0, position); |
} |
+ int32_t GetFunctionIdForTrap(wasm::TrapReason reason) { |
+ int32_t trap_id; |
+ if (builder_->module_ && !builder_->module_->instance->context.is_null()) { |
+ trap_id = wasm::WasmOpcodes::TrapReasonToFunctionId(reason); |
+ } else { |
+ // We use Runtime::kNumFunctions 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. |
+ trap_id = Runtime::kNumFunctions; |
+ } |
+ return trap_id; |
+ } |
+ |
// Add a trap if {cond} is true. |
void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, |
wasm::WasmCodePosition position) { |
+#if V8_TARGET_ARCH_X64 |
titzer
2016/12/12 14:21:33
Can you introduce another preprocessor definition,
ahaas
2016/12/13 12:38:59
Done.
|
+ if (FLAG_wasm_trap_if) { |
+ int32_t trap_id = GetFunctionIdForTrap(reason); |
+ Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, |
+ builder_->Effect(), builder_->Control()); |
+ *builder_->control_ = node; |
+ builder_->SetSourcePosition(node, position); |
+ return; |
+ } |
+#endif // V8_TARGET_ARCH_X64 |
AddTrapIf(reason, cond, true, position); |
titzer
2016/12/12 14:21:33
Can we rename this internal function to BuildTrapI
ahaas
2016/12/13 12:38:59
Done.
|
} |
// Add a trap if {cond} is false. |
void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, |
wasm::WasmCodePosition position) { |
+#if V8_TARGET_ARCH_X64 |
+ if (FLAG_wasm_trap_if) { |
+ int32_t trap_id = GetFunctionIdForTrap(reason); |
+ |
+ Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, |
+ builder_->Effect(), builder_->Control()); |
+ *builder_->control_ = node; |
+ builder_->SetSourcePosition(node, position); |
+ return; |
+ } |
+#endif // V8_TARGET_ARCH_X64 |
+ |
AddTrapIf(reason, cond, false, position); |
} |