11cb0ef41Sopenharmony_ci// Copyright 2018 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_GROWABLE_FIXED_ARRAY_GEN_H_
61cb0ef41Sopenharmony_ci#define V8_BUILTINS_GROWABLE_FIXED_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_ci
141cb0ef41Sopenharmony_ci// Utility class implementing a growable fixed array through CSA.
151cb0ef41Sopenharmony_ciclass GrowableFixedArray : public CodeStubAssembler {
161cb0ef41Sopenharmony_ci public:
171cb0ef41Sopenharmony_ci  explicit GrowableFixedArray(compiler::CodeAssemblerState* state)
181cb0ef41Sopenharmony_ci      : CodeStubAssembler(state),
191cb0ef41Sopenharmony_ci        var_array_(this),
201cb0ef41Sopenharmony_ci        var_length_(this),
211cb0ef41Sopenharmony_ci        var_capacity_(this) {
221cb0ef41Sopenharmony_ci    var_array_ = EmptyFixedArrayConstant();
231cb0ef41Sopenharmony_ci    var_capacity_ = IntPtrConstant(0);
241cb0ef41Sopenharmony_ci    var_length_ = IntPtrConstant(0);
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci  TNode<IntPtrT> length() const { return var_length_.value(); }
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci  TVariable<FixedArray>* var_array() { return &var_array_; }
301cb0ef41Sopenharmony_ci  TVariable<IntPtrT>* var_length() { return &var_length_; }
311cb0ef41Sopenharmony_ci  TVariable<IntPtrT>* var_capacity() { return &var_capacity_; }
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci  void Push(const TNode<Object> value);
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci  TNode<FixedArray> ToFixedArray();
361cb0ef41Sopenharmony_ci  TNode<JSArray> ToJSArray(const TNode<Context> context);
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci private:
391cb0ef41Sopenharmony_ci  TNode<IntPtrT> NewCapacity(TNode<IntPtrT> current_capacity);
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  // Creates a new array with {new_capacity} and copies the first
421cb0ef41Sopenharmony_ci  // {element_count} elements from the current array.
431cb0ef41Sopenharmony_ci  TNode<FixedArray> ResizeFixedArray(const TNode<IntPtrT> element_count,
441cb0ef41Sopenharmony_ci                                     const TNode<IntPtrT> new_capacity);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci private:
471cb0ef41Sopenharmony_ci  TVariable<FixedArray> var_array_;
481cb0ef41Sopenharmony_ci  TVariable<IntPtrT> var_length_;
491cb0ef41Sopenharmony_ci  TVariable<IntPtrT> var_capacity_;
501cb0ef41Sopenharmony_ci};
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci}  // namespace internal
531cb0ef41Sopenharmony_ci}  // namespace v8
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci#endif  // V8_BUILTINS_GROWABLE_FIXED_ARRAY_GEN_H_
56