• 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/macros.h"
10 #include "src/wasm/wasm-feature-flags.h"
11 
12 // All features, including features that do not have flags.
13 #define FOREACH_WASM_FEATURE FOREACH_WASM_FEATURE_FLAG
14 
15 namespace v8 {
16 namespace internal {
17 class Isolate;
18 namespace wasm {
19 
20 #define COMMA ,
21 #define SPACE
22 #define DECL_FIELD(feat, desc, val) bool feat = false;
23 #define JUST_TRUE(feat, desc, val) true
24 #define JUST_FALSE(feat, desc, val) false
25 #define DECL_PARAM(feat, desc, val) bool p##feat
26 #define DO_INIT(feat, desc, val) feat(p##feat)
27 
28 // Enabled or detected features.
29 struct WasmFeatures {
30   FOREACH_WASM_FEATURE(DECL_FIELD, SPACE)
31 
32   constexpr WasmFeatures() = default;
33 
WasmFeaturesWasmFeatures34   explicit constexpr WasmFeatures(FOREACH_WASM_FEATURE(DECL_PARAM, COMMA))
35       : FOREACH_WASM_FEATURE(DO_INIT, COMMA) {}
36 };
37 
38 static constexpr WasmFeatures kAllWasmFeatures{
39     FOREACH_WASM_FEATURE(JUST_TRUE, COMMA)};
40 
41 static constexpr WasmFeatures kNoWasmFeatures{
42     FOREACH_WASM_FEATURE(JUST_FALSE, COMMA)};
43 
44 #undef JUST_TRUE
45 #undef JUST_FALSE
46 #undef DECL_FIELD
47 #undef DECL_PARAM
48 #undef DO_INIT
49 #undef COMMA
50 #undef SPACE
51 
52 static constexpr WasmFeatures kAsmjsWasmFeatures = kNoWasmFeatures;
53 
54 V8_EXPORT_PRIVATE WasmFeatures WasmFeaturesFromFlags();
55 
56 // Enables features based on both commandline flags and the isolate.
57 // Precondition: A valid context must be set in {isolate->context()}.
58 V8_EXPORT_PRIVATE WasmFeatures WasmFeaturesFromIsolate(Isolate* isolate);
59 
60 V8_EXPORT_PRIVATE void UnionFeaturesInto(WasmFeatures* dst,
61                                          const WasmFeatures& src);
62 
63 }  // namespace wasm
64 }  // namespace internal
65 }  // namespace v8
66 
67 #endif  // V8_WASM_WASM_FEATURES_H_
68