summaryrefslogtreecommitdiff
path: root/node/FunctionNode.cc
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-25 16:14:41 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-25 16:14:41 +0800
commit958a811b18aee04e4795cf003fd8e3db00312c91 (patch)
tree92cbc52f7560af0e08febfe1da38ed657ad29735 /node/FunctionNode.cc
parentc5e9f890dab0e4595482301d77876793c8bceb8c (diff)
finish function calls and lvalue
Diffstat (limited to 'node/FunctionNode.cc')
-rw-r--r--node/FunctionNode.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc
index 3346db0..dfb7eff 100644
--- a/node/FunctionNode.cc
+++ b/node/FunctionNode.cc
@@ -31,15 +31,16 @@ FunctionNode::FunctionNode(
Value FunctionNode::CodeGen() {
llvm::Module* module = context_->GetModule();
llvm::IRBuilder<>* builder = context_->GetBuilder();
- std::vector<llvm::Type*> params(arguments_.size());
+ std::vector<std::shared_ptr<Type>> params(arguments_.size());
std::transform(arguments_.cbegin(), arguments_.cend(), params.begin(),
- [](const Declaration& decl) {
- return std::get<1>(decl)->GetLLVMType();
- });
- llvm::Type* type =
- llvm::FunctionType::get(type_->GetLLVMType(), params, false);
- llvm::FunctionCallee f = module->getOrInsertFunction(name_, type);
- llvm::Function* function = llvm::cast<llvm::Function>(f.getCallee());
+ [](const Declaration& decl) { return std::get<1>(decl); });
+ std::shared_ptr<Type> type =
+ context_->GetTypeManager()->CreateFunctionType(type_, params);
+ context_->AddFunctionType(name_, type);
+ llvm::FunctionType* LLVMType =
+ llvm::cast<llvm::FunctionType>(type->GetLLVMType());
+ llvm::Function* function = llvm::Function::Create(
+ LLVMType, llvm::GlobalValue::ExternalLinkage, name_, *module);
function->setCallingConv(llvm::CallingConv::C);
llvm::BasicBlock* block =
llvm::BasicBlock::Create(GlobalLLVMContext, name_, function);