Line data Source code
1 : // Copyright 2016 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 : #include "src/interpreter/bytecode-flags.h"
6 :
7 : #include "src/ast/ast-value-factory.h"
8 : #include "src/ast/ast.h"
9 : #include "src/builtins/builtins-constructor.h"
10 : #include "src/code-stubs.h"
11 : #include "src/objects-inl.h"
12 :
13 : namespace v8 {
14 : namespace internal {
15 : namespace interpreter {
16 :
17 : // static
18 151462 : uint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
19 : int runtime_flags) {
20 : uint8_t result = FlagsBits::encode(runtime_flags);
21 151462 : result |= FastShallowCloneBit::encode(use_fast_shallow_clone);
22 151462 : return result;
23 : }
24 :
25 : // static
26 346962 : uint8_t CreateObjectLiteralFlags::Encode(bool fast_clone_supported,
27 : int properties_count,
28 : int runtime_flags) {
29 : uint8_t result = FlagsBits::encode(runtime_flags);
30 346962 : if (fast_clone_supported) {
31 : STATIC_ASSERT(
32 : ConstructorBuiltins::kMaximumClonedShallowObjectProperties <=
33 : 1 << CreateObjectLiteralFlags::FastClonePropertiesCountBits::kShift);
34 : DCHECK_LE(properties_count,
35 : ConstructorBuiltins::kMaximumClonedShallowObjectProperties);
36 : result |= CreateObjectLiteralFlags::FastClonePropertiesCountBits::encode(
37 104511 : properties_count);
38 : }
39 346962 : return result;
40 : }
41 :
42 : // static
43 3434432 : uint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope) {
44 : uint8_t result = PretenuredBit::encode(pretenure);
45 3434432 : if (!FLAG_always_opt && !FLAG_prepare_always_opt &&
46 1917253 : pretenure == NOT_TENURED && is_function_scope) {
47 889182 : result |= FastNewClosureBit::encode(true);
48 : }
49 3434432 : return result;
50 : }
51 :
52 : // static
53 161052 : TestTypeOfFlags::LiteralFlag TestTypeOfFlags::GetFlagForLiteral(
54 882621 : const AstStringConstants* ast_constants, Literal* literal) {
55 161052 : const AstRawString* raw_literal = literal->raw_value()->AsString();
56 161052 : if (raw_literal == ast_constants->number_string()) {
57 : return LiteralFlag::kNumber;
58 126699 : } else if (raw_literal == ast_constants->string_string()) {
59 : return LiteralFlag::kString;
60 109623 : } else if (raw_literal == ast_constants->symbol_string()) {
61 : return LiteralFlag::kSymbol;
62 104932 : } else if (raw_literal == ast_constants->boolean_string()) {
63 : return LiteralFlag::kBoolean;
64 102163 : } else if (raw_literal == ast_constants->undefined_string()) {
65 : return LiteralFlag::kUndefined;
66 95999 : } else if (raw_literal == ast_constants->function_string()) {
67 : return LiteralFlag::kFunction;
68 21101 : } else if (raw_literal == ast_constants->object_string()) {
69 : return LiteralFlag::kObject;
70 : } else {
71 184 : return LiteralFlag::kOther;
72 : }
73 : }
74 :
75 : // static
76 160918 : uint8_t TestTypeOfFlags::Encode(LiteralFlag literal_flag) {
77 160918 : return static_cast<uint8_t>(literal_flag);
78 : }
79 :
80 : // static
81 59510 : TestTypeOfFlags::LiteralFlag TestTypeOfFlags::Decode(uint8_t raw_flag) {
82 : DCHECK_LE(raw_flag, static_cast<uint8_t>(LiteralFlag::kOther));
83 59510 : return static_cast<LiteralFlag>(raw_flag);
84 : }
85 :
86 : // static
87 19834 : uint8_t SuspendGeneratorBytecodeFlags::Encode(SuspendFlags flags) {
88 19834 : return FlagsBits::encode(flags);
89 : }
90 :
91 : // static
92 6707 : SuspendFlags SuspendGeneratorBytecodeFlags::Decode(uint8_t flags) {
93 6707 : return FlagsBits::decode(flags);
94 : }
95 :
96 : } // namespace interpreter
97 : } // namespace internal
98 : } // namespace v8
|