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 #ifndef V8_WASM_MODULE_H_ | 5 #ifndef V8_WASM_MODULE_H_ |
6 #define V8_WASM_MODULE_H_ | 6 #define V8_WASM_MODULE_H_ |
7 | 7 |
8 #include "src/wasm/wasm-opcodes.h" | 8 #include "src/wasm/wasm-opcodes.h" |
9 #include "src/wasm/wasm-result.h" | 9 #include "src/wasm/wasm-result.h" |
10 | 10 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 std::vector<FunctionSig*>* signatures; // signatures in this module. | 98 std::vector<FunctionSig*>* signatures; // signatures in this module. |
99 std::vector<WasmFunction>* functions; // functions in this module. | 99 std::vector<WasmFunction>* functions; // functions in this module. |
100 std::vector<WasmDataSegment>* data_segments; // data segments in this module. | 100 std::vector<WasmDataSegment>* data_segments; // data segments in this module. |
101 std::vector<uint16_t>* function_table; // function table. | 101 std::vector<uint16_t>* function_table; // function table. |
102 | 102 |
103 WasmModule(); | 103 WasmModule(); |
104 ~WasmModule(); | 104 ~WasmModule(); |
105 | 105 |
106 // Get a pointer to a string stored in the module bytes representing a name. | 106 // Get a pointer to a string stored in the module bytes representing a name. |
107 const char* GetName(uint32_t offset) { | 107 const char* GetName(uint32_t offset) { |
| 108 if (offset == 0) return "<?>"; // no name. |
108 CHECK(BoundsCheck(offset, offset + 1)); | 109 CHECK(BoundsCheck(offset, offset + 1)); |
109 if (offset == 0) return "<?>"; // no name. | |
110 return reinterpret_cast<const char*>(module_start + offset); | 110 return reinterpret_cast<const char*>(module_start + offset); |
111 } | 111 } |
112 | 112 |
113 // Checks the given offset range is contained within the module bytes. | 113 // Checks the given offset range is contained within the module bytes. |
114 bool BoundsCheck(uint32_t start, uint32_t end) { | 114 bool BoundsCheck(uint32_t start, uint32_t end) { |
115 size_t size = module_end - module_start; | 115 size_t size = module_end - module_start; |
116 return start < size && end < size; | 116 return start < size && end < size; |
117 } | 117 } |
118 | 118 |
119 // Creates a new instantiation of the module in the given isolate. | 119 // Creates a new instantiation of the module in the given isolate. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 const byte* module_end, bool asm_js = false); | 202 const byte* module_end, bool asm_js = false); |
203 | 203 |
204 // For testing. Decode, verify, and run the last exported function in the | 204 // For testing. Decode, verify, and run the last exported function in the |
205 // given decoded module. | 205 // given decoded module. |
206 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); | 206 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); |
207 } // namespace wasm | 207 } // namespace wasm |
208 } // namespace internal | 208 } // namespace internal |
209 } // namespace v8 | 209 } // namespace v8 |
210 | 210 |
211 #endif // V8_WASM_MODULE_H_ | 211 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |