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/wasm/wasm-objects.h" | 5 #include "src/wasm/wasm-objects.h" |
6 #include "src/wasm/wasm-module.h" | 6 #include "src/wasm/wasm-module.h" |
7 | 7 |
8 #define TRACE(...) \ | 8 #define TRACE(...) \ |
9 do { \ | 9 do { \ |
10 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ | 10 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 static uint32_t SafeUint32(Object* value) { | 43 static uint32_t SafeUint32(Object* value) { |
44 if (value->IsSmi()) { | 44 if (value->IsSmi()) { |
45 int32_t val = Smi::cast(value)->value(); | 45 int32_t val = Smi::cast(value)->value(); |
46 CHECK_GE(val, 0); | 46 CHECK_GE(val, 0); |
47 return static_cast<uint32_t>(val); | 47 return static_cast<uint32_t>(val); |
48 } | 48 } |
49 DCHECK(value->IsHeapNumber()); | 49 DCHECK(value->IsHeapNumber()); |
50 HeapNumber* num = HeapNumber::cast(value); | 50 HeapNumber* num = HeapNumber::cast(value); |
51 CHECK_GE(num->value(), 0.0); | 51 CHECK_GE(num->value(), 0.0); |
52 CHECK_LE(num->value(), kMaxUInt32); | 52 CHECK_LE(num->value(), static_cast<double>(kMaxUInt32)); |
53 return static_cast<uint32_t>(num->value()); | 53 return static_cast<uint32_t>(num->value()); |
54 } | 54 } |
55 | 55 |
56 static int32_t SafeInt32(Object* value) { | 56 static int32_t SafeInt32(Object* value) { |
57 if (value->IsSmi()) { | 57 if (value->IsSmi()) { |
58 return Smi::cast(value)->value(); | 58 return Smi::cast(value)->value(); |
59 } | 59 } |
60 DCHECK(value->IsHeapNumber()); | 60 DCHECK(value->IsHeapNumber()); |
61 HeapNumber* num = HeapNumber::cast(value); | 61 HeapNumber* num = HeapNumber::cast(value); |
62 CHECK_GE(num->value(), Smi::kMinValue); | 62 CHECK_GE(num->value(), static_cast<double>(Smi::kMinValue)); |
63 CHECK_LE(num->value(), Smi::kMaxValue); | 63 CHECK_LE(num->value(), static_cast<double>(Smi::kMaxValue)); |
64 return static_cast<int32_t>(num->value()); | 64 return static_cast<int32_t>(num->value()); |
65 } | 65 } |
66 | 66 |
67 Handle<WasmModuleObject> WasmModuleObject::New( | 67 Handle<WasmModuleObject> WasmModuleObject::New( |
68 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { | 68 Isolate* isolate, Handle<WasmCompiledModule> compiled_module) { |
69 ModuleOrigin origin = compiled_module->module()->origin; | 69 ModuleOrigin origin = compiled_module->module()->origin; |
70 | 70 |
71 Handle<JSObject> module_object; | 71 Handle<JSObject> module_object; |
72 if (origin == ModuleOrigin::kWasmOrigin) { | 72 if (origin == ModuleOrigin::kWasmOrigin) { |
73 Handle<JSFunction> module_cons( | 73 Handle<JSFunction> module_cons( |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 | 364 |
365 uint32_t WasmCompiledModule::default_mem_size() const { | 365 uint32_t WasmCompiledModule::default_mem_size() const { |
366 return min_mem_pages() * WasmModule::kPageSize; | 366 return min_mem_pages() * WasmModule::kPageSize; |
367 } | 367 } |
368 | 368 |
369 Vector<const uint8_t> WasmCompiledModule::GetRawFunctionName( | 369 Vector<const uint8_t> WasmCompiledModule::GetRawFunctionName( |
370 uint32_t func_index) { | 370 uint32_t func_index) { |
371 DCHECK_GT(module()->functions.size(), func_index); | 371 DCHECK_GT(module()->functions.size(), func_index); |
372 WasmFunction& function = module()->functions[func_index]; | 372 WasmFunction& function = module()->functions[func_index]; |
373 SeqOneByteString* bytes = ptr_to_module_bytes(); | 373 SeqOneByteString* bytes = ptr_to_module_bytes(); |
374 DCHECK_GE(bytes->length(), function.name_offset); | 374 DCHECK_GE(static_cast<size_t>(bytes->length()), function.name_offset); |
375 DCHECK_GE(bytes->length() - function.name_offset, function.name_length); | 375 DCHECK_GE(static_cast<size_t>(bytes->length() - function.name_offset), |
| 376 function.name_length); |
376 return Vector<const uint8_t>(bytes->GetCharsAddress() + function.name_offset, | 377 return Vector<const uint8_t>(bytes->GetCharsAddress() + function.name_offset, |
377 function.name_length); | 378 function.name_length); |
378 } | 379 } |
379 | 380 |
380 int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) const { | 381 int WasmCompiledModule::GetFunctionOffset(uint32_t func_index) const { |
381 std::vector<WasmFunction>& functions = module()->functions; | 382 std::vector<WasmFunction>& functions = module()->functions; |
382 if (static_cast<uint32_t>(func_index) >= functions.size()) return -1; | 383 if (static_cast<uint32_t>(func_index) >= functions.size()) return -1; |
383 DCHECK_GE(kMaxInt, functions[func_index].code_start_offset); | 384 DCHECK_GE(static_cast<uint32_t>(kMaxInt), |
| 385 functions[func_index].code_start_offset); |
384 return static_cast<int>(functions[func_index].code_start_offset); | 386 return static_cast<int>(functions[func_index].code_start_offset); |
385 } | 387 } |
386 | 388 |
387 int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) const { | 389 int WasmCompiledModule::GetContainingFunction(uint32_t byte_offset) const { |
388 std::vector<WasmFunction>& functions = module()->functions; | 390 std::vector<WasmFunction>& functions = module()->functions; |
389 | 391 |
390 // Binary search for a function containing the given position. | 392 // Binary search for a function containing the given position. |
391 int left = 0; // inclusive | 393 int left = 0; // inclusive |
392 int right = static_cast<int>(functions.size()); // exclusive | 394 int right = static_cast<int>(functions.size()); // exclusive |
393 if (right == 0) return false; | 395 if (right == 0) return false; |
(...skipping 21 matching lines...) Expand all Loading... |
415 if (func_index < 0) return false; | 417 if (func_index < 0) return false; |
416 | 418 |
417 WasmFunction& function = module()->functions[func_index]; | 419 WasmFunction& function = module()->functions[func_index]; |
418 | 420 |
419 info->line = func_index; | 421 info->line = func_index; |
420 info->column = position - function.code_start_offset; | 422 info->column = position - function.code_start_offset; |
421 info->line_start = function.code_start_offset; | 423 info->line_start = function.code_start_offset; |
422 info->line_end = function.code_end_offset; | 424 info->line_end = function.code_end_offset; |
423 return true; | 425 return true; |
424 } | 426 } |
OLD | NEW |