summaryrefslogtreecommitdiff
path: root/node/FunctionNode.cc
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-26 00:26:57 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-26 00:26:57 +0800
commite83990754f49ec6eba7b9e1a5ff80a6add5de3a1 (patch)
tree6308b4d0afa5bde2de82e7aa034058302cb1d193 /node/FunctionNode.cc
parent958a811b18aee04e4795cf003fd8e3db00312c91 (diff)
bugfix & test
Diffstat (limited to 'node/FunctionNode.cc')
-rw-r--r--node/FunctionNode.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc
index dfb7eff..e22c8b6 100644
--- a/node/FunctionNode.cc
+++ b/node/FunctionNode.cc
@@ -2,9 +2,11 @@
#include <vector>
#include <llvm/IR/IRBuilder.h>
+#include <llvm/IR/Verifier.h>
#include "DeclNode.hh"
#include "FunctionNode.hh"
+#include "Log.hh"
namespace pcc {
FunctionNode::FunctionNode(
@@ -34,7 +36,7 @@ Value FunctionNode::CodeGen() {
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); });
- std::shared_ptr<Type> type =
+ std::shared_ptr<FunctionType> type =
context_->GetTypeManager()->CreateFunctionType(type_, params);
context_->AddFunctionType(name_, type);
llvm::FunctionType* LLVMType =
@@ -46,7 +48,7 @@ Value FunctionNode::CodeGen() {
llvm::BasicBlock::Create(GlobalLLVMContext, name_, function);
builder->SetInsertPoint(block);
// alloc arguments
- llvm::Function::arg_iterator ArgIt;
+ llvm::Function::arg_iterator ArgIt = function->arg_begin();
for (auto& arg : arguments_) {
Value ArgValue = builder->CreateAlloca(std::get<1>(arg)->GetLLVMType());
builder->CreateStore(ArgIt++, ArgValue);
@@ -64,6 +66,10 @@ Value FunctionNode::CodeGen() {
body_->CodeGen();
builder->CreateRet(rv);
context_->PopScope();
+ std::string msg;
+ llvm::raw_string_ostream MsgStream(msg);
+ llvm::verifyFunction(*function, &MsgStream);
+ Log(LogLevel::PCC_INFO, "%s", msg.c_str());
return nullptr;
}