LCOV - code coverage report
Current view: top level - src/wasm - compilation-environment.h (source / functions) Hit Total Coverage
Test: app.info Lines: 6 6 100.0 %
Date: 2019-01-20 Functions: 0 2 0.0 %

          Line data    Source code
       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-features.h"
       9             : #include "src/wasm/wasm-limits.h"
      10             : #include "src/wasm/wasm-module.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : namespace wasm {
      15             : 
      16             : class NativeModule;
      17             : class WasmError;
      18             : 
      19             : enum RuntimeExceptionSupport : bool {
      20             :   kRuntimeExceptionSupport = true,
      21             :   kNoRuntimeExceptionSupport = false
      22             : };
      23             : 
      24             : enum UseTrapHandler : bool { kUseTrapHandler = true, kNoTrapHandler = false };
      25             : 
      26             : enum LowerSimd : bool { kLowerSimd = true, kNoLowerSimd = false };
      27             : 
      28             : // The {CompilationEnv} encapsulates the module data that is used during
      29             : // compilation. CompilationEnvs are shareable across multiple compilations.
      30             : struct CompilationEnv {
      31             :   // A pointer to the decoded module's static representation.
      32             :   const WasmModule* const module;
      33             : 
      34             :   // True if trap handling should be used in compiled code, rather than
      35             :   // compiling in bounds checks for each memory access.
      36             :   const UseTrapHandler use_trap_handler;
      37             : 
      38             :   // If the runtime doesn't support exception propagation,
      39             :   // we won't generate stack checks, and trap handling will also
      40             :   // be generated differently.
      41             :   const RuntimeExceptionSupport runtime_exception_support;
      42             : 
      43             :   // The smallest size of any memory that could be used with this module, in
      44             :   // bytes.
      45             :   const uint64_t min_memory_size;
      46             : 
      47             :   // The largest size of any memory that could be used with this module, in
      48             :   // bytes.
      49             :   const uint64_t max_memory_size;
      50             : 
      51             :   // Features enabled for this compilation.
      52             :   const WasmFeatures enabled_features;
      53             : 
      54             :   const LowerSimd lower_simd;
      55             : 
      56             :   constexpr CompilationEnv(const WasmModule* module,
      57             :                            UseTrapHandler use_trap_handler,
      58             :                            RuntimeExceptionSupport runtime_exception_support,
      59             :                            const WasmFeatures& enabled_features,
      60             :                            LowerSimd lower_simd = kNoLowerSimd)
      61             :       : module(module),
      62             :         use_trap_handler(use_trap_handler),
      63             :         runtime_exception_support(runtime_exception_support),
      64     1566063 :         min_memory_size(module ? module->initial_pages * uint64_t{kWasmPageSize}
      65             :                                : 0),
      66     1566069 :         max_memory_size((module && module->has_maximum_pages
      67             :                              ? module->maximum_pages
      68     1574078 :                              : kV8MaxWasmMemoryPages) *
      69             :                         uint64_t{kWasmPageSize}),
      70             :         enabled_features(enabled_features),
      71     4698157 :         lower_simd(lower_simd) {}
      72             : };
      73             : 
      74             : // The wire bytes are either owned by the StreamingDecoder, or (after streaming)
      75             : // by the NativeModule. This class abstracts over the storage location.
      76     2902021 : class WireBytesStorage {
      77             :  public:
      78     2902021 :   virtual ~WireBytesStorage() = default;
      79             :   virtual Vector<const uint8_t> GetCode(WireBytesRef) const = 0;
      80             : };
      81             : 
      82             : // Callbacks will receive either {kFailedCompilation} or both
      83             : // {kFinishedBaselineCompilation} and {kFinishedTopTierCompilation}, in that
      84             : // order. If tier up is off, both events are delivered right after each other.
      85             : enum class CompilationEvent : uint8_t {
      86             :   kFinishedBaselineCompilation,
      87             :   kFinishedTopTierCompilation,
      88             :   kFailedCompilation,
      89             : 
      90             :   // Marker:
      91             :   // After an event >= kFirstFinalEvent, no further events are generated.
      92             :   kFirstFinalEvent = kFinishedTopTierCompilation
      93             : };
      94             : 
      95             : // The implementation of {CompilationState} lives in module-compiler.cc.
      96             : // This is the PIMPL interface to that private class.
      97             : class CompilationState {
      98             :  public:
      99             :   using callback_t = std::function<void(CompilationEvent, const WasmError*)>;
     100             :   ~CompilationState();
     101             : 
     102             :   void CancelAndWait();
     103             : 
     104             :   void SetError(uint32_t func_index, const WasmError& error);
     105             : 
     106             :   void SetWireBytesStorage(std::shared_ptr<WireBytesStorage>);
     107             : 
     108             :   std::shared_ptr<WireBytesStorage> GetWireBytesStorage() const;
     109             : 
     110             :   void AddCallback(callback_t);
     111             : 
     112             :   bool failed() const;
     113             : 
     114             :  private:
     115             :   friend class NativeModule;
     116             :   CompilationState() = delete;
     117             : 
     118             :   static std::unique_ptr<CompilationState> New(Isolate*, NativeModule*);
     119             : };
     120             : 
     121             : }  // namespace wasm
     122             : }  // namespace internal
     123             : }  // namespace v8
     124             : 
     125             : #endif  // V8_WASM_COMPILATION_ENVIRONMENT_H_

Generated by: LCOV version 1.10