-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodegen.h
58 lines (54 loc) · 1.32 KB
/
codegen.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
55
56
57
58
#include<stack>
#include<map>
#include<list>
#include <llvm/IR/Module.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/CallingConv.h>
#include <llvm/IR/Type.h>
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/IR/Verifier.h>
#include <llvm/IR/IRPrintingPasses.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/IR/Function.h>
using namespace llvm;
class CodeGenBB {
public:
llvm::BasicBlock * block;
std::map<std::string, llvm::Value *> locals;
CodeGenBB() {}
CodeGenBB(llvm::BasicBlock * block) {
this->block = block;
}
};
class CodeGenContext {
private:
Function *mainFunction;
std::stack<CodeGenBB *> blocks;
public:
Module * module;
CodeGenContext() {
this->module = new Module("main", getGlobalContext());
}
void generateCode(AST *start);
std::map<std::string, Value *>& locals() {
return blocks.top()->locals;
}
BasicBlock *topBB() {
return blocks.top()->block;
}
GenericValue runCode();
void pushBB(BasicBlock *BB){
blocks.push(new CodeGenBB());
blocks.top()->block = BB;
}
void popBB() {
blocks.pop();
}
};