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

Side by Side Diff: src/wasm/wasm-module.h

Issue 1912103002: [wasm] Store function names in the wasm object (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-2
Patch Set: rebase Created 4 years, 7 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/wasm/wasm-function-name-table.cc ('k') | src/wasm/wasm-module.cc » ('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 #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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 // Get a string stored in the module bytes representing a name. 189 // Get a string stored in the module bytes representing a name.
190 WasmName GetName(uint32_t offset, uint32_t length) const { 190 WasmName GetName(uint32_t offset, uint32_t length) const {
191 if (length == 0) return {"<?>", 3}; // no name. 191 if (length == 0) return {"<?>", 3}; // no name.
192 CHECK(BoundsCheck(offset, offset + length)); 192 CHECK(BoundsCheck(offset, offset + length));
193 DCHECK_GE(static_cast<int>(length), 0); 193 DCHECK_GE(static_cast<int>(length), 0);
194 return {reinterpret_cast<const char*>(module_start + offset), 194 return {reinterpret_cast<const char*>(module_start + offset),
195 static_cast<int>(length)}; 195 static_cast<int>(length)};
196 } 196 }
197 197
198 // Get a string stored in the module bytes representing a function name.
199 WasmName GetName(WasmFunction* function) const {
200 return GetName(function->name_offset, function->name_length);
201 }
202
198 // Get a string stored in the module bytes representing a name. 203 // Get a string stored in the module bytes representing a name.
199 WasmName GetNameOrNull(uint32_t offset, uint32_t length) const { 204 WasmName GetNameOrNull(uint32_t offset, uint32_t length) const {
200 if (length == 0) return {NULL, 0}; // no name. 205 if (length == 0) return {NULL, 0}; // no name.
201 CHECK(BoundsCheck(offset, offset + length)); 206 CHECK(BoundsCheck(offset, offset + length));
202 DCHECK_GE(static_cast<int>(length), 0); 207 DCHECK_GE(static_cast<int>(length), 0);
203 return {reinterpret_cast<const char*>(module_start + offset), 208 return {reinterpret_cast<const char*>(module_start + offset),
204 static_cast<int>(length)}; 209 static_cast<int>(length)};
205 } 210 }
206 211
212 // Get a string stored in the module bytes representing a function name.
213 WasmName GetNameOrNull(WasmFunction* function) const {
214 return GetNameOrNull(function->name_offset, function->name_length);
215 }
216
207 // Checks the given offset range is contained within the module bytes. 217 // Checks the given offset range is contained within the module bytes.
208 bool BoundsCheck(uint32_t start, uint32_t end) const { 218 bool BoundsCheck(uint32_t start, uint32_t end) const {
209 size_t size = module_end - module_start; 219 size_t size = module_end - module_start;
210 return start < size && end < size; 220 return start < size && end < size;
211 } 221 }
212 222
213 // Creates a new instantiation of the module in the given isolate. 223 // Creates a new instantiation of the module in the given isolate.
214 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi, 224 MaybeHandle<JSObject> Instantiate(Isolate* isolate, Handle<JSObject> ffi,
215 Handle<JSArrayBuffer> memory); 225 Handle<JSArrayBuffer> memory);
216 }; 226 };
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 324
315 // For testing. Decode, verify, and run the last exported function in the 325 // For testing. Decode, verify, and run the last exported function in the
316 // given encoded module. 326 // given encoded module.
317 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, 327 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
318 const byte* module_end, bool asm_js = false); 328 const byte* module_end, bool asm_js = false);
319 329
320 // For testing. Decode, verify, and run the last exported function in the 330 // For testing. Decode, verify, and run the last exported function in the
321 // given decoded module. 331 // given decoded module.
322 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module); 332 int32_t CompileAndRunWasmModule(Isolate* isolate, WasmModule* module);
323 333
334 // Extract a function name from the given wasm object.
335 // Returns undefined if the function is unnamed or the function index is
336 // invalid.
337 Handle<Object> GetWasmFunctionName(Handle<JSObject> wasm, uint32_t func_index);
338
324 } // namespace wasm 339 } // namespace wasm
325 } // namespace internal 340 } // namespace internal
326 } // namespace v8 341 } // namespace v8
327 342
328 #endif // V8_WASM_MODULE_H_ 343 #endif // V8_WASM_MODULE_H_
OLDNEW
« no previous file with comments | « src/wasm/wasm-function-name-table.cc ('k') | src/wasm/wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698