wasm-features.cc 1.31 KB
Newer Older
1 2 3 4 5
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/wasm/wasm-features.h"
6
#include "src/execution/isolate.h"
7
#include "src/flags/flags.h"
8
#include "src/handles/handles-inl.h"
9 10 11 12 13

namespace v8 {
namespace internal {
namespace wasm {

14 15 16 17 18
// static
WasmFeatures WasmFeatures::FromFlags() {
  WasmFeatures features = WasmFeatures::None();
#define FLAG_REF(feat, ...) \
  if (FLAG_experimental_wasm_##feat) features.Add(kFeature_##feat);
19
  FOREACH_WASM_FEATURE_FLAG(FLAG_REF)
20
#undef FLAG_REF
21 22 23
#define NON_FLAG_REF(feat, ...) features.Add(kFeature_##feat);
  FOREACH_WASM_NON_FLAG_FEATURE(NON_FLAG_REF)
#undef NON_FLAG_REF
24
  return features;
25 26
}

27 28
// static
WasmFeatures WasmFeatures::FromIsolate(Isolate* isolate) {
29 30 31 32 33 34
  return FromContext(isolate, handle(isolate->context(), isolate));
}

// static
WasmFeatures WasmFeatures::FromContext(Isolate* isolate,
                                       Handle<Context> context) {
35
  WasmFeatures features = WasmFeatures::FromFlags();
36
  if (isolate->IsWasmSimdEnabled(context)) {
37 38
    features.Add(kFeature_simd);
  }
39
  if (isolate->AreWasmExceptionsEnabled(context)) {
40 41
    features.Add(kFeature_eh);
  }
42
  return features;
43 44 45 46 47
}

}  // namespace wasm
}  // namespace internal
}  // namespace v8