-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeclarations.cpp
More file actions
37 lines (27 loc) · 903 Bytes
/
declarations.cpp
File metadata and controls
37 lines (27 loc) · 903 Bytes
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
#include "declarations.hpp"
static Module* TheModule;
Value* FunctionAST::Codegen(llvm::LLVMContext& context) {
IRBuilder<> Builder(context);
std::vector<const Type*> args;
FunctionType* FT = FunctionType::get(Type::getInt64Ty(context), args, false);
Function* F = Function::Create(FT, Function::ExternalLinkage, name, TheModule);
if (F->getName() != name) {
F->eraseFromParent();
F = TheModule->getFunction(name);
if (!F->empty()) {
printf("redefinition of function");
return NULL;
}
if (F->arg_size() != args.size()) {
printf("redefinition of function with different # args");
return NULL;
}
}
BasicBlock* cur_block = BasicBlock::Create(context, "", F);
std::vector<StatementAST*>::iterator p;
for (p = stmts.begin(); p != stmts.end(); p++) {
(*p)->Codegen(context, F, cur_block);
}
verifyFunction(*F);
return F;
}