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 151119 : uint8_t CreateArrayLiteralFlags::Encode(bool use_fast_shallow_clone,
19 : int runtime_flags) {
20 : uint8_t result = FlagsBits::encode(runtime_flags);
21 151119 : result |= FastShallowCloneBit::encode(use_fast_shallow_clone);
22 151119 : return result;
23 : }
24 :
25 : // static
26 346528 : 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 346528 : 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 104372 : properties_count);
38 : }
39 346528 : return result;
40 : }
41 :
42 : // static
43 3431460 : uint8_t CreateClosureFlags::Encode(bool pretenure, bool is_function_scope) {
44 : uint8_t result = PretenuredBit::encode(pretenure);
45 3431460 : if (!FLAG_always_opt && !FLAG_prepare_always_opt &&
46 1915059 : pretenure == NOT_TENURED && is_function_scope) {
47 888212 : result |= FastNewClosureBit::encode(true);
48 : }
49 3431460 : return result;
50 : }
51 :
52 : // static
53 160799 : TestTypeOfFlags::LiteralFlag TestTypeOfFlags::GetFlagForLiteral(
54 881148 : const AstStringConstants* ast_constants, Literal* literal) {
55 160799 : const AstRawString* raw_literal = literal->raw_value()->AsString();
56 160799 : if (raw_literal == ast_constants->number_string()) {
57 : return LiteralFlag::kNumber;
58 126489 : } else if (raw_literal == ast_constants->string_string()) {
59 : return LiteralFlag::kString;
60 109431 : } else if (raw_literal == ast_constants->symbol_string()) {
61 : return LiteralFlag::kSymbol;
62 104748 : } else if (raw_literal == ast_constants->boolean_string()) {
63 : return LiteralFlag::kBoolean;
64 101983 : } else if (raw_literal == ast_constants->undefined_string()) {
65 : return LiteralFlag::kUndefined;
66 95823 : } else if (raw_literal == ast_constants->function_string()) {
67 : return LiteralFlag::kFunction;
68 21076 : } 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 160665 : uint8_t TestTypeOfFlags::Encode(LiteralFlag literal_flag) {
77 160665 : return static_cast<uint8_t>(literal_flag);
78 : }
79 :
80 : // static
81 59584 : TestTypeOfFlags::LiteralFlag TestTypeOfFlags::Decode(uint8_t raw_flag) {
82 : DCHECK_LE(raw_flag, static_cast<uint8_t>(LiteralFlag::kOther));
83 59584 : 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 6825 : SuspendFlags SuspendGeneratorBytecodeFlags::Decode(uint8_t flags) {
93 6825 : return FlagsBits::decode(flags);
94 : }
95 :
96 : } // namespace interpreter
97 : } // namespace internal
98 : } // namespace v8
|