Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 1874383002: [wasm] Throw real Error on wasm trap (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@trapreasons-to-messages
Patch Set: remove a TODO Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/isolate-inl.h" 7 #include "src/isolate-inl.h"
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (traps_[reason] == nullptr) { 186 if (traps_[reason] == nullptr) {
187 // Create trap code for the first time this trap is used. 187 // Create trap code for the first time this trap is used.
188 return BuildTrapCode(reason); 188 return BuildTrapCode(reason);
189 } 189 }
190 // Connect the current control and effect to the existing trap code. 190 // Connect the current control and effect to the existing trap code.
191 builder_->AppendToMerge(traps_[reason], builder_->Control()); 191 builder_->AppendToMerge(traps_[reason], builder_->Control());
192 builder_->AppendToPhi(traps_[reason], effects_[reason], builder_->Effect()); 192 builder_->AppendToPhi(traps_[reason], effects_[reason], builder_->Effect());
193 } 193 }
194 194
195 void BuildTrapCode(wasm::TrapReason reason) { 195 void BuildTrapCode(wasm::TrapReason reason) {
196 Node* exception = 196 Node* message_id = builder_->NumberConstant(
197 builder_->String(wasm::WasmOpcodes::TrapReasonMessage(reason)); 197 wasm::WasmOpcodes::TrapReasonToMessageId(reason));
198 Node* end; 198 Node* end;
199 Node** control_ptr = builder_->control_; 199 Node** control_ptr = builder_->control_;
200 Node** effect_ptr = builder_->effect_; 200 Node** effect_ptr = builder_->effect_;
201 wasm::ModuleEnv* module = builder_->module_; 201 wasm::ModuleEnv* module = builder_->module_;
202 DCHECK(traps_[reason] == NULL);
202 *control_ptr = traps_[reason] = 203 *control_ptr = traps_[reason] =
203 graph()->NewNode(common()->Merge(1), *control_ptr); 204 graph()->NewNode(common()->Merge(1), *control_ptr);
204 *effect_ptr = effects_[reason] = 205 *effect_ptr = effects_[reason] =
205 graph()->NewNode(common()->EffectPhi(1), *effect_ptr, *control_ptr); 206 graph()->NewNode(common()->EffectPhi(1), *effect_ptr, *control_ptr);
206 207
207 if (module && !module->instance->context.is_null()) { 208 if (module && !module->instance->context.is_null()) {
208 // Use the module context to call the runtime to throw an exception. 209 // Use the module context to call the runtime to throw an exception.
209 Runtime::FunctionId f = Runtime::kThrow; 210 Runtime::FunctionId f = Runtime::kThrowWasmError;
210 const Runtime::Function* fun = Runtime::FunctionForId(f); 211 const Runtime::Function* fun = Runtime::FunctionForId(f);
211 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( 212 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor(
212 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties, 213 jsgraph()->zone(), f, fun->nargs, Operator::kNoProperties,
213 CallDescriptor::kNoFlags); 214 CallDescriptor::kNoFlags);
214 Node* inputs[] = { 215 Node* inputs[] = {
215 jsgraph()->CEntryStubConstant(fun->result_size), // C entry 216 jsgraph()->CEntryStubConstant(fun->result_size), // C entry
216 exception, // exception 217 message_id, // message id
217 jsgraph()->ExternalConstant( 218 jsgraph()->ExternalConstant(
218 ExternalReference(f, jsgraph()->isolate())), // ref 219 ExternalReference(f, jsgraph()->isolate())), // ref
219 jsgraph()->Int32Constant(fun->nargs), // arity 220 jsgraph()->Int32Constant(fun->nargs), // arity
220 jsgraph()->Constant(module->instance->context), // context 221 jsgraph()->Constant(module->instance->context), // context
221 *effect_ptr, 222 *effect_ptr,
222 *control_ptr}; 223 *control_ptr};
223 224
224 Node* node = graph()->NewNode( 225 Node* node = graph()->NewNode(
225 common()->Call(desc), static_cast<int>(arraysize(inputs)), inputs); 226 common()->Call(desc), static_cast<int>(arraysize(inputs)), inputs);
226 *control_ptr = node; 227 *control_ptr = node;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 338
338 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects, 339 Node* WasmGraphBuilder::EffectPhi(unsigned count, Node** effects,
339 Node* control) { 340 Node* control) {
340 DCHECK(IrOpcode::IsMergeOpcode(control->opcode())); 341 DCHECK(IrOpcode::IsMergeOpcode(control->opcode()));
341 Node** buf = Realloc(effects, count, count + 1); 342 Node** buf = Realloc(effects, count, count + 1);
342 buf[count] = control; 343 buf[count] = control;
343 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1, 344 return graph()->NewNode(jsgraph()->common()->EffectPhi(count), count + 1,
344 buf); 345 buf);
345 } 346 }
346 347
348 Node* WasmGraphBuilder::NumberConstant(int32_t value) {
349 return jsgraph()->Constant(value);
350 }
347 351
348 Node* WasmGraphBuilder::Int32Constant(int32_t value) { 352 Node* WasmGraphBuilder::Int32Constant(int32_t value) {
349 return jsgraph()->Int32Constant(value); 353 return jsgraph()->Int32Constant(value);
350 } 354 }
351 355
352 356
353 Node* WasmGraphBuilder::Int64Constant(int64_t value) { 357 Node* WasmGraphBuilder::Int64Constant(int64_t value) {
354 return jsgraph()->Int64Constant(value); 358 return jsgraph()->Int64Constant(value);
355 } 359 }
356 360
(...skipping 2680 matching lines...) Expand 10 before | Expand all | Expand 10 after
3037 // TODO(bradnelson): Improve histogram handling of size_t. 3041 // TODO(bradnelson): Improve histogram handling of size_t.
3038 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample( 3042 isolate->counters()->wasm_compile_function_peak_memory_bytes()->AddSample(
3039 static_cast<int>(zone.allocation_size())); 3043 static_cast<int>(zone.allocation_size()));
3040 return code; 3044 return code;
3041 } 3045 }
3042 3046
3043 3047
3044 } // namespace compiler 3048 } // namespace compiler
3045 } // namespace internal 3049 } // namespace internal
3046 } // namespace v8 3050 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/wasm-compiler.h ('k') | src/runtime/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698