OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/wasm-compiler.h" | 5 #include "src/compiler/wasm-compiler.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 position); | 161 position); |
162 return builder_->Control(); | 162 return builder_->Control(); |
163 } | 163 } |
164 | 164 |
165 // Add a check that traps if {node} is zero. | 165 // Add a check that traps if {node} is zero. |
166 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, | 166 Node* ZeroCheck64(wasm::TrapReason reason, Node* node, |
167 wasm::WasmCodePosition position) { | 167 wasm::WasmCodePosition position) { |
168 return TrapIfEq64(reason, node, 0, position); | 168 return TrapIfEq64(reason, node, 0, position); |
169 } | 169 } |
170 | 170 |
171 int32_t GetFunctionIdForTrap(wasm::TrapReason reason) { | 171 Runtime::FunctionId GetFunctionIdForTrap(wasm::TrapReason reason) { |
172 int32_t trap_id; | |
173 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { | 172 if (builder_->module_ && !builder_->module_->instance->context.is_null()) { |
174 trap_id = wasm::WasmOpcodes::TrapReasonToFunctionId(reason); | 173 switch (reason) { |
| 174 #define TRAPREASON_TO_MESSAGE(name) \ |
| 175 case wasm::k##name: \ |
| 176 return Runtime::kThrowWasm##name; |
| 177 FOREACH_WASM_TRAPREASON(TRAPREASON_TO_MESSAGE) |
| 178 #undef TRAPREASON_TO_MESSAGE |
| 179 default: |
| 180 UNREACHABLE(); |
| 181 return Runtime::kNumFunctions; |
| 182 } |
175 } else { | 183 } else { |
176 // We use Runtime::kNumFunctions as a marker to tell the code generator | 184 // We use Runtime::kNumFunctions as a marker to tell the code generator |
177 // to generate a call to a testing c-function instead of a runtime | 185 // to generate a call to a testing c-function instead of a runtime |
178 // function. This code should only be called from a cctest. | 186 // function. This code should only be called from a cctest. |
179 trap_id = Runtime::kNumFunctions; | 187 return Runtime::kNumFunctions; |
180 } | 188 } |
181 return trap_id; | |
182 } | 189 } |
183 | 190 |
184 #if V8_TARGET_ARCH_X64 | 191 #if V8_TARGET_ARCH_X64 || V8_TARGET_ARCH_IA32 |
185 #define WASM_TRAP_IF_SUPPORTED | 192 #define WASM_TRAP_IF_SUPPORTED |
186 #endif | 193 #endif |
187 | 194 |
188 // Add a trap if {cond} is true. | 195 // Add a trap if {cond} is true. |
189 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, | 196 void AddTrapIfTrue(wasm::TrapReason reason, Node* cond, |
190 wasm::WasmCodePosition position) { | 197 wasm::WasmCodePosition position) { |
191 #ifdef WASM_TRAP_IF_SUPPORTED | 198 #ifdef WASM_TRAP_IF_SUPPORTED |
192 if (FLAG_wasm_trap_if) { | 199 if (FLAG_wasm_trap_if) { |
193 int32_t trap_id = GetFunctionIdForTrap(reason); | 200 int32_t trap_id = GetFunctionIdForTrap(reason); |
194 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, | 201 Node* node = graph()->NewNode(common()->TrapIf(trap_id), cond, |
195 builder_->Effect(), builder_->Control()); | 202 builder_->Effect(), builder_->Control()); |
196 *builder_->control_ = node; | 203 *builder_->control_ = node; |
197 builder_->SetSourcePosition(node, position); | 204 builder_->SetSourcePosition(node, position); |
198 return; | 205 return; |
199 } | 206 } |
200 #endif // V8_TARGET_ARCH_X64 | 207 #endif // WASM_TRAP_IF_SUPPORTED |
201 BuildTrapIf(reason, cond, true, position); | 208 BuildTrapIf(reason, cond, true, position); |
202 } | 209 } |
203 | 210 |
204 // Add a trap if {cond} is false. | 211 // Add a trap if {cond} is false. |
205 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, | 212 void AddTrapIfFalse(wasm::TrapReason reason, Node* cond, |
206 wasm::WasmCodePosition position) { | 213 wasm::WasmCodePosition position) { |
207 #ifdef WASM_TRAP_IF_SUPPORTED | 214 #ifdef WASM_TRAP_IF_SUPPORTED |
208 if (FLAG_wasm_trap_if) { | 215 if (FLAG_wasm_trap_if) { |
209 int32_t trap_id = GetFunctionIdForTrap(reason); | 216 int32_t trap_id = GetFunctionIdForTrap(reason); |
210 | 217 |
211 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, | 218 Node* node = graph()->NewNode(common()->TrapUnless(trap_id), cond, |
212 builder_->Effect(), builder_->Control()); | 219 builder_->Effect(), builder_->Control()); |
213 *builder_->control_ = node; | 220 *builder_->control_ = node; |
214 builder_->SetSourcePosition(node, position); | 221 builder_->SetSourcePosition(node, position); |
215 return; | 222 return; |
216 } | 223 } |
217 #endif // V8_TARGET_ARCH_X64 | 224 #endif // WASM_TRAP_IF_SUPPORTED |
218 | 225 |
219 BuildTrapIf(reason, cond, false, position); | 226 BuildTrapIf(reason, cond, false, position); |
220 } | 227 } |
221 | 228 |
222 // Add a trap if {cond} is true or false according to {iftrue}. | 229 // Add a trap if {cond} is true or false according to {iftrue}. |
223 void BuildTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, | 230 void BuildTrapIf(wasm::TrapReason reason, Node* cond, bool iftrue, |
224 wasm::WasmCodePosition position) { | 231 wasm::WasmCodePosition position) { |
225 Node** effect_ptr = builder_->effect_; | 232 Node** effect_ptr = builder_->effect_; |
226 Node** control_ptr = builder_->control_; | 233 Node** control_ptr = builder_->control_; |
227 Node* before = *effect_ptr; | 234 Node* before = *effect_ptr; |
(...skipping 3424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3652 Smi::FromInt(instruction.instr_offset)); | 3659 Smi::FromInt(instruction.instr_offset)); |
3653 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, | 3660 fn_protected->set(Code::kTrapDataSize * i + Code::kTrapLandingOffset, |
3654 Smi::FromInt(instruction.landing_offset)); | 3661 Smi::FromInt(instruction.landing_offset)); |
3655 } | 3662 } |
3656 return fn_protected; | 3663 return fn_protected; |
3657 } | 3664 } |
3658 | 3665 |
3659 } // namespace compiler | 3666 } // namespace compiler |
3660 } // namespace internal | 3667 } // namespace internal |
3661 } // namespace v8 | 3668 } // namespace v8 |
OLD | NEW |