Commit 97f140d1e4c2ebd7b32afd4241891d525e51c1fc

Authored by Austin Sun
1 parent 2d64c72aa5
Exists in master

well

Showing 2 changed files with 4 additions and 5 deletions Inline Diff

/* File: ast_stmt.cc 1 1 /* File: ast_stmt.cc
* ----------------- 2 2 * -----------------
* Implementation of statement node classes. 3 3 * Implementation of statement node classes.
*/ 4 4 */
#include "ast_stmt.h" 5 5 #include "ast_stmt.h"
#include "ast_type.h" 6 6 #include "ast_type.h"
#include "ast_decl.h" 7 7 #include "ast_decl.h"
#include "ast_expr.h" 8 8 #include "ast_expr.h"
#include "symtable.h" 9 9 #include "symtable.h"
10 10
#include "irgen.h" 11 11 #include "irgen.h"
#include "llvm/Bitcode/ReaderWriter.h" 12 12 #include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/raw_ostream.h" 13 13 #include "llvm/Support/raw_ostream.h"
14 14
15 15
Program::Program(List<Decl*> *d) { 16 16 Program::Program(List<Decl*> *d) {
Assert(d != NULL); 17 17 Assert(d != NULL);
(decls=d)->SetParentAll(this); 18 18 (decls=d)->SetParentAll(this);
} 19 19 }
20 20
void Program::PrintChildren(int indentLevel) { 21 21 void Program::PrintChildren(int indentLevel) {
decls->PrintAll(indentLevel+1); 22 22 decls->PrintAll(indentLevel+1);
printf("\n"); 23 23 printf("\n");
} 24 24 }
//pls work 25 25 //pls work
llvm::Value* Program::Emit() { 26 26 llvm::Value* Program::Emit() {
llvm::Module *module = irgen.GetOrCreateModule("program"); 27 27 llvm::Module *module = irgen.GetOrCreateModule("program");
pushScope(); 28 28 pushScope();
for (int i = 0; i < decls->NumElements(); i++){ 29 29 for (int i = 0; i < decls->NumElements(); i++){
decls->Nth(i)->Emit(); 30 30 decls->Nth(i)->Emit();
} 31 31 }
popScope(); 32 32 popScope();
33 33
module->dump(); 34 34 module->dump();
llvm::WriteBitcodeToFile(module, llvm::outs()); 35 35 llvm::WriteBitcodeToFile(module, llvm::outs());
return NULL; 36 36 return NULL;
} 37 37 }
38 38
StmtBlock::StmtBlock(List<VarDecl*> *d, List<Stmt*> *s) { 39 39 StmtBlock::StmtBlock(List<VarDecl*> *d, List<Stmt*> *s) {
Assert(d != NULL && s != NULL); 40 40 Assert(d != NULL && s != NULL);
(decls=d)->SetParentAll(this); 41 41 (decls=d)->SetParentAll(this);
(stmts=s)->SetParentAll(this); 42 42 (stmts=s)->SetParentAll(this);
} 43 43 }
44 44
void StmtBlock::PrintChildren(int indentLevel) { 45 45 void StmtBlock::PrintChildren(int indentLevel) {
decls->PrintAll(indentLevel+1); 46 46 decls->PrintAll(indentLevel+1);
stmts->PrintAll(indentLevel+1); 47 47 stmts->PrintAll(indentLevel+1);
} 48 48 }
49 49
DeclStmt::DeclStmt(Decl *d) { 50 50 DeclStmt::DeclStmt(Decl *d) {
Assert(d != NULL); 51 51 Assert(d != NULL);
(decl=d)->SetParent(this); 52 52 (decl=d)->SetParent(this);
} 53 53 }
54 54
void DeclStmt::PrintChildren(int indentLevel) { 55 55 void DeclStmt::PrintChildren(int indentLevel) {
decl->Print(indentLevel+1); 56 56 decl->Print(indentLevel+1);
} 57 57 }
58 58
ConditionalStmt::ConditionalStmt(Expr *t, Stmt *b) { 59 59 ConditionalStmt::ConditionalStmt(Expr *t, Stmt *b) {
Assert(t != NULL && b != NULL); 60 60 Assert(t != NULL && b != NULL);
(test=t)->SetParent(this); 61 61 (test=t)->SetParent(this);
(body=b)->SetParent(this); 62 62 (body=b)->SetParent(this);
} 63 63 }
64 64
ForStmt::ForStmt(Expr *i, Expr *t, Expr *s, Stmt *b): LoopStmt(t, b) { 65 65 ForStmt::ForStmt(Expr *i, Expr *t, Expr *s, Stmt *b): LoopStmt(t, b) {
Assert(i != NULL && t != NULL && b != NULL); 66 66 Assert(i != NULL && t != NULL && b != NULL);
(init=i)->SetParent(this); 67 67 (init=i)->SetParent(this);
step = s; 68 68 step = s;
if ( s ) 69 69 if ( s )
(step=s)->SetParent(this); 70 70 (step=s)->SetParent(this);
} 71 71 }
72 72
void ForStmt::PrintChildren(int indentLevel) { 73 73 void ForStmt::PrintChildren(int indentLevel) {
init->Print(indentLevel+1, "(init) "); 74 74 init->Print(indentLevel+1, "(init) ");
test->Print(indentLevel+1, "(test) "); 75 75 test->Print(indentLevel+1, "(test) ");
if ( step ) 76 76 if ( step )
step->Print(indentLevel+1, "(step) "); 77 77 step->Print(indentLevel+1, "(step) ");
body->Print(indentLevel+1, "(body) "); 78 78 body->Print(indentLevel+1, "(body) ");
} 79 79 }
80 80
void WhileStmt::PrintChildren(int indentLevel) { 81 81 void WhileStmt::PrintChildren(int indentLevel) {
test->Print(indentLevel+1, "(test) "); 82 82 test->Print(indentLevel+1, "(test) ");
body->Print(indentLevel+1, "(body) "); 83 83 body->Print(indentLevel+1, "(body) ");
} 84 84 }
85 85
IfStmt::IfStmt(Expr *t, Stmt *tb, Stmt *eb): ConditionalStmt(t, tb) { 86 86 IfStmt::IfStmt(Expr *t, Stmt *tb, Stmt *eb): ConditionalStmt(t, tb) {
Assert(t != NULL && tb != NULL); // else can be NULL 87 87 Assert(t != NULL && tb != NULL); // else can be NULL
elseBody = eb; 88 88 elseBody = eb;
if (elseBody) elseBody->SetParent(this); 89 89 if (elseBody) elseBody->SetParent(this);
} 90 90 }
91 91
void IfStmt::PrintChildren(int indentLevel) { 92 92 void IfStmt::PrintChildren(int indentLevel) {
if (test) test->Print(indentLevel+1, "(test) "); 93 93 if (test) test->Print(indentLevel+1, "(test) ");
if (body) body->Print(indentLevel+1, "(then) "); 94 94 if (body) body->Print(indentLevel+1, "(then) ");
if (elseBody) elseBody->Print(indentLevel+1, "(else) "); 95 95 if (elseBody) elseBody->Print(indentLevel+1, "(else) ");
} 96 96 }
97 97
98 98
ReturnStmt::ReturnStmt(yyltype loc, Expr *e) : Stmt(loc) { 99 99 ReturnStmt::ReturnStmt(yyltype loc, Expr *e) : Stmt(loc) {
expr = e; 100 100 expr = e;
if (e != NULL) expr->SetParent(this); 101 101 if (e != NULL) expr->SetParent(this);
} 102 102 }
103 103
void ReturnStmt::PrintChildren(int indentLevel) { 104 104 void ReturnStmt::PrintChildren(int indentLevel) {
if ( expr ) 105 105 if ( expr )
expr->Print(indentLevel+1); 106 106 expr->Print(indentLevel+1);
} 107 107 }
108 108
SwitchLabel::SwitchLabel(Expr *l, Stmt *s) { 109 109 SwitchLabel::SwitchLabel(Expr *l, Stmt *s) {
Assert(l != NULL && s != NULL); 110 110 Assert(l != NULL && s != NULL);
(label=l)->SetParent(this); 111 111 (label=l)->SetParent(this);
(stmt=s)->SetParent(this); 112 112 (stmt=s)->SetParent(this);
} 113 113 }
114 114
SwitchLabel::SwitchLabel(Stmt *s) { 115 115 SwitchLabel::SwitchLabel(Stmt *s) {
Assert(s != NULL); 116 116 Assert(s != NULL);
label = NULL; 117 117 label = NULL;
(stmt=s)->SetParent(this); 118 118 (stmt=s)->SetParent(this);
} 119 119 }
120 120
void SwitchLabel::PrintChildren(int indentLevel) { 121 121 void SwitchLabel::PrintChildren(int indentLevel) {
if (label) label->Print(indentLevel+1); 122 122 if (label) label->Print(indentLevel+1);
if (stmt) stmt->Print(indentLevel+1); 123 123 if (stmt) stmt->Print(indentLevel+1);
} 124 124 }
125 125
SwitchStmt::SwitchStmt(Expr *e, List<Stmt *> *c, Default *d) { 126 126 SwitchStmt::SwitchStmt(Expr *e, List<Stmt *> *c, Default *d) {
Assert(e != NULL && c != NULL && c->NumElements() != 0 ); 127 127 Assert(e != NULL && c != NULL && c->NumElements() != 0 );
(expr=e)->SetParent(this); 128 128 (expr=e)->SetParent(this);
(cases=c)->SetParentAll(this); 129 129 (cases=c)->SetParentAll(this);
def = d; 130 130 def = d;
if (def) def->SetParent(this); 131 131 if (def) def->SetParent(this);
} 132 132 }
133 133
void SwitchStmt::PrintChildren(int indentLevel) { 134 134 void SwitchStmt::PrintChildren(int indentLevel) {
if (expr) expr->Print(indentLevel+1); 135 135 if (expr) expr->Print(indentLevel+1);
if (cases) cases->PrintAll(indentLevel+1); 136 136 if (cases) cases->PrintAll(indentLevel+1);
if (def) def->Print(indentLevel+1); 137 137 if (def) def->Print(indentLevel+1);
} 138 138 }
//----------------------------------------------------------------------- 139 139 //-----------------------------------------------------------------------
//rest of the emits 140 140 //rest of the emits
//----------------------------------------------------------------------- 141 141 //-----------------------------------------------------------------------
llvm::Value * StmtBlock::Emit(){ 142 142 llvm::Value * StmtBlock::Emit(){
pushScope(); 143 143 pushScope();
for (int i = 0; i < decls->NumElements(); i++){ 144 144 for (int i = 0; i < decls->NumElements(); i++){
decls->Nth(i)->Emit(); 145 145 decls->Nth(i)->Emit();
} 146 146 }
for (int i = 0; i < stmts->NumElements(); i++){ 147 147 for (int i = 0; i < stmts->NumElements(); i++){
stmts->Nth(i)->Emit(); 148 148 stmts->Nth(i)->Emit();
} 149 149 }
150 150
popScope(); 151 151 popScope();
return NULL; 152 152 return NULL;
} 153 153 }
154 154
llvm::Value * DeclStmt::Emit(){ 155 155 llvm::Value * DeclStmt::Emit(){
llvm::Value * val; 156 156 llvm::Value * val;
if (VarDecl * vd = dynamic_cast<VarDecl*>(this->decl)){ 157 157 if (VarDecl * vd = dynamic_cast<VarDecl*>(this->decl)){
val = vd->Emit(); 158 158 val = vd->Emit();
} 159 159 }
else if (FnDecl * fd = dynamic_cast<FnDecl*>(this->decl)){ 160 160 else if (FnDecl * fd = dynamic_cast<FnDecl*>(this->decl)){
val = fd->Emit(); 161 161 val = fd->Emit();
} 162 162 }
else{ 163 163 else{
val = NULL; 164 164 val = NULL;
} 165 165 }
return val; 166 166 return val;
} 167 167 }
168 168
llvm::Value * ConditionalStmt::Emit(){ 169 169 llvm::Value * ConditionalStmt::Emit(){
return NULL; 170 170 return NULL;
} 171 171 }
//for statement 172 172 //for statement
llvm::Value * ForStmt::Emit() 173 173 llvm::Value * ForStmt::Emit()
{ 174 174 {
pushScope(); 175 175 pushScope();
llvm::LLVMContext * context = irgen.GetContext(); 176 176 llvm::LLVMContext * context = irgen.GetContext();
llvm::Function * func = irgen.GetFunction(); 177 177 llvm::Function * func = irgen.GetFunction();
llvm::BasicBlock * headBlock = llvm::BasicBlock::Create(*context, "headBlock", func); 178 178 llvm::BasicBlock * headBlock = llvm::BasicBlock::Create(*context, "headBlock", func);
llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", func); 179 179 llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", func);
llvm::BasicBlock * incBlock = llvm::BasicBlock::Create(*context, "incBlock", func); 180 180 llvm::BasicBlock * incBlock = llvm::BasicBlock::Create(*context, "incBlock", func);
llvm::BasicBlock * bodyBlock = llvm::BasicBlock::Create(*context, "bodyBlock", func); 181 181 llvm::BasicBlock * bodyBlock = llvm::BasicBlock::Create(*context, "bodyBlock", func);
llvm::Value * condition; 182 182 llvm::Value * condition;
183 183
// init and branch to head 184 184 // init and branch to head
init->Emit(); 185 185 init->Emit();
186 186
llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock()); 187 187 llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock());
188 188
// head 189 189 // head
irgen.SetBasicBlock(headBlock); 190 190 irgen.SetBasicBlock(headBlock);
condition = test->Emit(); 191 191 condition = test->Emit();
if(!irgen.GetBasicBlock()->getTerminator()) 192 192 if(!irgen.GetBasicBlock()->getTerminator())
{ 193 193 {
llvm::BranchInst::Create(bodyBlock, footBlock, condition, irgen.GetBasicBlock()); 194 194 llvm::BranchInst::Create(bodyBlock, footBlock, condition, irgen.GetBasicBlock());
} 195 195 }
196 196
// body 197 197 // body
irgen.SetBasicBlock(bodyBlock); 198 198 irgen.SetBasicBlock(bodyBlock);
body->Emit(); 199 199 body->Emit();
if(!irgen.GetBasicBlock()->getTerminator()) 200 200 if(!irgen.GetBasicBlock()->getTerminator())
{ 201 201 {
llvm::BranchInst::Create(incBlock, irgen.GetBasicBlock()); 202 202 llvm::BranchInst::Create(incBlock, irgen.GetBasicBlock());
} 203 203 }
204 204
// step 205 205 // step
irgen.SetBasicBlock(incBlock); 206 206 irgen.SetBasicBlock(incBlock);
step->Emit(); 207 207 step->Emit();
if(!irgen.GetBasicBlock()->getTerminator()) 208 208 if(!irgen.GetBasicBlock()->getTerminator())
{ 209 209 {
llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock()); 210 210 llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock());
} 211 211 }
212 212
irgen.SetBasicBlock(footBlock); 213 213 irgen.SetBasicBlock(footBlock);
popScope(); 214 214 popScope();
return NULL; 215 215 return NULL;
} 216 216 }
//while statement 217 217 //while statement
llvm::Value * WhileStmt::Emit(){ 218 218 llvm::Value * WhileStmt::Emit(){
pushScope(); 219 219 pushScope();
llvm::LLVMContext * context = irgen.GetContext(); 220 220 llvm::LLVMContext * context = irgen.GetContext();
llvm::Function * f = irgen.GetFunction(); 221 221 llvm::Function * f = irgen.GetFunction();
llvm::Value * cond; 222 222 llvm::Value * cond;
223 223
llvm::BasicBlock * headBlock = llvm::BasicBlock::Create(*context, "headBlock", f); 224 224 llvm::BasicBlock * headBlock = llvm::BasicBlock::Create(*context, "headBlock", f);
llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", f); 225 225 llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", f);
llvm::BasicBlock * bodyBlock = llvm::BasicBlock::Create(*context, "bodyBlock", f); 226 226 llvm::BasicBlock * bodyBlock = llvm::BasicBlock::Create(*context, "bodyBlock", f);
llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock()); 227 227 llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock());
228 228
irgen.SetBasicBlock(headBlock); 229 229 irgen.SetBasicBlock(headBlock);
cond = test->Emit(); 230 230 cond = test->Emit();
if(!irgen.GetBasicBlock()->getTerminator()) 231 231 if(!irgen.GetBasicBlock()->getTerminator())
{ 232 232 {
llvm::BranchInst::Create(bodyBlock, footBlock, cond, irgen.GetBasicBlock()); // given in the slides 233 233 llvm::BranchInst::Create(bodyBlock, footBlock, cond, irgen.GetBasicBlock()); // given in the slides
} 234 234 }
235 235
irgen.SetBasicBlock(bodyBlock); 236 236 irgen.SetBasicBlock(bodyBlock);
body->Emit(); 237 237 body->Emit();
if(!irgen.GetBasicBlock()->getTerminator()) 238 238 if(!irgen.GetBasicBlock()->getTerminator())
{ 239 239 {
llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock()); // given in the slides 240 240 llvm::BranchInst::Create(headBlock, irgen.GetBasicBlock()); // given in the slides
} 241 241 }
242 242
243 243
irgen.SetBasicBlock(footBlock); 244 244 irgen.SetBasicBlock(footBlock);
popScope(); 245 245 popScope();
return NULL; 246 246 return NULL;
} 247 247 }
248 248
249 249
//if statement 250 250 //if statement
llvm::Value * IfStmt::Emit(){ 251 251 llvm::Value * IfStmt::Emit(){
llvm::LLVMContext * context = irgen.GetContext(); 252 252 llvm::LLVMContext * context = irgen.GetContext();
llvm::Function * func = irgen.GetFunction(); 253 253 llvm::Function * func = irgen.GetFunction();
llvm::BasicBlock * elseBlock = NULL; 254 254 llvm::BasicBlock * elseBlock = NULL;
llvm::BasicBlock * thenBlock = llvm::BasicBlock::Create(*context, "thenBlock", func); 255 255 llvm::BasicBlock * thenBlock = llvm::BasicBlock::Create(*context, "thenBlock", func);
llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", func); 256 256 llvm::BasicBlock * footBlock = llvm::BasicBlock::Create(*context, "footBlock", func);
llvm::Value * val; 257 257 llvm::Value * val;
llvm::Value * condition = test->Emit(); 258 258 llvm::Value * condition = test->Emit();
if(elseBody) 259 259 if(elseBody)
{ 260 260 {
elseBlock = llvm::BasicBlock::Create(*context, "elseBlock", func); 261 261 elseBlock = llvm::BasicBlock::Create(*context, "elseBlock", func);
} 262 262 }
263 263
val = llvm::BranchInst::Create(thenBlock, elseBody ? elseBlock : footBlock, condition, irgen.GetBasicBlock()); 264 264 val = llvm::BranchInst::Create(thenBlock, elseBody ? elseBlock : footBlock, condition, irgen.GetBasicBlock());
pushScope(); 265 265 pushScope();
irgen.SetBasicBlock(thenBlock); 266 266 irgen.SetBasicBlock(thenBlock);
body->Emit(); 267 267 body->Emit();
268 268
if(!irgen.GetBasicBlock()->getTerminator()) 269 269 if(!irgen.GetBasicBlock()->getTerminator())
{ 270 270 {
val = llvm::BranchInst::Create(footBlock, irgen.GetBasicBlock()); 271 271 val = llvm::BranchInst::Create(footBlock, irgen.GetBasicBlock());
} 272 272 }
popScope(); 273 273 popScope();
274 274
if(elseBody) 275 275 if(elseBody)
{ 276 276 {
pushScope(); 277 277 pushScope();
irgen.SetBasicBlock(elseBlock); 278 278 irgen.SetBasicBlock(elseBlock);
elseBody->Emit(); 279 279 elseBody->Emit();
280 280
if(!irgen.GetBasicBlock()->getTerminator()) 281 281 if(!irgen.GetBasicBlock()->getTerminator())
{ 282 282 {
val = llvm::BranchInst::Create(footBlock, irgen.GetBasicBlock()); 283 283 val = llvm::BranchInst::Create(footBlock, irgen.GetBasicBlock());
} 284 284 }
popScope(); 285 285 popScope();
} 286 286 }
irgen.SetBasicBlock(footBlock); 287 287 irgen.SetBasicBlock(footBlock);
return val; 288 288 return val;
} 289 289 }
290 290
llvm::Value * BreakStmt::Emit(){ 291 291 llvm::Value * BreakStmt::Emit(){
//goes to footer 292 292 //goes to footer
llvm::Value * val; 293 293 llvm::Value * val;
llvm::LLVMContext * context = irgen.GetContext(); 294 294 llvm::LLVMContext * context = irgen.GetContext();
llvm::Function * func = irgen.GetFunction(); 295 295 llvm::Function * func = irgen.GetFunction();
llvm::BasicBlock * breakBlock = llvm::BasicBlock::Create(*context, "breakBlock", func); 296 296 llvm::BasicBlock * breakBlock = llvm::BasicBlock::Create(*context, "breakBlock", func);
val=llvm::BranchInst::Create (breakBlock, irgen.GetBasicBlock()); 297 297 val=llvm::BranchInst::Create (breakBlock, irgen.GetBasicBlock());
return val; 298 298 return val;
} 299 299 }
300 300
llvm::Value * ContinueStmt::Emit(){ 301 301 llvm::Value * ContinueStmt::Emit(){
llvm::Value * val; 302 302 llvm::Value * val;
llvm::LLVMContext * context = irgen.GetContext(); 303 303 llvm::LLVMContext * context = irgen.GetContext();
llvm::Function * func = irgen.GetFunction(); 304 304 llvm::Function * func = irgen.GetFunction();
llvm::BasicBlock * contBlock = llvm::BasicBlock::Create(*context, "contBlock", func); 305 305 llvm::BasicBlock * contBlock = llvm::BasicBlock::Create(*context, "contBlock", func);
val=llvm::BranchInst::Create (contBlock, irgen.GetBasicBlock()); 306 306 val=llvm::BranchInst::Create (contBlock, irgen.GetBasicBlock());
return val; 307 307 return val;
} 308 308 }
309 309
//Not sure 310 310 //Not sure
llvm::Value * ReturnStmt::Emit(){ 311 311 llvm::Value * ReturnStmt::Emit(){
llvm::Value * val; 312 312 llvm::Value * val;
llvm::LLVMContext * context = irgen.GetContext(); 313 313 llvm::LLVMContext * context = irgen.GetContext();
/* irgen.cc - LLVM IR generator 1 1 /* irgen.cc - LLVM IR generator
* 2 2 *
* You can implement any LLVM related functions here. 3 3 * You can implement any LLVM related functions here.
*/ 4 4 */
5 5
#include "irgen.h" 6 6 #include "irgen.h"
7 7
IRGenerator irgen; 8 8 IRGenerator irgen;
9 9
IRGenerator::IRGenerator() : 10 10 IRGenerator::IRGenerator() :
context(NULL), 11 11 context(NULL),
module(NULL), 12 12 module(NULL),
currentFunc(NULL), 13 13 currentFunc(NULL),
currentBB(NULL), 14 14 currentBB(NULL),
currentFooter(NULL), 15 15 currentFooter(NULL),
currentHeader(NULL) 16 16 currentHeader(NULL)
{ 17 17 {
} 18 18 }
19 19
IRGenerator::~IRGenerator() { 20 20 IRGenerator::~IRGenerator() {
} 21 21 }
22 22
llvm::Module *IRGenerator::GetOrCreateModule(const char *moduleID) 23 23 llvm::Module *IRGenerator::GetOrCreateModule(const char *moduleID)
{ 24 24 {
if ( module == NULL ) { 25 25 if ( module == NULL ) {
context = new llvm::LLVMContext(); 26 26 context = new llvm::LLVMContext();
module = new llvm::Module(moduleID, *context); 27 27 module = new llvm::Module(moduleID, *context);
module->setTargetTriple(TargetTriple); 28 28 module->setTargetTriple(TargetTriple);
module->setDataLayout(TargetLayout); 29 29 module->setDataLayout(TargetLayout);
} 30 30 }
return module; 31 31 return module;
} 32 32 }
33 33
void IRGenerator::SetFunction(llvm::Function *func) { 34 34 void IRGenerator::SetFunction(llvm::Function *func) {
currentFunc = func; 35 35 currentFunc = func;
} 36 36 }
37 37
llvm::Function *IRGenerator::GetFunction() const { 38 38 llvm::Function *IRGenerator::GetFunction() const {
return currentFunc; 39 39 return currentFunc;
} 40 40 }
41 41
void IRGenerator::SetBasicBlock(llvm::BasicBlock *bb) { 42 42 void IRGenerator::SetBasicBlock(llvm::BasicBlock *bb) {
currentBB = bb; 43 43 currentBB = bb;
} 44 44 }
45 45
llvm::BasicBlock *IRGenerator::GetBasicBlock() const { 46 46 llvm::BasicBlock *IRGenerator::GetBasicBlock() const {
return currentBB; 47 47 return currentBB;
} 48 48 }
49 49
llvm::Type *IRGenerator::GetIntType() const { 50 50 llvm::Type *IRGenerator::GetIntType() const {
llvm::Type *ty = llvm::Type::getInt32Ty(*context); 51 51 llvm::Type *ty = llvm::Type::getInt32Ty(*context);
return ty; 52 52 return ty;
} 53 53 }
54 54
llvm::Type *IRGenerator::GetBoolType() const { 55 55 llvm::Type *IRGenerator::GetBoolType() const {
llvm::Type *ty = llvm::Type::getInt1Ty(*context); 56 56 llvm::Type *ty = llvm::Type::getInt1Ty(*context);
return ty; 57 57 return ty;
} 58 58 }
59 59
llvm::Type *IRGenerator::GetFloatType() const { 60 60 llvm::Type *IRGenerator::GetFloatType() const {
llvm::Type *ty = llvm::Type::getFloatTy(*context); 61 61 llvm::Type *ty = llvm::Type::getFloatTy(*context);
return ty; 62 62 return ty;
} 63 63 }
64 64
void IRGenerator::SetFootBlock(llvm::BasicBlock *bb) { 65 65 void IRGenerator::SetFooterBlock(llvm::BasicBlock *bb) {
currentFooter = bb; 66 66 currentFooter = bb;
} 67 67 }