Changed current relation from BasicBlock to BasicBlockImpl, and Function
[jitcs.git] / src / jitcs_int_adt_tmpvector.h
blob9bfa1359ce97db20069ad22b236591b1acc50fa0
1 //===-- evm/function.h - Class to represent a single basic block --*- C++ -*-===//
2 //
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
5 // result.
6 //
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"
16 namespace jitcs {
18 template <typename T, unsigned N>
19 struct TmpVector : public Slice<T> {
20 typedef T ItemType;
21 typedef Slice<T> super;
22 ItemType _short_data[N];
23 size_t _capacity;
24 TempAllocator& _alloc;
26 TmpVector(TempAllocator& a) : super(_short_data, 0), _capacity(N), _alloc(a) {}
28 TmpVector() = delete;
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);
45 this->_size = sz;
46 std::fill(this->ptr(), this->ptr() + sz, filler);
49 private:
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
61 #endif
62 // _JITCS_INT_ADT_TMPVECTOR_H_