-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllvmcodegen.hpp
More file actions
41 lines (34 loc) · 1.03 KB
/
Copy pathllvmcodegen.hpp
File metadata and controls
41 lines (34 loc) · 1.03 KB
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
#ifndef CODEGEN_HPP
#define CODEGEN_HPP
#include <map>
#include <string>
#include <vector>
#include <memory>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
struct ArrayInfo {
llvm::Value* alloc;
std::vector<int> dims;
};
class ASTNode; // Forward declaration
class CodeGenContext {
public:
llvm::LLVMContext context;
llvm::IRBuilder<> builder;
std::unique_ptr<llvm::Module> module;
llvm::Value *currentValue;
std::map<std::string, ArrayInfo> arrays;
CodeGenContext() : builder(context) {
module = std::make_unique<llvm::Module>("main", context);
currentValue = nullptr;
}
void generateCode(ASTNode* root);
void writeIR(const std::string &filename);
void setCurrentValue(llvm::Value *v) { currentValue = v; }
llvm::Value* getCurrentValue() { return currentValue; }
llvm::Type* getDoublePtrTy() {
return llvm::PointerType::get(builder.getDoubleTy(),0);
}
};
#endif // CODEGEN_HPP