| 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/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
| 6 | 6 |
| 7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 LocalType* buffer = | 766 LocalType* buffer = |
| 767 module_zone->NewArray<LocalType>(param_count + return_count); | 767 module_zone->NewArray<LocalType>(param_count + return_count); |
| 768 uint32_t b = 0; | 768 uint32_t b = 0; |
| 769 for (uint32_t i = 0; i < return_count; i++) buffer[b++] = returns[i]; | 769 for (uint32_t i = 0; i < return_count; i++) buffer[b++] = returns[i]; |
| 770 for (uint32_t i = 0; i < param_count; i++) buffer[b++] = params[i]; | 770 for (uint32_t i = 0; i < param_count; i++) buffer[b++] = params[i]; |
| 771 | 771 |
| 772 return new (module_zone) FunctionSig(return_count, param_count, buffer); | 772 return new (module_zone) FunctionSig(return_count, param_count, buffer); |
| 773 } | 773 } |
| 774 }; | 774 }; |
| 775 | 775 |
| 776 | |
| 777 // Helpers for nice error messages. | 776 // Helpers for nice error messages. |
| 778 class ModuleError : public ModuleResult { | 777 class ModuleError : public ModuleResult { |
| 779 public: | 778 public: |
| 780 explicit ModuleError(const char* msg) { | 779 explicit ModuleError(const char* msg) { |
| 781 error_code = kError; | 780 error_code = kError; |
| 782 size_t len = strlen(msg) + 1; | 781 size_t len = strlen(msg) + 1; |
| 783 char* result = new char[len]; | 782 char* result = new char[len]; |
| 784 strncpy(result, msg, len); | 783 strncpy(result, msg, len); |
| 785 result[len - 1] = 0; | 784 result[len - 1] = 0; |
| 786 error_msg.Reset(result); | 785 error_msg.Reset(result); |
| 787 } | 786 } |
| 788 }; | 787 }; |
| 789 | 788 |
| 790 | |
| 791 // Helpers for nice error messages. | 789 // Helpers for nice error messages. |
| 792 class FunctionError : public FunctionResult { | 790 class FunctionError : public FunctionResult { |
| 793 public: | 791 public: |
| 794 explicit FunctionError(const char* msg) { | 792 explicit FunctionError(const char* msg) { |
| 795 error_code = kError; | 793 error_code = kError; |
| 796 size_t len = strlen(msg) + 1; | 794 size_t len = strlen(msg) + 1; |
| 797 char* result = new char[len]; | 795 char* result = new char[len]; |
| 798 strncpy(result, msg, len); | 796 strncpy(result, msg, len); |
| 799 result[len - 1] = 0; | 797 result[len - 1] = 0; |
| 800 error_msg.Reset(result); | 798 error_msg.Reset(result); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 821 static_cast<int>(zone->allocation_size() - decode_memory_start)); | 819 static_cast<int>(zone->allocation_size() - decode_memory_start)); |
| 822 return result; | 820 return result; |
| 823 } | 821 } |
| 824 | 822 |
| 825 FunctionSig* DecodeWasmSignatureForTesting(Zone* zone, const byte* start, | 823 FunctionSig* DecodeWasmSignatureForTesting(Zone* zone, const byte* start, |
| 826 const byte* end) { | 824 const byte* end) { |
| 827 ModuleDecoder decoder(zone, start, end, kWasmOrigin); | 825 ModuleDecoder decoder(zone, start, end, kWasmOrigin); |
| 828 return decoder.DecodeFunctionSignature(start); | 826 return decoder.DecodeFunctionSignature(start); |
| 829 } | 827 } |
| 830 | 828 |
| 831 | |
| 832 FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone, | 829 FunctionResult DecodeWasmFunction(Isolate* isolate, Zone* zone, |
| 833 ModuleEnv* module_env, | 830 ModuleEnv* module_env, |
| 834 const byte* function_start, | 831 const byte* function_start, |
| 835 const byte* function_end) { | 832 const byte* function_end) { |
| 836 HistogramTimerScope wasm_decode_function_time_scope( | 833 HistogramTimerScope wasm_decode_function_time_scope( |
| 837 isolate->counters()->wasm_decode_function_time()); | 834 isolate->counters()->wasm_decode_function_time()); |
| 838 size_t size = function_end - function_start; | 835 size_t size = function_end - function_start; |
| 839 if (function_start > function_end) return FunctionError("start > end"); | 836 if (function_start > function_end) return FunctionError("start > end"); |
| 840 if (size > kMaxFunctionSize) | 837 if (size > kMaxFunctionSize) |
| 841 return FunctionError("size > maximum function size"); | 838 return FunctionError("size > maximum function size"); |
| 842 isolate->counters()->wasm_function_size_bytes()->AddSample( | 839 isolate->counters()->wasm_function_size_bytes()->AddSample( |
| 843 static_cast<int>(size)); | 840 static_cast<int>(size)); |
| 844 WasmFunction* function = new WasmFunction(); | 841 WasmFunction* function = new WasmFunction(); |
| 845 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 842 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
| 846 return decoder.DecodeSingleFunction(module_env, function); | 843 return decoder.DecodeSingleFunction(module_env, function); |
| 847 } | 844 } |
| 848 } // namespace wasm | 845 } // namespace wasm |
| 849 } // namespace internal | 846 } // namespace internal |
| 850 } // namespace v8 | 847 } // namespace v8 |
| OLD | NEW |