unlogic
Loading...
Searching...
No Matches
IRGenerationContext.h
Go to the documentation of this file.
1#ifndef UNLOGIC_IRGENERATIONCONTEXT_H
2#define UNLOGIC_IRGENERATIONCONTEXT_H
3
4#include <vector>
5#include <optional>
6#include <map>
7#include <ranges>
8#include <llvm/IR/Value.h>
9#include <llvm/IR/LLVMContext.h>
10
11namespace unlogic
12{
13 class Scope
14 {
15 std::vector<std::map<std::string, llvm::Value*>> layers;
16
17 public:
18 std::optional<llvm::Value*> Lookup(std::string const &key)
19 {
20 for(auto &layer : this->layers | std::ranges::views::reverse)
21 {
22 if(layer.contains(key)) return layer[key];
23 }
24
25 return std::nullopt;
26 }
27
28 void Insert(std::string const &key, llvm::Value *value)
29 {
30 this->layers.back()[key] = value;
31 }
32
33 void PushLayer()
34 {
35 this->layers.emplace_back();
36 }
37
38 void PopLayer()
39 {
40 this->layers.pop_back();
41 }
42 };
43
45 {
46 llvm::LLVMContext &llvm_ctx;
47 std::unique_ptr<llvm::Module> module;
49 };
50}
51
52#endif //UNLOGIC_IRGENERATIONCONTEXT_H
void Insert(std::string const &key, llvm::Value *value)
std::optional< llvm::Value * > Lookup(std::string const &key)
std::unique_ptr< llvm::Module > Scope & scope