11cb0ef41Sopenharmony_ci// Copyright 2016 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/interpreter/bytecode-flags.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include "src/ast/ast-value-factory.h"
81cb0ef41Sopenharmony_ci#include "src/ast/ast.h"
91cb0ef41Sopenharmony_ci#include "src/builtins/builtins-constructor.h"
101cb0ef41Sopenharmony_ci#include "src/objects/objects-inl.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cinamespace v8 {
131cb0ef41Sopenharmony_cinamespace internal {
141cb0ef41Sopenharmony_cinamespace interpreter {
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// static
171cb0ef41Sopenharmony_ciuint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
181cb0ef41Sopenharmony_ci                                        int runtime_flags) {
191cb0ef41Sopenharmony_ci  uint8_t result = FlagsBits::encode(runtime_flags);
201cb0ef41Sopenharmony_ci  result |= FastCloneSupportedBit::encode(use_fast_shallow_clone);
211cb0ef41Sopenharmony_ci  return result;
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// static
251cb0ef41Sopenharmony_ciuint8_t CreateObjectLiteralFlags::Encode(int runtime_flags,
261cb0ef41Sopenharmony_ci                                         bool fast_clone_supported) {
271cb0ef41Sopenharmony_ci  uint8_t result = FlagsBits::encode(runtime_flags);
281cb0ef41Sopenharmony_ci  result |= FastCloneSupportedBit::encode(fast_clone_supported);
291cb0ef41Sopenharmony_ci  return result;
301cb0ef41Sopenharmony_ci}
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci// static
331cb0ef41Sopenharmony_ciuint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope,
341cb0ef41Sopenharmony_ci                                   bool might_always_opt) {
351cb0ef41Sopenharmony_ci  uint8_t result = PretenuredBit::encode(pretenure);
361cb0ef41Sopenharmony_ci  if (!might_always_opt && !pretenure && is_function_scope) {
371cb0ef41Sopenharmony_ci    result |= FastNewClosureBit::encode(true);
381cb0ef41Sopenharmony_ci  }
391cb0ef41Sopenharmony_ci  return result;
401cb0ef41Sopenharmony_ci}
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ci// static
431cb0ef41Sopenharmony_ciTestTypeOfFlags::LiteralFlag TestTypeOfFlags::GetFlagForLiteral(
441cb0ef41Sopenharmony_ci    const AstStringConstants* ast_constants, Literal* literal) {
451cb0ef41Sopenharmony_ci  const AstRawString* raw_literal = literal->AsRawString();
461cb0ef41Sopenharmony_ci  if (raw_literal == ast_constants->number_string()) {
471cb0ef41Sopenharmony_ci    return LiteralFlag::kNumber;
481cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->string_string()) {
491cb0ef41Sopenharmony_ci    return LiteralFlag::kString;
501cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->symbol_string()) {
511cb0ef41Sopenharmony_ci    return LiteralFlag::kSymbol;
521cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->boolean_string()) {
531cb0ef41Sopenharmony_ci    return LiteralFlag::kBoolean;
541cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->bigint_string()) {
551cb0ef41Sopenharmony_ci    return LiteralFlag::kBigInt;
561cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->undefined_string()) {
571cb0ef41Sopenharmony_ci    return LiteralFlag::kUndefined;
581cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->function_string()) {
591cb0ef41Sopenharmony_ci    return LiteralFlag::kFunction;
601cb0ef41Sopenharmony_ci  } else if (raw_literal == ast_constants->object_string()) {
611cb0ef41Sopenharmony_ci    return LiteralFlag::kObject;
621cb0ef41Sopenharmony_ci  } else {
631cb0ef41Sopenharmony_ci    return LiteralFlag::kOther;
641cb0ef41Sopenharmony_ci  }
651cb0ef41Sopenharmony_ci}
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci// static
681cb0ef41Sopenharmony_ciuint8_t TestTypeOfFlags::Encode(LiteralFlag literal_flag) {
691cb0ef41Sopenharmony_ci  return static_cast<uint8_t>(literal_flag);
701cb0ef41Sopenharmony_ci}
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci// static
731cb0ef41Sopenharmony_ciTestTypeOfFlags::LiteralFlag TestTypeOfFlags::Decode(uint8_t raw_flag) {
741cb0ef41Sopenharmony_ci  DCHECK_LE(raw_flag, static_cast<uint8_t>(LiteralFlag::kOther));
751cb0ef41Sopenharmony_ci  return static_cast<LiteralFlag>(raw_flag);
761cb0ef41Sopenharmony_ci}
771cb0ef41Sopenharmony_ci
781cb0ef41Sopenharmony_ci// static
791cb0ef41Sopenharmony_ciuint8_t StoreLookupSlotFlags::Encode(LanguageMode language_mode,
801cb0ef41Sopenharmony_ci                                     LookupHoistingMode lookup_hoisting_mode) {
811cb0ef41Sopenharmony_ci  DCHECK_IMPLIES(lookup_hoisting_mode == LookupHoistingMode::kLegacySloppy,
821cb0ef41Sopenharmony_ci                 language_mode == LanguageMode::kSloppy);
831cb0ef41Sopenharmony_ci  return LanguageModeBit::encode(language_mode) |
841cb0ef41Sopenharmony_ci         LookupHoistingModeBit::encode(static_cast<bool>(lookup_hoisting_mode));
851cb0ef41Sopenharmony_ci}
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ci}  // namespace interpreter
881cb0ef41Sopenharmony_ci}  // namespace internal
891cb0ef41Sopenharmony_ci}  // namespace v8
90