| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "src/api.h" | 10 #include "src/api.h" |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 const WasmFunction* function_; | 346 const WasmFunction* function_; |
| 347 const WasmModule* module_; | 347 const WasmModule* module_; |
| 348 WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv) | 348 WasmFunctionName(const WasmFunction* function, const ModuleEnv* menv) |
| 349 : function_(function), module_(menv ? menv->module : nullptr) {} | 349 : function_(function), module_(menv ? menv->module : nullptr) {} |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 std::ostream& operator<<(std::ostream& os, const WasmModule& module); | 352 std::ostream& operator<<(std::ostream& os, const WasmModule& module); |
| 353 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); | 353 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); |
| 354 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); | 354 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); |
| 355 | 355 |
| 356 // Extract a function name from the given wasm object. | 356 // Extract a function name from the given wasm instance. |
| 357 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 357 // Returns "<WASM UNNAMED>" if no instance is passed, the function is unnamed or |
| 358 // valid UTF-8 string. | 358 // the name is not a valid UTF-8 string. |
| 359 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 359 // TODO(5620): Refactor once we always get a wasm instance. |
| 360 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> instance, |
| 360 uint32_t func_index); | 361 uint32_t func_index); |
| 361 | 362 |
| 362 // Extract a function name from the given wasm object. | |
| 363 // Returns a null handle if the function is unnamed or the name is not a valid | |
| 364 // UTF-8 string. | |
| 365 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | |
| 366 uint32_t func_index); | |
| 367 | |
| 368 // Return the binary source bytes of a wasm module. | 363 // Return the binary source bytes of a wasm module. |
| 369 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); | 364 Handle<SeqOneByteString> GetWasmBytes(Handle<JSObject> wasm); |
| 370 | 365 |
| 371 // Get the debug info associated with the given wasm object. | 366 // Get the debug info associated with the given wasm object. |
| 372 // If no debug info exists yet, it is created automatically. | 367 // If no debug info exists yet, it is created automatically. |
| 373 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); | 368 Handle<WasmDebugInfo> GetDebugInfo(Handle<JSObject> wasm); |
| 374 | 369 |
| 375 // Return the number of functions in the given wasm object. | 370 // Return the number of functions in the given wasm object. |
| 376 int GetNumberOfFunctions(Handle<JSObject> wasm); | 371 int GetNumberOfFunctions(Handle<JSObject> wasm); |
| 377 | 372 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 388 // special marker as internal field, which will definitely never occur anywhere | 383 // special marker as internal field, which will definitely never occur anywhere |
| 389 // else. | 384 // else. |
| 390 bool IsWasmInstance(Object* instance); | 385 bool IsWasmInstance(Object* instance); |
| 391 | 386 |
| 392 // Return the compiled module object for this WASM instance. | 387 // Return the compiled module object for this WASM instance. |
| 393 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); | 388 WasmCompiledModule* GetCompiledModule(Object* wasm_instance); |
| 394 | 389 |
| 395 // Check whether the wasm module was generated from asm.js code. | 390 // Check whether the wasm module was generated from asm.js code. |
| 396 bool WasmIsAsmJs(Object* instance, Isolate* isolate); | 391 bool WasmIsAsmJs(Object* instance, Isolate* isolate); |
| 397 | 392 |
| 398 // Get the script for the asm.js origin of the wasm module. | 393 // Get the script of the wasm module. If the origin of the module is asm.js, the |
| 399 Handle<Script> GetAsmWasmScript(Handle<JSObject> instance); | 394 // returned Script will be a JavaScript Script of Script::TYPE_NORMAL, otherwise |
| 395 // it's of type TYPE_WASM. |
| 396 Handle<Script> GetScript(Handle<JSObject> instance); |
| 400 | 397 |
| 401 // Get the asm.js source position for the given byte offset in the given | 398 // Get the asm.js source position for the given byte offset in the given |
| 402 // function. | 399 // function. |
| 403 int GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, | 400 int GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
| 404 int byte_offset); | 401 int byte_offset); |
| 405 | 402 |
| 406 V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes( | 403 V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes( |
| 407 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, | 404 Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower, |
| 408 ModuleOrigin origin, Handle<Script> asm_js_script, | 405 ModuleOrigin origin, Handle<Script> asm_js_script, |
| 409 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); | 406 const byte* asm_offset_tables_start, const byte* asm_offset_tables_end); |
| 410 | 407 |
| 411 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, | 408 V8_EXPORT_PRIVATE bool ValidateModuleBytes(Isolate* isolate, const byte* start, |
| 412 const byte* end, | 409 const byte* end, |
| 413 ErrorThrower* thrower, | 410 ErrorThrower* thrower, |
| 414 ModuleOrigin origin); | 411 ModuleOrigin origin); |
| 415 | 412 |
| 416 // Get the number of imported functions for a WASM instance. | 413 // Get the offset of the code of a function within a module. |
| 417 int GetNumImportedFunctions(Handle<JSObject> instance); | 414 int GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, |
| 415 int func_index); |
| 416 |
| 417 // Translate from byte offset in the module to function number and byte offset |
| 418 // within that function, encoded as line and column in the position info. |
| 419 bool GetPositionInfo(Handle<WasmCompiledModule> compiled_module, |
| 420 uint32_t position, Script::PositionInfo* info); |
| 418 | 421 |
| 419 // Assumed to be called with a code object associated to a wasm module instance. | 422 // Assumed to be called with a code object associated to a wasm module instance. |
| 420 // Intended to be called from runtime functions. | 423 // Intended to be called from runtime functions. |
| 421 // Returns nullptr on failing to get owning instance. | 424 // Returns nullptr on failing to get owning instance. |
| 422 Object* GetOwningWasmInstance(Code* code); | 425 Object* GetOwningWasmInstance(Code* code); |
| 423 | 426 |
| 424 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, | 427 MaybeHandle<JSArrayBuffer> GetInstanceMemory(Isolate* isolate, |
| 425 Handle<JSObject> instance); | 428 Handle<JSObject> instance); |
| 426 | 429 |
| 427 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); | 430 int32_t GetInstanceMemorySize(Isolate* isolate, Handle<JSObject> instance); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 438 int instance_count); | 441 int instance_count); |
| 439 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); | 442 void ValidateModuleState(Isolate* isolate, Handle<JSObject> wasm_module); |
| 440 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); | 443 void ValidateOrphanedInstance(Isolate* isolate, Handle<JSObject> instance); |
| 441 | 444 |
| 442 } // namespace testing | 445 } // namespace testing |
| 443 } // namespace wasm | 446 } // namespace wasm |
| 444 } // namespace internal | 447 } // namespace internal |
| 445 } // namespace v8 | 448 } // namespace v8 |
| 446 | 449 |
| 447 #endif // V8_WASM_MODULE_H_ | 450 #endif // V8_WASM_MODULE_H_ |
| OLD | NEW |