1
2
3
4
5
6 #ifndef CMAJOR_CMLLVM_VALUE_STACK_INCLUDED
7 #define CMAJOR_CMLLVM_VALUE_STACK_INCLUDED
8 #include <soulng/util/Error.hpp>
9 #include <cmajor/ir/GenObject.hpp>
10 #include <cmajor/ir/ValueStack.hpp>
11 #include <llvm/IR/Value.h>
12 #include <vector>
13
14 namespace cmllvm {
15
16 class ValueStack : public cmajor::ir::ValueStack
17 {
18 public:
19 void Push(void* val) override
20 {
21 llvm::Value* value = static_cast<llvm::Value*>(val);
22 s.push_back(value);
23 }
24 void* Pop() override
25 {
26 Assert(!s.empty(), "value stack is empty");
27 llvm::Value* top = s.back();
28 s.pop_back();
29 return top;
30 }
31 void Dup() override
32 {
33 s.push_back(s.back());
34 }
35 void Swap() override
36 {
37 std::swap(s.back(), s[s.size() - 2]);
38 }
39 void Rotate() override
40 {
41 std::swap(s[s.size() - 3], s[s.size() - 2]);
42 std::swap(s.back(), s[s.size() - 2]);
43 }
44 private:
45 std::vector<llvm::Value*> s;
46 };
47
48 }
49
50 #endif // CMAJOR_CMLLVM_VALUE_STACK_INCLUDED