• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WASM_FEATURES_H_
6 #define V8_WASM_WASM_FEATURES_H_
7 
8 // The feature flags are declared in their own header.
9 #include "src/base/enum-set.h"
10 #include "src/base/macros.h"
11 #include "src/wasm/wasm-feature-flags.h"
12 
13 // All features, including features that do not have flags.
14 #define FOREACH_WASM_FEATURE FOREACH_WASM_FEATURE_FLAG
15 
16 namespace v8 {
17 namespace internal {
18 
19 class Isolate;
20 
21 namespace wasm {
22 
23 enum WasmFeature {
24 #define DECL_FEATURE_ENUM(feat, ...) kFeature_##feat,
25   FOREACH_WASM_FEATURE(DECL_FEATURE_ENUM)
26 #undef DECL_FEATURE_ENUM
27 };
28 
29 // Enabled or detected features.
30 class WasmFeatures : public base::EnumSet<WasmFeature> {
31  public:
32   constexpr WasmFeatures() = default;
WasmFeatures(std::initializer_list<WasmFeature> features)33   explicit constexpr WasmFeatures(std::initializer_list<WasmFeature> features)
34       : EnumSet(features) {}
35 
36   // Simplified getters. Use {has_foo()} instead of {contains(kFeature_foo)}.
37 #define DECL_FEATURE_GETTER(feat, ...) \
38   bool has_##feat() const { return contains(kFeature_##feat); }
FOREACH_WASM_FEATURE(DECL_FEATURE_GETTER)39   FOREACH_WASM_FEATURE(DECL_FEATURE_GETTER)
40 #undef DECL_FEATURE_GETTER
41 
42   static constexpr const char* name_for_feature(WasmFeature feature) {
43     switch (feature) {
44 #define NAME(feat, ...)              \
45   case WasmFeature::kFeature_##feat: \
46     return #feat;
47       FOREACH_WASM_FEATURE(NAME)
48     }
49 #undef NAME
50   }
51   static inline constexpr WasmFeatures All();
52   static inline constexpr WasmFeatures None();
53   static inline constexpr WasmFeatures ForAsmjs();
54   static WasmFeatures FromFlags();
55   static V8_EXPORT_PRIVATE WasmFeatures FromIsolate(Isolate*);
56 };
57 
58 // static
All()59 constexpr WasmFeatures WasmFeatures::All() {
60 #define LIST_FEATURE(feat, ...) kFeature_##feat,
61   return WasmFeatures({FOREACH_WASM_FEATURE(LIST_FEATURE)});
62 #undef LIST_FEATURE
63 }
64 
65 // static
None()66 constexpr WasmFeatures WasmFeatures::None() { return {}; }
67 
68 // static
ForAsmjs()69 constexpr WasmFeatures WasmFeatures::ForAsmjs() { return {}; }
70 
71 }  // namespace wasm
72 }  // namespace internal
73 }  // namespace v8
74 
75 #endif  // V8_WASM_WASM_FEATURES_H_
76