V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
compilation-environment.h
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_WASM_COMPILATION_ENVIRONMENT_H_
6 #define V8_WASM_COMPILATION_ENVIRONMENT_H_
7 
8 #include "src/wasm/wasm-limits.h"
9 #include "src/wasm/wasm-module.h"
10 
11 namespace v8 {
12 namespace internal {
13 namespace wasm {
14 
15 class NativeModule;
16 class ResultBase;
17 
18 enum RuntimeExceptionSupport : bool {
19  kRuntimeExceptionSupport = true,
20  kNoRuntimeExceptionSupport = false
21 };
22 
23 enum UseTrapHandler : bool { kUseTrapHandler = true, kNoTrapHandler = false };
24 
25 enum LowerSimd : bool { kLowerSimd = true, kNoLowerSimd = false };
26 
27 // The {CompilationEnv} encapsulates the module data that is used during
28 // compilation. CompilationEnvs are shareable across multiple compilations.
30  // A pointer to the decoded module's static representation.
31  const WasmModule* const module;
32 
33  // True if trap handling should be used in compiled code, rather than
34  // compiling in bounds checks for each memory access.
35  const UseTrapHandler use_trap_handler;
36 
37  // If the runtime doesn't support exception propagation,
38  // we won't generate stack checks, and trap handling will also
39  // be generated differently.
40  const RuntimeExceptionSupport runtime_exception_support;
41 
42  // The smallest size of any memory that could be used with this module, in
43  // bytes.
44  const uint64_t min_memory_size;
45 
46  // The largest size of any memory that could be used with this module, in
47  // bytes.
48  const uint64_t max_memory_size;
49 
50  const LowerSimd lower_simd;
51 
52  constexpr CompilationEnv(const WasmModule* module,
53  UseTrapHandler use_trap_handler,
54  RuntimeExceptionSupport runtime_exception_support,
55  LowerSimd lower_simd = kNoLowerSimd)
56  : module(module),
57  use_trap_handler(use_trap_handler),
58  runtime_exception_support(runtime_exception_support),
59  min_memory_size(module ? module->initial_pages * uint64_t{kWasmPageSize}
60  : 0),
61  max_memory_size((module && module->has_maximum_pages
62  ? module->maximum_pages
63  : kV8MaxWasmMemoryPages) *
64  uint64_t{kWasmPageSize}),
65  lower_simd(lower_simd) {}
66 };
67 
68 // The wire bytes are either owned by the StreamingDecoder, or (after streaming)
69 // by the NativeModule. This class abstracts over the storage location.
71  public:
72  virtual ~WireBytesStorage() = default;
73  virtual Vector<const uint8_t> GetCode(WireBytesRef) const = 0;
74 };
75 
76 // The implementation of {CompilationState} lives in module-compiler.cc.
77 // This is the PIMPL interface to that private class.
79  public:
81 
82  void CancelAndWait();
83 
84  void SetError(uint32_t func_index, const ResultBase& error_result);
85 
86  void SetWireBytesStorage(std::shared_ptr<WireBytesStorage>);
87 
88  std::shared_ptr<WireBytesStorage> GetWireBytesStorage();
89 
90  private:
91  friend class NativeModule;
92  CompilationState() = delete;
93 
94  static std::unique_ptr<CompilationState> New(Isolate*, NativeModule*);
95 };
96 
97 } // namespace wasm
98 } // namespace internal
99 } // namespace v8
100 
101 #endif // V8_WASM_COMPILATION_ENVIRONMENT_H_
Definition: libplatform.h:13