bytecode-flags.h 2.65 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 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.

#ifndef V8_INTERPRETER_BYTECODE_FLAGS_H_
#define V8_INTERPRETER_BYTECODE_FLAGS_H_

8 9
#include "src/base/bit-field.h"
#include "src/common/globals.h"
10 11 12

namespace v8 {
namespace internal {
13 14 15 16 17

// Forward declarations.
class Literal;
class AstStringConstants;

18 19
namespace interpreter {

20 21
class CreateArrayLiteralFlags {
 public:
22
  using FlagsBits = base::BitField8<int, 0, 5>;
23
  using FastCloneSupportedBit = FlagsBits::Next<bool, 1>;
24 25 26 27 28 29 30

  static uint8_t Encode(bool use_fast_shallow_clone, int runtime_flags);

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(CreateArrayLiteralFlags);
};

31 32
class CreateObjectLiteralFlags {
 public:
33
  using FlagsBits = base::BitField8<int, 0, 5>;
34
  using FastCloneSupportedBit = FlagsBits::Next<bool, 1>;
35

36
  static uint8_t Encode(int runtime_flags, bool fast_clone_supported);
37 38 39 40 41 42 43

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(CreateObjectLiteralFlags);
};

class CreateClosureFlags {
 public:
44
  using PretenuredBit = base::BitField8<bool, 0, 1>;
45
  using FastNewClosureBit = PretenuredBit::Next<bool, 1>;
46

47 48
  static uint8_t Encode(bool pretenure, bool is_function_scope,
                        bool might_always_opt);
49 50 51 52 53

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(CreateClosureFlags);
};

54 55 56 57 58
#define TYPEOF_LITERAL_LIST(V) \
  V(Number, number)            \
  V(String, string)            \
  V(Symbol, symbol)            \
  V(Boolean, boolean)          \
Georg Neis's avatar
Georg Neis committed
59
  V(BigInt, bigint)            \
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  V(Undefined, undefined)      \
  V(Function, function)        \
  V(Object, object)            \
  V(Other, other)

class TestTypeOfFlags {
 public:
  enum class LiteralFlag : uint8_t {
#define DECLARE_LITERAL_FLAG(name, _) k##name,
    TYPEOF_LITERAL_LIST(DECLARE_LITERAL_FLAG)
#undef DECLARE_LITERAL_FLAG
  };

  static LiteralFlag GetFlagForLiteral(const AstStringConstants* ast_constants,
                                       Literal* literal);
  static uint8_t Encode(LiteralFlag literal_flag);
  static LiteralFlag Decode(uint8_t raw_flag);

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(TestTypeOfFlags);
};

82 83
class StoreLookupSlotFlags {
 public:
84
  using LanguageModeBit = base::BitField8<LanguageMode, 0, 1>;
85
  using LookupHoistingModeBit = LanguageModeBit::Next<bool, 1>;
86
  STATIC_ASSERT(LanguageModeSize <= LanguageModeBit::kNumValues);
87 88 89 90 91 92 93 94

  static uint8_t Encode(LanguageMode language_mode,
                        LookupHoistingMode lookup_hoisting_mode);

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(StoreLookupSlotFlags);
};

95 96 97 98 99
}  // namespace interpreter
}  // namespace internal
}  // namespace v8

#endif  // V8_INTERPRETER_BYTECODE_FLAGS_H_