summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorNagi5Yeq <wu@x-nagi.com>2020-05-15 21:16:26 +0800
committerNagi5Yeq <wu@x-nagi.com>2020-05-15 21:16:26 +0800
commit41f6e75e3f26bdcccfcb3910f202452e14653826 (patch)
tree0076a928d4ac9737f8b83b7b6b0c055e5ff4f46a /node
parentd80958f987790f533f5048c2e0e8a1cd5fd9f5a1 (diff)
basic support of types
Diffstat (limited to 'node')
-rw-r--r--node/BaseNode.cc4
-rw-r--r--node/BaseNode.hh9
-rw-r--r--node/ExpressionNode.hh8
-rw-r--r--node/LiteralNode.cc8
-rw-r--r--node/LiteralNode.hh7
5 files changed, 21 insertions, 15 deletions
diff --git a/node/BaseNode.cc b/node/BaseNode.cc
index de38f55..8fe2c5d 100644
--- a/node/BaseNode.cc
+++ b/node/BaseNode.cc
@@ -1,6 +1,6 @@
#include "Node.hh"
namespace pcc {
-BaseNode::BaseNode(Driver* driver)
- : driver_(driver) {}
+BaseNode::BaseNode(Context* context)
+ : context_(context) {}
} // namespace pcc
diff --git a/node/BaseNode.hh b/node/BaseNode.hh
index 60e25bd..4a3746c 100644
--- a/node/BaseNode.hh
+++ b/node/BaseNode.hh
@@ -3,17 +3,16 @@
#include <llvm/IR/Value.h>
-namespace pcc {
-using Value = llvm::Value*;
-class Driver;
+#include "Context.hh"
+namespace pcc {
class BaseNode {
public:
virtual Value CodeGen() = 0;
- BaseNode(Driver* driver);
+ BaseNode(Context* context);
protected:
- Driver* driver_;
+ Context* context_;
};
} // namespace pcc
diff --git a/node/ExpressionNode.hh b/node/ExpressionNode.hh
new file mode 100644
index 0000000..ad31835
--- /dev/null
+++ b/node/ExpressionNode.hh
@@ -0,0 +1,8 @@
+#ifndef PCC_EXPRESSIONNODE_H
+#define PCC_EXPRESSIONNODE_H
+
+#include "BaseNode.hh"
+
+
+
+#endif
diff --git a/node/LiteralNode.cc b/node/LiteralNode.cc
index 1e9c4b7..fedeb36 100644
--- a/node/LiteralNode.cc
+++ b/node/LiteralNode.cc
@@ -6,7 +6,7 @@
namespace pcc {
template <> Value BooleanLiteralNode::CodeGen() {
- llvm::LLVMContext& context = driver_->GetModule()->getContext();
+ llvm::LLVMContext& context = context_->GetModule()->getContext();
if (value_ == true) {
return llvm::ConstantInt::getTrue(context);
} else {
@@ -15,19 +15,19 @@ template <> Value BooleanLiteralNode::CodeGen() {
}
template <> Value IntegerLiteralNode::CodeGen() {
- llvm::LLVMContext& context = driver_->GetModule()->getContext();
+ llvm::LLVMContext& context = context_->GetModule()->getContext();
llvm::APInt value(32, (uint64_t) value_, true);
return llvm::ConstantInt::get(context, value);
}
template <> Value RealLiteralNode::CodeGen() {
- llvm::LLVMContext& context = driver_->GetModule()->getContext();
+ llvm::LLVMContext& context = context_->GetModule()->getContext();
llvm::APFloat value(value_);
return llvm::ConstantFP::get(context, value);
}
template <> Value StringLiteralNode::CodeGen() {
- llvm::Module* module = driver_->GetModule();
+ llvm::Module* module = context_->GetModule();
llvm::LLVMContext& context = module->getContext();
llvm::Constant* str = llvm::ConstantDataArray::getString(context, value_);
llvm::Type* type = str->getType();
diff --git a/node/LiteralNode.hh b/node/LiteralNode.hh
index 1d5c1b8..7c74f27 100644
--- a/node/LiteralNode.hh
+++ b/node/LiteralNode.hh
@@ -9,7 +9,7 @@ namespace pcc {
template <typename Type, typename Construct = Type>
class LiteralNode : public BaseNode {
public:
- LiteralNode(Driver* driver, Construct value);
+ LiteralNode(Context* context, Construct value);
Value CodeGen() override; // type-specific CodeGen() is in the .cc file.
private:
@@ -17,9 +17,8 @@ class LiteralNode : public BaseNode {
};
template <typename Type, typename Construct>
-LiteralNode<Type, Construct>::LiteralNode(Driver* driver,
- Construct value)
- : BaseNode(driver)
+LiteralNode<Type, Construct>::LiteralNode(Context* context, Construct value)
+ : BaseNode(context)
, value_(value) {}
using BooleanLiteralNode = LiteralNode<bool>;