mini-llvm 0.1.0
Loading...
Searching...
No Matches
StackFrame.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstddef>
6#include <iterator>
7#include <list>
8#include <memory>
9#include <utility>
10
14
15namespace mini_llvm::mir {
16
18 using StackSlotList = std::list<std::unique_ptr<StackSlot>>;
19
20public:
25
26 StackFrame() = default;
27 StackFrame(const StackFrame &) = delete;
28 StackFrame(StackFrame &&) = delete;
29 StackFrame &operator=(const StackFrame &) = delete;
31
33 return iterator(slots_.begin());
34 }
35
37 return const_iterator(slots_.begin());
38 }
39
41 return iterator(slots_.end());
42 }
43
45 return const_iterator(slots_.end());
46 }
47
49 return reverse_iterator(slots_.rbegin());
50 }
51
53 return const_reverse_iterator(slots_.rbegin());
54 }
55
57 return reverse_iterator(slots_.rend());
58 }
59
61 return const_reverse_iterator(slots_.rend());
62 }
63
65 return *begin();
66 }
67
68 const StackSlot &front() const {
69 return *begin();
70 }
71
73 return *std::prev(end());
74 }
75
76 const StackSlot &back() const {
77 return *std::prev(end());
78 }
79
80 bool empty() const {
81 return slots_.empty();
82 }
83
84 size_t size() const {
85 return slots_.size();
86 }
87
88 StackSlot &add(const_iterator pos, std::unique_ptr<StackSlot> slot);
89
90 StackSlot &add(const_iterator pos, int size, int alignment) {
91 return add(pos, std::make_unique<StackSlot>(size, alignment));
92 }
93
94 StackSlot &prepend(std::unique_ptr<StackSlot> slot) {
95 return add(begin(), std::move(slot));
96 }
97
98 StackSlot &prepend(int size, int alignment) {
99 return prepend(std::make_unique<StackSlot>(size, alignment));
100 }
101
102 StackSlot &append(std::unique_ptr<StackSlot> slot) {
103 return add(end(), std::move(slot));
104 }
105
106 StackSlot &append(int size, int alignment) {
107 return append(std::make_unique<StackSlot>(size, alignment));
108 }
109
110 std::unique_ptr<StackSlot> remove(iterator pos);
111
112 std::unique_ptr<StackSlot> removeFirst() {
113 return remove(begin());
114 }
115
116 std::unique_ptr<StackSlot> removeLast() {
117 return remove(std::prev(end()));
118 }
119
120 void clear();
121
122private:
123 StackSlotList slots_;
124 bool offsetsUpToDate_ = false;
125
126 void computeOffsets();
127
128 friend class StackSlot;
129};
130
131} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition IndirectIterator.h:16
StackFrame(const StackFrame &)=delete
StackSlot & front()
Definition StackFrame.h:64
IndirectIterator< StackSlotList::const_iterator, const StackSlot > const_iterator
Definition StackFrame.h:22
const StackSlot & back() const
Definition StackFrame.h:76
StackFrame & operator=(const StackFrame &)=delete
iterator end()
Definition StackFrame.h:40
std::unique_ptr< StackSlot > remove(iterator pos)
const_iterator end() const
Definition StackFrame.h:44
reverse_iterator rbegin()
Definition StackFrame.h:48
reverse_iterator rend()
Definition StackFrame.h:56
const StackSlot & front() const
Definition StackFrame.h:68
IndirectIterator< StackSlotList::iterator, StackSlot > iterator
Definition StackFrame.h:21
const_reverse_iterator rend() const
Definition StackFrame.h:60
const_reverse_iterator rbegin() const
Definition StackFrame.h:52
StackSlot & prepend(int size, int alignment)
Definition StackFrame.h:98
StackSlot & append(int size, int alignment)
Definition StackFrame.h:106
StackSlot & back()
Definition StackFrame.h:72
StackFrame & operator=(StackFrame &&)=delete
std::unique_ptr< StackSlot > removeFirst()
Definition StackFrame.h:112
iterator begin()
Definition StackFrame.h:32
StackSlot & prepend(std::unique_ptr< StackSlot > slot)
Definition StackFrame.h:94
const_iterator begin() const
Definition StackFrame.h:36
StackSlot & add(const_iterator pos, int size, int alignment)
Definition StackFrame.h:90
size_t size() const
Definition StackFrame.h:84
IndirectIterator< StackSlotList::reverse_iterator, StackSlot > reverse_iterator
Definition StackFrame.h:23
bool empty() const
Definition StackFrame.h:80
friend class StackSlot
Definition StackFrame.h:128
IndirectIterator< StackSlotList::const_reverse_iterator, const StackSlot > const_reverse_iterator
Definition StackFrame.h:24
StackFrame(StackFrame &&)=delete
StackSlot & add(const_iterator pos, std::unique_ptr< StackSlot > slot)
std::unique_ptr< StackSlot > removeLast()
Definition StackFrame.h:116
StackSlot & append(std::unique_ptr< StackSlot > slot)
Definition StackFrame.h:102
Definition BasicBlock.h:22