builtins-array-gen.h 5.19 KB
Newer Older
1 2 3 4 5 6 7
// 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_

8
#include "src/codegen/code-stub-assembler.h"
9 10 11 12

namespace v8 {
namespace internal {

13
class ArrayBuiltinsAssembler : public CodeStubAssembler {
14 15 16
 public:
  explicit ArrayBuiltinsAssembler(compiler::CodeAssemblerState* state);

17 18
  using BuiltinResultGenerator =
      std::function<void(ArrayBuiltinsAssembler* masm)>;
19

20
  using CallResultProcessor = std::function<TNode<Object>(
21
      ArrayBuiltinsAssembler* masm, TNode<Object> k_value, TNode<UintPtrT> k)>;
22 23 24 25

  void TypedArrayMapResultGenerator();

  // See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map.
26 27
  TNode<Object> TypedArrayMapProcessor(TNode<Object> k_value,
                                       TNode<UintPtrT> k);
28

29 30 31 32 33 34 35 36
  TNode<String> CallJSArrayArrayJoinConcatToSequentialString(
      TNode<FixedArray> fixed_array, TNode<IntPtrT> length, TNode<String> sep,
      TNode<String> dest) {
    TNode<ExternalReference> func = ExternalConstant(
        ExternalReference::jsarray_array_join_concat_to_sequential_string());
    TNode<ExternalReference> isolate_ptr =
        ExternalConstant(ExternalReference::isolate_address(isolate()));
    return UncheckedCast<String>(
37 38 39 40 41 42 43
        CallCFunction(func,
                      MachineType::AnyTagged(),  // <return> 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)));
44 45
  }

46
 protected:
47 48 49
  TNode<Context> context() { return context_; }
  TNode<Object> receiver() { return receiver_; }
  TNode<IntPtrT> argc() { return argc_; }
50
  TNode<JSReceiver> o() { return o_; }
51
  TNode<UintPtrT> len() { return len_; }
52 53
  TNode<Object> callbackfn() { return callbackfn_; }
  TNode<Object> this_arg() { return this_arg_; }
54
  TNode<UintPtrT> k() { return k_.value(); }
55
  TNode<Object> a() { return a_.value(); }
56

57
  void ReturnFromBuiltin(TNode<Object> value);
58

59
  void InitIteratingArrayBuiltinBody(TNode<Context> context,
60 61 62 63
                                     TNode<Object> receiver,
                                     TNode<Object> callbackfn,
                                     TNode<Object> this_arg,
                                     TNode<IntPtrT> argc);
64 65 66

  void GenerateIteratingTypedArrayBuiltinBody(
      const char* name, const BuiltinResultGenerator& generator,
67
      const CallResultProcessor& processor,
68 69
      ForEachDirection direction = ForEachDirection::kForward);

70 71 72 73 74
  void TailCallArrayConstructorStub(
      const Callable& callable, TNode<Context> context,
      TNode<JSFunction> target, TNode<HeapObject> allocation_site_or_undefined,
      TNode<Int32T> argc);

75 76 77 78
  void GenerateDispatchToArrayStub(
      TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
      AllocationSiteOverrideMode mode,
      base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt);
79 80 81 82

  void CreateArrayDispatchNoArgument(
      TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
      AllocationSiteOverrideMode mode,
83
      base::Optional<TNode<AllocationSite>> allocation_site);
84 85 86 87

  void CreateArrayDispatchSingleArgument(
      TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
      AllocationSiteOverrideMode mode,
88
      base::Optional<TNode<AllocationSite>> allocation_site);
89

90 91 92 93
  void GenerateConstructor(TNode<Context> context,
                           TNode<HeapObject> array_function,
                           TNode<Map> array_map, TNode<Object> array_size,
                           TNode<HeapObject> allocation_site,
94 95 96 97 98
                           ElementsKind elements_kind, AllocationSiteMode mode);
  void GenerateArrayNoArgumentConstructor(ElementsKind kind,
                                          AllocationSiteOverrideMode mode);
  void GenerateArraySingleArgumentConstructor(ElementsKind kind,
                                              AllocationSiteOverrideMode mode);
99 100 101 102 103
  void GenerateArrayNArgumentsConstructor(
      TNode<Context> context, TNode<JSFunction> target,
      TNode<Object> new_target, TNode<Int32T> argc,
      TNode<HeapObject> maybe_allocation_site);

104
 private:
105
  void VisitAllTypedArrayElements(TNode<JSArrayBuffer> array_buffer,
106
                                  const CallResultProcessor& processor,
107 108
                                  Label* detached, ForEachDirection direction,
                                  TNode<JSTypedArray> typed_array);
109

110
  TNode<Object> callbackfn_;
111
  TNode<JSReceiver> o_;
112
  TNode<Object> this_arg_;
113
  TNode<UintPtrT> len_;
114 115 116
  TNode<Context> context_;
  TNode<Object> receiver_;
  TNode<IntPtrT> argc_;
117
  TNode<BoolT> fast_typed_array_target_;
118
  const char* name_ = nullptr;
119
  TVariable<UintPtrT> k_;
120
  TVariable<Object> a_;
121 122 123 124 125 126 127 128
  Label fully_spec_compliant_;
  ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS;
};

}  // namespace internal
}  // namespace v8

#endif  // V8_BUILTINS_BUILTINS_ARRAY_GEN_H_