diff options
Diffstat (limited to 'node')
| -rw-r--r-- | node/BaseNode.cc | 4 | ||||
| -rw-r--r-- | node/BaseNode.hh | 9 | ||||
| -rw-r--r-- | node/ExpressionNode.hh | 8 | ||||
| -rw-r--r-- | node/LiteralNode.cc | 8 | ||||
| -rw-r--r-- | node/LiteralNode.hh | 7 |
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>; |
