summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-27 02:08:29 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-27 02:08:29 +0800
commitba1e3fdd1eea618a38e56918912dc966d1e399a8 (patch)
tree0abf1bf045529cc20da9312cbabe32ded31a0103 /node
parente83990754f49ec6eba7b9e1a5ff80a6add5de3a1 (diff)
fix array, string, and constant nodes
Diffstat (limited to 'node')
-rw-r--r--node/DeclNode.cc4
-rw-r--r--node/FunctionNode.cc7
-rw-r--r--node/LiteralNode.cc10
-rw-r--r--node/LiteralNode.hh4
4 files changed, 14 insertions, 11 deletions
diff --git a/node/DeclNode.cc b/node/DeclNode.cc
index 63dc848..0fc3b89 100644
--- a/node/DeclNode.cc
+++ b/node/DeclNode.cc
@@ -1,7 +1,7 @@
-#include "DeclNode.hh"
-
#include <llvm/IR/IRBuilder.h>
+#include "DeclNode.hh"
+
namespace pcc {
VarDeclNode::VarDeclNode(Context* context, VariableList* scope,
std::list<Declaration> decls)
diff --git a/node/FunctionNode.cc b/node/FunctionNode.cc
index e22c8b6..6352b5b 100644
--- a/node/FunctionNode.cc
+++ b/node/FunctionNode.cc
@@ -64,12 +64,15 @@ Value FunctionNode::CodeGen() {
// push the function scope variables
context_->PushScope(&locals_);
body_->CodeGen();
- builder->CreateRet(rv);
+ builder->CreateRet(builder->CreateLoad(type_->GetLLVMType(), rv));
context_->PopScope();
std::string msg;
llvm::raw_string_ostream MsgStream(msg);
llvm::verifyFunction(*function, &MsgStream);
- Log(LogLevel::PCC_INFO, "%s", msg.c_str());
+ MsgStream.flush();
+ if (!msg.empty()) {
+ Log(LogLevel::PCC_INFO, "%s", msg.c_str());
+ }
return nullptr;
}
diff --git a/node/LiteralNode.cc b/node/LiteralNode.cc
index 19a2419..c68a219 100644
--- a/node/LiteralNode.cc
+++ b/node/LiteralNode.cc
@@ -27,10 +27,10 @@ template <> Value RealLiteralNode::CodeGen() {
}
StringLiteralNode::StringLiteralNode(Context* context,
- std::shared_ptr<Type> type, char* begin,
- char* end)
+ std::shared_ptr<Type> type,
+ std::vector<char> value)
: ExprNode(context)
- , value_(begin, end) {
+ , value_(value) {
type_ = type;
}
@@ -41,8 +41,8 @@ Value StringLiteralNode::CodeGen() {
llvm::Constant* ConstantString =
llvm::ConstantDataArray::get(GlobalLLVMContext, value_);
llvm::Constant* GlobalString = new llvm::GlobalVariable(
- type_->GetLLVMType(), true, llvm::GlobalValue::PrivateLinkage,
- ConstantString);
+ *context_->GetModule(), ConstantString->getType(), true,
+ llvm::GlobalValue::PrivateLinkage, ConstantString);
Value ZeroIndex =
llvm::ConstantInt::get(pointer->GetIndexType()->GetLLVMType(), 0, true);
return builder->CreateInBoundsGEP(GlobalString, {ZeroIndex, ZeroIndex});
diff --git a/node/LiteralNode.hh b/node/LiteralNode.hh
index b7fcb38..ca12131 100644
--- a/node/LiteralNode.hh
+++ b/node/LiteralNode.hh
@@ -33,8 +33,8 @@ using RealLiteralNode = LiteralNode<float>;
class StringLiteralNode : public ExprNode {
public:
- StringLiteralNode(Context* context, std::shared_ptr<Type> type, char* begin,
- char* end);
+ StringLiteralNode(Context* context, std::shared_ptr<Type> type,
+ std::vector<char> value);
Value CodeGen() override;
private: