-
Notifications
You must be signed in to change notification settings - Fork 0
/
astcodegen.h
55 lines (42 loc) · 981 Bytes
/
astcodegen.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
#pragma once
#include "llvm/IR/Verifier.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include <memory>
#include <string>
#include <map>
#include <vector>
#include "astnode.h"
namespace Blang
{
typedef std::map< std::string, llvm::Value* > VarMap_t;
struct CodeGenContext
{
CodeGenContext(llvm::IRBuilder& builder)
: m_builder(builder)
{
m_localVars.clear();
m_extrnVars.clear();
m_localExtrnVars.clear();
}
VarMap_t m_localVars; //in-scope auto decls
VarMap_t m_localExtrnVars; //in-scope extrn decls
VarMap_t m_extrnVars; //global extrn vars
VarMap_t m_funcs;
llvm::IRBuilder& m_builder;
};
class IRBuilder
{
public:
IRBuilder() {};
~IRBuilder() {};
void Init(std::string& moduleName);
void GenerateIR(ProgramAST* astRoot);
void OutputIR();
private:
llvm::LLVMContext& m_context;
std::unique_ptr<llvm::Module> m_module;
};
}