-
Notifications
You must be signed in to change notification settings - Fork 2
/
context.h
54 lines (41 loc) · 1016 Bytes
/
context.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <map>
#include <memory>
#include <string>
#include "llvm.h"
#include "type.h"
class FunDecl;
class Literal;
struct Record {
std::string id;
Type type;
llvm::AllocaInst* addr;
};
struct Trace {
llvm::Function* llvmFun;
FunDecl* fun;
llvm::BasicBlock* contB;
llvm::BasicBlock* endB;
};
class Scope {
Scope* parent;
typedef std::map<std::string, Record> VarRec;
std::shared_ptr<VarRec> varRec;
Trace* trace;
bool localCount(std::string);
void setOrCreateVar(std::string, Record r);
public:
Scope(Scope* parent = nullptr, Trace* trace = nullptr)
: parent(parent), trace(trace) {
varRec = std::make_shared<VarRec>();
}
bool count(std::string);
void define(std::string, Record r);
void set(std::string, Record r);
Record get(std::string);
void setTrace(Trace r);
Trace getTrace();
bool isWrapped() const { return parent; }
Scope wrap() { return Scope(this, trace); }
Scope wrapWithTrace(Trace* t) { return Scope(this, t); };
};