From e83990754f49ec6eba7b9e1a5ff80a6add5de3a1 Mon Sep 17 00:00:00 2001 From: Nagi5Yeq Date: Tue, 26 May 2020 00:26:57 +0800 Subject: bugfix & test --- node/FunctionNode.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'node/FunctionNode.cc') 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 #include +#include #include "DeclNode.hh" #include "FunctionNode.hh" +#include "Log.hh" namespace pcc { FunctionNode::FunctionNode( @@ -34,7 +36,7 @@ Value FunctionNode::CodeGen() { std::vector> params(arguments_.size()); std::transform(arguments_.cbegin(), arguments_.cend(), params.begin(), [](const Declaration& decl) { return std::get<1>(decl); }); - std::shared_ptr type = + std::shared_ptr 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; } -- cgit