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
11
namespace
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
44
struct
IRGenerationContext
45
{
46
llvm::LLVMContext &
llvm_ctx
;
47
std::unique_ptr<llvm::Module>
module
;
48
Scope
&
scope
;
49
};
50
}
51
52
#endif
//UNLOGIC_IRGENERATIONCONTEXT_H
unlogic::Scope
Definition
IRGenerationContext.h:14
unlogic::Scope::PushLayer
void PushLayer()
Definition
IRGenerationContext.h:33
unlogic::Scope::PopLayer
void PopLayer()
Definition
IRGenerationContext.h:38
unlogic::Scope::Insert
void Insert(std::string const &key, llvm::Value *value)
Definition
IRGenerationContext.h:28
unlogic::Scope::Lookup
std::optional< llvm::Value * > Lookup(std::string const &key)
Definition
IRGenerationContext.h:18
unlogic
Definition
Compiler.h:18
unlogic::IRGenerationContext
Definition
IRGenerationContext.h:45
unlogic::IRGenerationContext::scope
std::unique_ptr< llvm::Module > Scope & scope
Definition
IRGenerationContext.h:48
unlogic::IRGenerationContext::llvm_ctx
llvm::LLVMContext & llvm_ctx
Definition
IRGenerationContext.h:46
unlogic
src
compiler
transformer
IRGenerationContext.h
Generated by
1.9.8