1// Copyright 2018 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_GROWABLE_FIXED_ARRAY_GEN_H_ 6#define V8_BUILTINS_GROWABLE_FIXED_ARRAY_GEN_H_ 7 8#include "src/codegen/code-stub-assembler.h" 9 10namespace v8 { 11namespace internal { 12 13 14// Utility class implementing a growable fixed array through CSA. 15class GrowableFixedArray : public CodeStubAssembler { 16 public: 17 explicit GrowableFixedArray(compiler::CodeAssemblerState* state) 18 : CodeStubAssembler(state), 19 var_array_(this), 20 var_length_(this), 21 var_capacity_(this) { 22 var_array_ = EmptyFixedArrayConstant(); 23 var_capacity_ = IntPtrConstant(0); 24 var_length_ = IntPtrConstant(0); 25 } 26 27 TNode<IntPtrT> length() const { return var_length_.value(); } 28 29 TVariable<FixedArray>* var_array() { return &var_array_; } 30 TVariable<IntPtrT>* var_length() { return &var_length_; } 31 TVariable<IntPtrT>* var_capacity() { return &var_capacity_; } 32 33 void Push(const TNode<Object> value); 34 35 TNode<FixedArray> ToFixedArray(); 36 TNode<JSArray> ToJSArray(const TNode<Context> context); 37 38 private: 39 TNode<IntPtrT> NewCapacity(TNode<IntPtrT> current_capacity); 40 41 // Creates a new array with {new_capacity} and copies the first 42 // {element_count} elements from the current array. 43 TNode<FixedArray> ResizeFixedArray(const TNode<IntPtrT> element_count, 44 const TNode<IntPtrT> new_capacity); 45 46 private: 47 TVariable<FixedArray> var_array_; 48 TVariable<IntPtrT> var_length_; 49 TVariable<IntPtrT> var_capacity_; 50}; 51 52} // namespace internal 53} // namespace v8 54 55#endif // V8_BUILTINS_GROWABLE_FIXED_ARRAY_GEN_H_ 56