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/api.h" | 8 #include "src/api.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/wasm/wasm-opcodes.h" | 10 #include "src/wasm/wasm-opcodes.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 | 328 |
329 std::ostream& operator<<(std::ostream& os, const WasmModule& module); | 329 std::ostream& operator<<(std::ostream& os, const WasmModule& module); |
330 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); | 330 std::ostream& operator<<(std::ostream& os, const WasmFunction& function); |
331 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); | 331 std::ostream& operator<<(std::ostream& os, const WasmFunctionName& name); |
332 | 332 |
333 typedef Result<const WasmModule*> ModuleResult; | 333 typedef Result<const WasmModule*> ModuleResult; |
334 typedef Result<WasmFunction*> FunctionResult; | 334 typedef Result<WasmFunction*> FunctionResult; |
335 typedef std::vector<std::pair<int, int>> FunctionOffsets; | 335 typedef std::vector<std::pair<int, int>> FunctionOffsets; |
336 typedef Result<FunctionOffsets> FunctionOffsetsResult; | 336 typedef Result<FunctionOffsets> FunctionOffsetsResult; |
337 | 337 |
338 // For testing. Decode, verify, and run the last exported function in the | |
339 // given encoded module. | |
340 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | |
341 const byte* module_end, bool asm_js = false); | |
342 | |
343 // For testing. Decode, verify, and run the last exported function in the | |
344 // given decoded module. | |
345 int32_t CompileAndRunWasmModule(Isolate* isolate, const WasmModule* module); | |
346 | |
347 // Extract a function name from the given wasm object. | 338 // Extract a function name from the given wasm object. |
348 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a | 339 // Returns "<WASM UNNAMED>" if the function is unnamed or the name is not a |
349 // valid UTF-8 string. | 340 // valid UTF-8 string. |
350 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 341 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, |
351 uint32_t func_index); | 342 uint32_t func_index); |
352 | 343 |
353 // Extract a function name from the given wasm object. | 344 // Extract a function name from the given wasm object. |
354 // Returns a null handle if the function is unnamed or the name is not a valid | 345 // Returns a null handle if the function is unnamed or the name is not a valid |
355 // UTF-8 string. | 346 // UTF-8 string. |
356 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | 347 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, |
357 uint32_t func_index); | 348 uint32_t func_index); |
358 | 349 |
359 // Return the binary source bytes of a wasm module. | 350 // Return the binary source bytes of a wasm module. |
360 SeqOneByteString* GetWasmBytes(JSObject* wasm); | 351 SeqOneByteString* GetWasmBytes(JSObject* wasm); |
361 | 352 |
362 // Get the debug info associated with the given wasm object. | 353 // Get the debug info associated with the given wasm object. |
363 // If no debug info exists yet, it is created automatically. | 354 // If no debug info exists yet, it is created automatically. |
364 WasmDebugInfo* GetDebugInfo(JSObject* wasm); | 355 WasmDebugInfo* GetDebugInfo(JSObject* wasm); |
365 | 356 |
366 // Check whether the given object is a wasm object. | 357 // Check whether the given object is a wasm object. |
367 // This checks the number and type of internal fields, so it's not 100 percent | 358 // This checks the number and type of internal fields, so it's not 100 percent |
368 // secure. If it turns out that we need more complete checks, we could add a | 359 // secure. If it turns out that we need more complete checks, we could add a |
369 // special marker as internal field, which will definitely never occur anywhere | 360 // special marker as internal field, which will definitely never occur anywhere |
370 // else. | 361 // else. |
371 bool IsWasmObject(Object* object); | 362 bool IsWasmObject(Object* object); |
372 | 363 |
| 364 namespace testing { |
| 365 |
| 366 // Decode, verify, and run the function labeled "main" in the |
| 367 // given encoded module. The module should have no imports. |
| 368 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
| 369 const byte* module_end, bool asm_js = false); |
| 370 |
| 371 } // namespace testing |
| 372 |
373 } // namespace wasm | 373 } // namespace wasm |
374 } // namespace internal | 374 } // namespace internal |
375 } // namespace v8 | 375 } // namespace v8 |
376 | 376 |
377 #endif // V8_WASM_MODULE_H_ | 377 #endif // V8_WASM_MODULE_H_ |
OLD | NEW |