11cb0ef41Sopenharmony_ci// Copyright 2017 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#ifndef V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ 61cb0ef41Sopenharmony_ci#define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci#include "src/codegen/code-stub-assembler.h" 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cinamespace v8 { 111cb0ef41Sopenharmony_cinamespace internal { 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciclass ArrayBuiltinsAssembler : public CodeStubAssembler { 141cb0ef41Sopenharmony_ci public: 151cb0ef41Sopenharmony_ci explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci using BuiltinResultGenerator = 181cb0ef41Sopenharmony_ci std::function<void(ArrayBuiltinsAssembler* masm)>; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci using CallResultProcessor = std::function<TNode<Object>( 211cb0ef41Sopenharmony_ci ArrayBuiltinsAssembler* masm, TNode<Object> k_value, TNode<UintPtrT> k)>; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci void TypedArrayMapResultGenerator(); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci // See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map. 261cb0ef41Sopenharmony_ci TNode<Object> TypedArrayMapProcessor(TNode<Object> k_value, 271cb0ef41Sopenharmony_ci TNode<UintPtrT> k); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci TNode<String> CallJSArrayArrayJoinConcatToSequentialString( 301cb0ef41Sopenharmony_ci TNode<FixedArray> fixed_array, TNode<IntPtrT> length, TNode<String> sep, 311cb0ef41Sopenharmony_ci TNode<String> dest) { 321cb0ef41Sopenharmony_ci TNode<ExternalReference> func = ExternalConstant( 331cb0ef41Sopenharmony_ci ExternalReference::jsarray_array_join_concat_to_sequential_string()); 341cb0ef41Sopenharmony_ci TNode<ExternalReference> isolate_ptr = 351cb0ef41Sopenharmony_ci ExternalConstant(ExternalReference::isolate_address(isolate())); 361cb0ef41Sopenharmony_ci return UncheckedCast<String>( 371cb0ef41Sopenharmony_ci CallCFunction(func, 381cb0ef41Sopenharmony_ci MachineType::AnyTagged(), // <return> String 391cb0ef41Sopenharmony_ci std::make_pair(MachineType::Pointer(), isolate_ptr), 401cb0ef41Sopenharmony_ci std::make_pair(MachineType::AnyTagged(), fixed_array), 411cb0ef41Sopenharmony_ci std::make_pair(MachineType::IntPtr(), length), 421cb0ef41Sopenharmony_ci std::make_pair(MachineType::AnyTagged(), sep), 431cb0ef41Sopenharmony_ci std::make_pair(MachineType::AnyTagged(), dest))); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci protected: 471cb0ef41Sopenharmony_ci TNode<Context> context() { return context_; } 481cb0ef41Sopenharmony_ci TNode<Object> receiver() { return receiver_; } 491cb0ef41Sopenharmony_ci TNode<IntPtrT> argc() { return argc_; } 501cb0ef41Sopenharmony_ci TNode<JSReceiver> o() { return o_; } 511cb0ef41Sopenharmony_ci TNode<UintPtrT> len() { return len_; } 521cb0ef41Sopenharmony_ci TNode<Object> callbackfn() { return callbackfn_; } 531cb0ef41Sopenharmony_ci TNode<Object> this_arg() { return this_arg_; } 541cb0ef41Sopenharmony_ci TNode<UintPtrT> k() { return k_.value(); } 551cb0ef41Sopenharmony_ci TNode<Object> a() { return a_.value(); } 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci void ReturnFromBuiltin(TNode<Object> value); 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci void InitIteratingArrayBuiltinBody(TNode<Context> context, 601cb0ef41Sopenharmony_ci TNode<Object> receiver, 611cb0ef41Sopenharmony_ci TNode<Object> callbackfn, 621cb0ef41Sopenharmony_ci TNode<Object> this_arg, 631cb0ef41Sopenharmony_ci TNode<IntPtrT> argc); 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci void GenerateIteratingTypedArrayBuiltinBody( 661cb0ef41Sopenharmony_ci const char* name, const BuiltinResultGenerator& generator, 671cb0ef41Sopenharmony_ci const CallResultProcessor& processor, 681cb0ef41Sopenharmony_ci ForEachDirection direction = ForEachDirection::kForward); 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci void TailCallArrayConstructorStub( 711cb0ef41Sopenharmony_ci const Callable& callable, TNode<Context> context, 721cb0ef41Sopenharmony_ci TNode<JSFunction> target, TNode<HeapObject> allocation_site_or_undefined, 731cb0ef41Sopenharmony_ci TNode<Int32T> argc); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ci void GenerateDispatchToArrayStub( 761cb0ef41Sopenharmony_ci TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc, 771cb0ef41Sopenharmony_ci AllocationSiteOverrideMode mode, 781cb0ef41Sopenharmony_ci base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ci void CreateArrayDispatchNoArgument( 811cb0ef41Sopenharmony_ci TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc, 821cb0ef41Sopenharmony_ci AllocationSiteOverrideMode mode, 831cb0ef41Sopenharmony_ci base::Optional<TNode<AllocationSite>> allocation_site); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci void CreateArrayDispatchSingleArgument( 861cb0ef41Sopenharmony_ci TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc, 871cb0ef41Sopenharmony_ci AllocationSiteOverrideMode mode, 881cb0ef41Sopenharmony_ci base::Optional<TNode<AllocationSite>> allocation_site); 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci void GenerateConstructor(TNode<Context> context, 911cb0ef41Sopenharmony_ci TNode<HeapObject> array_function, 921cb0ef41Sopenharmony_ci TNode<Map> array_map, TNode<Object> array_size, 931cb0ef41Sopenharmony_ci TNode<HeapObject> allocation_site, 941cb0ef41Sopenharmony_ci ElementsKind elements_kind, AllocationSiteMode mode); 951cb0ef41Sopenharmony_ci void GenerateArrayNoArgumentConstructor(ElementsKind kind, 961cb0ef41Sopenharmony_ci AllocationSiteOverrideMode mode); 971cb0ef41Sopenharmony_ci void GenerateArraySingleArgumentConstructor(ElementsKind kind, 981cb0ef41Sopenharmony_ci AllocationSiteOverrideMode mode); 991cb0ef41Sopenharmony_ci void GenerateArrayNArgumentsConstructor( 1001cb0ef41Sopenharmony_ci TNode<Context> context, TNode<JSFunction> target, 1011cb0ef41Sopenharmony_ci TNode<Object> new_target, TNode<Int32T> argc, 1021cb0ef41Sopenharmony_ci TNode<HeapObject> maybe_allocation_site); 1031cb0ef41Sopenharmony_ci 1041cb0ef41Sopenharmony_ci private: 1051cb0ef41Sopenharmony_ci void VisitAllTypedArrayElements(TNode<JSArrayBuffer> array_buffer, 1061cb0ef41Sopenharmony_ci const CallResultProcessor& processor, 1071cb0ef41Sopenharmony_ci ForEachDirection direction, 1081cb0ef41Sopenharmony_ci TNode<JSTypedArray> typed_array, 1091cb0ef41Sopenharmony_ci bool can_shrink); 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci TNode<Object> callbackfn_; 1121cb0ef41Sopenharmony_ci TNode<JSReceiver> o_; 1131cb0ef41Sopenharmony_ci TNode<Object> this_arg_; 1141cb0ef41Sopenharmony_ci TNode<UintPtrT> len_; 1151cb0ef41Sopenharmony_ci TNode<Context> context_; 1161cb0ef41Sopenharmony_ci TNode<Object> receiver_; 1171cb0ef41Sopenharmony_ci TNode<IntPtrT> argc_; 1181cb0ef41Sopenharmony_ci TNode<BoolT> fast_typed_array_target_; 1191cb0ef41Sopenharmony_ci const char* name_ = nullptr; 1201cb0ef41Sopenharmony_ci TVariable<UintPtrT> k_; 1211cb0ef41Sopenharmony_ci TVariable<Object> a_; 1221cb0ef41Sopenharmony_ci Label fully_spec_compliant_; 1231cb0ef41Sopenharmony_ci ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS; 1241cb0ef41Sopenharmony_ci}; 1251cb0ef41Sopenharmony_ci 1261cb0ef41Sopenharmony_ci} // namespace internal 1271cb0ef41Sopenharmony_ci} // namespace v8 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci#endif // V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ 130