summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp')
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index 22b0819cd71..50912109e81 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
std::unique_ptr<ExprAST> RHS)
: Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+
Value *codegen() override;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud