bytecode-flags.cc 3.06 KB
Newer Older
1 2 3 4 5 6
// 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.

#include "src/interpreter/bytecode-flags.h"

7 8
#include "src/ast/ast-value-factory.h"
#include "src/ast/ast.h"
9
#include "src/builtins/builtins-constructor.h"
10
#include "src/objects/objects-inl.h"
11 12 13 14 15

namespace v8 {
namespace internal {
namespace interpreter {

16 17 18 19
// static
uint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
                                        int runtime_flags) {
  uint8_t result = FlagsBits::encode(runtime_flags);
20
  result |= FastCloneSupportedBit::encode(use_fast_shallow_clone);
21 22 23
  return result;
}

24
// static
25 26
uint8_t CreateObjectLiteralFlags::Encode(int runtime_flags,
                                         bool fast_clone_supported) {
27
  uint8_t result = FlagsBits::encode(runtime_flags);
28
  result |= FastCloneSupportedBit::encode(fast_clone_supported);
29 30 31 32
  return result;
}

// static
33 34
uint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope,
                                   bool might_always_opt) {
35
  uint8_t result = PretenuredBit::encode(pretenure);
36
  if (!might_always_opt && !pretenure && is_function_scope) {
37 38 39 40 41
    result |= FastNewClosureBit::encode(true);
  }
  return result;
}

42 43 44
// static
TestTypeOfFlags::LiteralFlag TestTypeOfFlags::GetFlagForLiteral(
    const AstStringConstants* ast_constants, Literal* literal) {
45
  const AstRawString* raw_literal = literal->AsRawString();
46 47 48 49 50 51 52 53
  if (raw_literal == ast_constants->number_string()) {
    return LiteralFlag::kNumber;
  } else if (raw_literal == ast_constants->string_string()) {
    return LiteralFlag::kString;
  } else if (raw_literal == ast_constants->symbol_string()) {
    return LiteralFlag::kSymbol;
  } else if (raw_literal == ast_constants->boolean_string()) {
    return LiteralFlag::kBoolean;
Georg Neis's avatar
Georg Neis committed
54 55
  } else if (raw_literal == ast_constants->bigint_string()) {
    return LiteralFlag::kBigInt;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
  } else if (raw_literal == ast_constants->undefined_string()) {
    return LiteralFlag::kUndefined;
  } else if (raw_literal == ast_constants->function_string()) {
    return LiteralFlag::kFunction;
  } else if (raw_literal == ast_constants->object_string()) {
    return LiteralFlag::kObject;
  } else {
    return LiteralFlag::kOther;
  }
}

// static
uint8_t TestTypeOfFlags::Encode(LiteralFlag literal_flag) {
  return static_cast<uint8_t>(literal_flag);
}

// static
TestTypeOfFlags::LiteralFlag TestTypeOfFlags::Decode(uint8_t raw_flag) {
  DCHECK_LE(raw_flag, static_cast<uint8_t>(LiteralFlag::kOther));
  return static_cast<LiteralFlag>(raw_flag);
}

78 79 80 81
// static
uint8_t StoreLookupSlotFlags::Encode(LanguageMode language_mode,
                                     LookupHoistingMode lookup_hoisting_mode) {
  DCHECK_IMPLIES(lookup_hoisting_mode == LookupHoistingMode::kLegacySloppy,
82
                 language_mode == LanguageMode::kSloppy);
83 84 85 86
  return LanguageModeBit::encode(language_mode) |
         LookupHoistingModeBit::encode(static_cast<bool>(lookup_hoisting_mode));
}

87 88 89
}  // namespace interpreter
}  // namespace internal
}  // namespace v8