v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
builtins-string-gen.h
Go to the documentation of this file.
1// Copyright 2017 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#ifndef V8_BUILTINS_BUILTINS_STRING_GEN_H_
6#define V8_BUILTINS_BUILTINS_STRING_GEN_H_
7
10
11namespace v8 {
12namespace internal {
13
15 public:
18
19 // ES#sec-getsubstitution
21 TNode<String> subject_string,
22 TNode<Smi> match_start_index,
23 TNode<Smi> match_end_index,
24 TNode<String> replace_string);
25 void StringEqual_Core(TNode<String> lhs, TNode<Word32T> lhs_instance_type,
26 TNode<String> rhs, TNode<Word32T> rhs_instance_type,
27 TNode<IntPtrT> length, Label* if_equal,
28 Label* if_not_equal, Label* if_indirect);
30 TNode<Context> context,
31 Label* if_true,
32 Label* if_false);
33
35 TNode<IntPtrT> index,
36 UnicodeEncoding encoding);
38
40 Label* if_indirect);
41
43
44 // Return a new string object which holds a substring containing the range
45 // [from,to[ of string.
46 // TODO(v8:9880): Fix implementation to use UintPtrT arguments and drop
47 // IntPtrT version once all callers use UintPtrT version.
51 TNode<UintPtrT> to) {
52 return SubString(string, Signed(from), Signed(to));
53 }
54
55 // Copies |character_count| elements from |from_string| to |to_string|
56 // starting at the |from_index|'th character. |from_string| and |to_string|
57 // can either be one-byte strings or two-byte strings, although if
58 // |from_string| is two-byte, then |to_string| must be two-byte.
59 // |from_index|, |to_index| and |character_count| must be intptr_ts s.t. 0 <=
60 // |from_index| <= |from_index| + |character_count| <= from_string.length and
61 // 0 <= |to_index| <= |to_index| + |character_count| <= to_string.length.
62 template <typename T>
63 void CopyStringCharacters(TNode<T> from_string, TNode<String> to_string,
64 TNode<IntPtrT> from_index, TNode<IntPtrT> to_index,
65 TNode<IntPtrT> character_count,
66 String::Encoding from_encoding,
67 String::Encoding to_encoding);
68
69 // Torque wrapper methods for CallSearchStringRaw for each combination of
70 // search and subject character widths (char8/char16). This is a workaround
71 // for Torque's current lack of support for extern macros with generics.
73 const TNode<RawPtrT> subject_ptr, const TNode<IntPtrT> subject_length,
74 const TNode<RawPtrT> search_ptr, const TNode<IntPtrT> search_length,
75 const TNode<IntPtrT> start_position);
77 const TNode<RawPtrT> subject_ptr, const TNode<IntPtrT> subject_length,
78 const TNode<RawPtrT> search_ptr, const TNode<IntPtrT> search_length,
79 const TNode<IntPtrT> start_position);
81 const TNode<RawPtrT> subject_ptr, const TNode<IntPtrT> subject_length,
82 const TNode<RawPtrT> search_ptr, const TNode<IntPtrT> search_length,
83 const TNode<IntPtrT> start_position);
85 const TNode<RawPtrT> subject_ptr, const TNode<IntPtrT> subject_length,
86 const TNode<RawPtrT> search_ptr, const TNode<IntPtrT> search_length,
87 const TNode<IntPtrT> start_position);
89 const TNode<RawPtrT> subject_ptr, const TNode<IntPtrT> subject_length,
90 const TNode<RawPtrT> search_ptr, const TNode<IntPtrT> start_position);
91
93 const TNode<String> string);
94
95 protected:
103
104 void StringEqual_FastLoop(TNode<String> lhs, TNode<Word32T> lhs_instance_type,
105 TNode<String> rhs, TNode<Word32T> rhs_instance_type,
106 TNode<IntPtrT> byte_length, Label* if_equal,
107 Label* if_not_equal);
108 void StringEqual_Loop(TNode<String> lhs, TNode<Word32T> lhs_instance_type,
109 MachineType lhs_type, TNode<String> rhs,
110 TNode<Word32T> rhs_instance_type, MachineType rhs_type,
111 TNode<IntPtrT> length, Label* if_equal,
112 Label* if_not_equal);
114 TNode<Word32T> string_instance_type);
115
116 template <typename SubjectChar, typename PatternChar>
118 const TNode<IntPtrT> subject_length,
119 const TNode<RawPtrT> search_ptr,
121 const TNode<IntPtrT> start_position);
122
124 TNode<IntPtrT> length);
126 TNode<String> right,
128
130 TNode<String> subject_string,
131 TNode<Smi> subject_length,
132 TNode<Number> limit_number);
133
135 return SmiLessThan(value, SmiConstant(0));
136 }
137
139 TNode<String> right);
140
142 TNode<String> left, TNode<String> right);
143
144 // Check if |string| is an indirect (thin or flat cons) string type that can
145 // be dereferenced by DerefIndirectString.
147 TNode<Int32T> instance_type,
148 Label* can_deref, Label* cannot_deref);
149 // Allocate an appropriate one- or two-byte ConsString with the first and
150 // second parts specified by |left| and |right|.
151 // Unpack an indirect (thin or flat cons) string type.
152 void DerefIndirectString(TVariable<String>* var_string,
153 TNode<Int32T> instance_type);
154 // Check if |var_string| has an indirect (thin or flat cons) string type, and
155 // unpack it if so.
157 TNode<Int32T> instance_type, Label* did_deref,
158 Label* cannot_deref);
159 // Check if |var_left| or |var_right| has an indirect (thin or flat cons)
160 // string type, and unpack it/them if so. Fall through if nothing was done.
162 TNode<Int32T> left_instance_type,
163 TVariable<String>* var_right,
164 TNode<Int32T> right_instance_type,
165 Label* did_something);
167 TNode<Int32T> instance_type,
168 Label* cannot_deref);
169
170 // Implements boilerplate logic for {match, split, replace, search} of the
171 // form:
172 //
173 // if (!IS_NULL_OR_UNDEFINED(object)) {
174 // var maybe_function = object[symbol];
175 // if (!IS_UNDEFINED(maybe_function)) {
176 // return %_Call(maybe_function, ...);
177 // }
178 // }
179 //
180 // Contains fast paths for Smi and RegExp objects.
181 // Important: {regexp_call} may not contain any code that can call into JS.
182 using NodeFunction0 = std::function<void()>;
183 using NodeFunction1 = std::function<void(TNode<Object> fn)>;
187 const TNode<Context> context, const TNode<JSAny> object,
188 const TNode<Object> maybe_string, Handle<Symbol> symbol,
189 DescriptorIndexNameValue additional_property_to_check,
190 const NodeFunction0& regexp_call, const NodeFunction1& generic_call);
191
192 private:
193 template <typename T>
195 TNode<BoolT> from_is_one_byte,
196 TNode<IntPtrT> from_index,
197 TNode<IntPtrT> character_count);
198};
199
200} // namespace internal
201} // namespace v8
202
203#endif // V8_BUILTINS_BUILTINS_STRING_GEN_H_
void ReplaceUnpairedSurrogates(TNode< String > source, TNode< String > dest, Label *if_indirect)
void StringEqual_Core(TNode< String > lhs, TNode< Word32T > lhs_instance_type, TNode< String > rhs, TNode< Word32T > rhs_instance_type, TNode< IntPtrT > length, Label *if_equal, Label *if_not_equal, Label *if_indirect)
TNode< Smi > IndexOfDollarChar(const TNode< Context > context, const TNode< String > string)
void BranchIfCanDerefIndirectString(TNode< String > string, TNode< Int32T > instance_type, Label *can_deref, Label *cannot_deref)
void MaybeDerefIndirectString(TVariable< String > *var_string, TNode< Int32T > instance_type, Label *did_deref, Label *cannot_deref)
TNode< IntPtrT > SearchOneByteStringInOneByteString(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > search_length, const TNode< IntPtrT > start_position)
TNode< IntPtrT > SearchOneByteStringInTwoByteString(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > search_length, const TNode< IntPtrT > start_position)
TNode< String > AllocateConsString(TNode< Uint32T > length, TNode< String > left, TNode< String > right)
TNode< JSArray > StringToArray(TNode< NativeContext > context, TNode< String > subject_string, TNode< Smi > subject_length, TNode< Number > limit_number)
TNode< String > AllocAndCopyStringCharacters(TNode< T > from, TNode< BoolT > from_is_one_byte, TNode< IntPtrT > from_index, TNode< IntPtrT > character_count)
TNode< String > SubString(TNode< String > string, TNode< IntPtrT > from, TNode< IntPtrT > to)
void CopyStringCharacters(TNode< T > from_string, TNode< String > to_string, TNode< IntPtrT > from_index, TNode< IntPtrT > to_index, TNode< IntPtrT > character_count, String::Encoding from_encoding, String::Encoding to_encoding)
TNode< String > SubString(TNode< String > string, TNode< UintPtrT > from, TNode< UintPtrT > to)
void BranchIfStringPrimitiveWithNoCustomIteration(TNode< Object > object, TNode< Context > context, Label *if_true, Label *if_false)
TNode< IntPtrT > SearchTwoByteStringInOneByteString(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > search_length, const TNode< IntPtrT > start_position)
TNode< String > StringAdd(TNode< ContextOrEmptyContext > context, TNode< String > left, TNode< String > right)
void GenerateStringRelationalComparison(TNode< String > left, TNode< String > right, StringComparison op)
TNode< RawPtrT > DirectStringData(TNode< String > string, TNode< Word32T > string_instance_type)
TNode< BoolT > HasUnpairedSurrogate(TNode< String > string, Label *if_indirect)
void DerefIndirectString(TVariable< String > *var_string, TNode< Int32T > instance_type)
TNode< IntPtrT > CallSearchStringRaw(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > search_length, const TNode< IntPtrT > start_position)
TNode< IntPtrT > SearchTwoByteStringInTwoByteString(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > search_length, const TNode< IntPtrT > start_position)
TNode< Int32T > LoadSurrogatePairAt(TNode< String > string, TNode< IntPtrT > length, TNode< IntPtrT > index, UnicodeEncoding encoding)
TNode< String > GetSubstitution(TNode< Context > context, TNode< String > subject_string, TNode< Smi > match_start_index, TNode< Smi > match_end_index, TNode< String > replace_string)
TNode< IntPtrT > SearchOneByteInOneByteString(const TNode< RawPtrT > subject_ptr, const TNode< IntPtrT > subject_length, const TNode< RawPtrT > search_ptr, const TNode< IntPtrT > start_position)
TNode< String > StringFromSingleUTF16EncodedCodePoint(TNode< Int32T > codepoint)
void MaybeCallFunctionAtSymbol(const TNode< Context > context, const TNode< JSAny > object, const TNode< Object > maybe_string, Handle< Symbol > symbol, DescriptorIndexNameValue additional_property_to_check, const NodeFunction0 &regexp_call, const NodeFunction1 &generic_call)
void StringEqual_Loop(TNode< String > lhs, TNode< Word32T > lhs_instance_type, MachineType lhs_type, TNode< String > rhs, TNode< Word32T > rhs_instance_type, MachineType rhs_type, TNode< IntPtrT > length, Label *if_equal, Label *if_not_equal)
StringBuiltinsAssembler(compiler::CodeAssemblerState *state)
void StringEqual_FastLoop(TNode< String > lhs, TNode< Word32T > lhs_instance_type, TNode< String > rhs, TNode< Word32T > rhs_instance_type, TNode< IntPtrT > byte_length, Label *if_equal, Label *if_not_equal)
TNode< BoolT > SmiIsNegative(TNode< Smi > value)
void MaybeDerefIndirectStrings(TVariable< String > *var_left, TNode< Int32T > left_instance_type, TVariable< String > *var_right, TNode< Int32T > right_instance_type, Label *did_something)
void GenerateStringEqual(TNode< String > left, TNode< String > right, TNode< IntPtrT > length)
std::function< void(TNode< Object > fn)> NodeFunction1
TNode< Int32T > Signed(TNode< Word32T > x)
TNode< Smi > SmiConstant(Tagged< Smi > value)
EmitFn fn
BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL BUILTIN_FP_CALL int size_t search_length