irgen.cc
1.47 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* irgen.cc - LLVM IR generator
*
* You can implement any LLVM related functions here.
*/
#include "irgen.h"
IRGenerator irgen;
IRGenerator::IRGenerator() :
context(NULL),
module(NULL),
currentFunc(NULL),
currentBB(NULL)
{
}
IRGenerator::~IRGenerator() {
}
llvm::Module *IRGenerator::GetOrCreateModule(const char *moduleID)
{
if ( module == NULL ) {
context = new llvm::LLVMContext();
module = new llvm::Module(moduleID, *context);
module->setTargetTriple(TargetTriple);
module->setDataLayout(TargetLayout);
}
return module;
}
void IRGenerator::SetFunction(llvm::Function *func) {
currentFunc = func;
}
llvm::Function *IRGenerator::GetFunction() const {
return currentFunc;
}
void IRGenerator::SetBasicBlock(llvm::BasicBlock *bb) {
currentBB = bb;
}
llvm::BasicBlock *IRGenerator::GetBasicBlock() const {
return currentBB;
}
llvm::Type *IRGenerator::GetIntType() const {
llvm::Type *ty = llvm::Type::getInt32Ty(*context);
return ty;
}
llvm::Type *IRGenerator::GetBoolType() const {
llvm::Type *ty = llvm::Type::getInt1Ty(*context);
return ty;
}
llvm::Type *IRGenerator::GetFloatType() const {
llvm::Type *ty = llvm::Type::getFloatTy(*context);
return ty;
}
const char *IRGenerator::TargetLayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128";
const char *IRGenerator::TargetTriple = "x86_64-redhat-linux-gnu";