// Copyright 2017 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ #define V8_BUILTINS_BUILTINS_ARRAY_GEN_H_ #include "src/codegen/code-stub-assembler.h" namespace v8 { namespace internal { class ArrayBuiltinsAssembler : public CodeStubAssembler { public: explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state); using BuiltinResultGenerator = std::function; using CallResultProcessor = std::function( ArrayBuiltinsAssembler* masm, TNode k_value, TNode k)>; void TypedArrayMapResultGenerator(); // See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map. TNode TypedArrayMapProcessor(TNode k_value, TNode k); TNode CallJSArrayArrayJoinConcatToSequentialString( TNode fixed_array, TNode length, TNode sep, TNode dest) { TNode func = ExternalConstant( ExternalReference::jsarray_array_join_concat_to_sequential_string()); TNode isolate_ptr = ExternalConstant(ExternalReference::isolate_address(isolate())); return UncheckedCast( CallCFunction(func, MachineType::AnyTagged(), // String std::make_pair(MachineType::Pointer(), isolate_ptr), std::make_pair(MachineType::AnyTagged(), fixed_array), std::make_pair(MachineType::IntPtr(), length), std::make_pair(MachineType::AnyTagged(), sep), std::make_pair(MachineType::AnyTagged(), dest))); } protected: TNode context() { return context_; } TNode receiver() { return receiver_; } TNode argc() { return argc_; } TNode o() { return o_; } TNode len() { return len_; } TNode callbackfn() { return callbackfn_; } TNode this_arg() { return this_arg_; } TNode k() { return k_.value(); } TNode a() { return a_.value(); } void ReturnFromBuiltin(TNode value); void InitIteratingArrayBuiltinBody(TNode context, TNode receiver, TNode callbackfn, TNode this_arg, TNode argc); void GenerateIteratingTypedArrayBuiltinBody( const char* name, const BuiltinResultGenerator& generator, const CallResultProcessor& processor, ForEachDirection direction = ForEachDirection::kForward); void TailCallArrayConstructorStub( const Callable& callable, TNode context, TNode target, TNode allocation_site_or_undefined, TNode argc); void GenerateDispatchToArrayStub(TNode context, TNode target, TNode argc, AllocationSiteOverrideMode mode, TNode allocation_site = {}); void CreateArrayDispatchNoArgument( TNode context, TNode target, TNode argc, AllocationSiteOverrideMode mode, TNode allocation_site = {}); void CreateArrayDispatchSingleArgument( TNode context, TNode target, TNode argc, AllocationSiteOverrideMode mode, TNode allocation_site = {}); void GenerateConstructor(TNode context, TNode array_function, TNode array_map, TNode array_size, TNode allocation_site, ElementsKind elements_kind, AllocationSiteMode mode); void GenerateArrayNoArgumentConstructor(ElementsKind kind, AllocationSiteOverrideMode mode); void GenerateArraySingleArgumentConstructor(ElementsKind kind, AllocationSiteOverrideMode mode); void GenerateArrayNArgumentsConstructor( TNode context, TNode target, TNode new_target, TNode argc, TNode maybe_allocation_site); private: void VisitAllTypedArrayElements(TNode array_buffer, const CallResultProcessor& processor, Label* detached, ForEachDirection direction, TNode typed_array); TNode callbackfn_; TNode o_; TNode this_arg_; TNode len_; TNode context_; TNode receiver_; TNode argc_; TNode fast_typed_array_target_; const char* name_ = nullptr; TVariable k_; TVariable a_; Label fully_spec_compliant_; ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS; }; } // namespace internal } // namespace v8 #endif // V8_BUILTINS_BUILTINS_ARRAY_GEN_H_