diff options
Diffstat (limited to 'llvm/examples/Kaleidoscope/Chapter4/toy.cpp')
| -rw-r--r-- | llvm/examples/Kaleidoscope/Chapter4/toy.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp index 836a2053cbe..39b9563bc28 100644 --- a/llvm/examples/Kaleidoscope/Chapter4/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter4/toy.cpp @@ -15,6 +15,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "../include/KaleidoscopeJIT.h" +#include <algorithm> #include <cassert> #include <cctype> #include <cstdint> @@ -103,11 +104,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; }; @@ -117,6 +121,7 @@ class NumberExprAST : public ExprAST { public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -126,6 +131,7 @@ class VariableExprAST : public ExprAST { public: VariableExprAST(const std::string &Name) : Name(Name) {} + Value *codegen() override; }; @@ -138,6 +144,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; }; @@ -150,6 +157,7 @@ public: CallExprAST(const std::string &Callee, std::vector<std::unique_ptr<ExprAST>> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -163,6 +171,7 @@ class PrototypeAST { public: PrototypeAST(const std::string &Name, std::vector<std::string> Args) : Name(Name), Args(std::move(Args)) {} + Function *codegen(); const std::string &getName() const { return Name; } }; @@ -176,8 +185,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 //===----------------------------------------------------------------------===// |

