1 //===-- evm/function.h - Class to represent a single basic block --*- C++ -*-===//
3 // A basicblock contains nodes, and must end in a terminal instruction node.
4 // Nodes can be instructions, constants. Each node may produce more than one
7 //===----------------------------------------------------------------------===//
9 #ifndef _JITCS_INT_ADT_TMPVECTOR_H_
10 #define _JITCS_INT_ADT_TMPVECTOR_H_
12 #include "jitcs_adt_slice.h"
13 #include "jitcs_base.h"
14 #include "jitcs_tmpalloc.h"
18 template <typename T
, unsigned N
>
19 struct TmpVector
: public Slice
<T
> {
21 typedef Slice
<T
> super
;
22 ItemType _short_data
[N
];
24 TempAllocator
& _alloc
;
26 TmpVector(TempAllocator
& a
) : super(_short_data
, 0), _capacity(N
), _alloc(a
) {}
29 TmpVector(const TmpVector
&) = delete;
30 TmpVector
& operator =(const TmpVector
&) = delete;
32 void push_back(ItemType i
) {
33 if (this->size() >= _capacity
) _resize(1);
34 this->_ptr
[this->_size
++] = i
;
36 void append(Slice
<ItemType
> items
) {
37 if (this->size() + items
.size() > _capacity
) _resize(items
.size());
38 std::copy(items
.begin(), items
.end(), this->ptr() + this->size());
39 this->_size
+= items
.size();
41 bool isLocalData() const { return this->ptr() == _short_data
; }
43 void initSizeAndClear(size_t sz
, const ItemType
& filler
) {
44 if (sz
> _capacity
) _resize(sz
);
46 std::fill(this->ptr(), this->ptr() + sz
, filler
);
50 void _resize(size_t g
) {
51 Slice
<ItemType
> newdata
52 = _alloc
.allocTypedArray
<ItemType
>((_capacity
| g
) * 2 + 2);
53 std::copy(this->ptr(), this->ptr() + this->size(), newdata
.ptr());
54 this->_ptr
= newdata
.ptr();
55 this->_capacity
= newdata
.size();
59 } // end of namespace jitcs
62 // _JITCS_INT_ADT_TMPVECTOR_H_