forked from bhargavkulk/CSF363-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvmcodegen.hh
33 lines (27 loc) · 810 Bytes
/
llvmcodegen.hh
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
#ifndef LLVMCODEGEN_HH
#define LLVMCODEGEN_HH
#include <llvm/IR/Instructions.h>
#include <string>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <unordered_map>
#include "ast.hh"
using namespace llvm;
/**
Compiler struct to store state of the LLVM IRBuilder.
The `compile` method recursively calls the llvmcodegen method for a given
`Node`.
*/
struct LLVMCompiler {
LLVMContext *context;
IRBuilder<> builder;
Module module;
std::unordered_map<std::string, AllocaInst*> locals;
LLVMCompiler(LLVMContext *context, std::string file_name) :
context(context), builder(*context), module(file_name, *context) {}
void compile(Node *root);
void dump();
void write(std::string file_name);
};
#endif