Index: examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h @@ -93,7 +93,6 @@ void removeModule(ModuleHandle H) { CompileLayer.removeModuleSet(H); } - }; } // end namespace orc Index: examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp +++ 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 #include #include #include @@ -135,11 +133,14 @@ //===----------------------------------------------------------------------===// // 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 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -158,8 +160,9 @@ 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 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -182,6 +186,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -194,6 +199,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -205,6 +211,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -219,6 +226,7 @@ std::unique_ptr 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 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -249,6 +258,7 @@ 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 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h @@ -25,10 +25,13 @@ #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/Support/DynamicLibrary.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/GVN.h" #include #include #include @@ -105,7 +108,6 @@ } private: - std::unique_ptr optimizeModule(std::unique_ptr M) { // Create a function pass manager. auto FPM = llvm::make_unique(M.get()); @@ -124,7 +126,6 @@ return M; } - }; } // end namespace orc Index: examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp +++ examples/Kaleidoscope/BuildingAJIT/Chapter2/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 #include #include #include @@ -135,11 +133,14 @@ //===----------------------------------------------------------------------===// // 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 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -158,8 +160,9 @@ 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 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -182,6 +186,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -194,6 +199,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -205,6 +211,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -219,6 +226,7 @@ std::unique_ptr 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 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -249,6 +258,7 @@ 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 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h @@ -26,12 +26,16 @@ #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/GVN.h" #include #include +#include #include #include @@ -116,7 +120,6 @@ } private: - std::unique_ptr optimizeModule(std::unique_ptr M) { // Create a function pass manager. auto FPM = llvm::make_unique(M.get()); @@ -135,7 +138,6 @@ return M; } - }; } // end namespace orc Index: examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp +++ examples/Kaleidoscope/BuildingAJIT/Chapter3/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 #include #include #include @@ -135,11 +133,14 @@ //===----------------------------------------------------------------------===// // 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 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -158,8 +160,9 @@ 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 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -182,6 +186,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -194,6 +199,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -205,6 +211,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -219,6 +226,7 @@ std::unique_ptr 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 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -249,6 +258,7 @@ 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 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h @@ -26,11 +26,17 @@ #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/GVN.h" #include +#include +#include #include #include #include @@ -47,6 +53,7 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + const PrototypeAST& getProto() const; const std::string& getName() const; llvm::Function *codegen(); @@ -197,7 +204,6 @@ } private: - std::string mangle(const std::string &Name) { std::string MangledName; raw_string_ostream MangledNameStream(MangledName); @@ -223,7 +229,6 @@ return M; } - }; } // end namespace orc Index: examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp +++ examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp @@ -7,16 +7,15 @@ #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/Error.h" +#include "llvm/Support/ErrorHandling.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 #include #include #include @@ -140,7 +139,8 @@ /// ExprAST - Base class for all expression nodes. class ExprAST { public: - virtual ~ExprAST() {} + virtual ~ExprAST() = default; + virtual Value *codegen() = 0; }; @@ -150,6 +150,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -159,8 +160,9 @@ 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. @@ -171,6 +173,7 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -183,6 +186,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -195,6 +199,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -206,6 +211,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -220,6 +226,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -233,6 +240,7 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -250,6 +258,7 @@ 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; } Index: examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h @@ -15,11 +15,12 @@ #define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H #include "RemoteJITUtils.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Triple.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/JITSymbol.h" #include "llvm/ExecutionEngine/RuntimeDyld.h" -#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" @@ -28,11 +29,17 @@ #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Mangler.h" #include "llvm/Support/DynamicLibrary.h" +#include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Scalar/GVN.h" #include +#include +#include #include #include #include @@ -49,6 +56,7 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + const PrototypeAST& getProto() const; const std::string& getName() const; llvm::Function *codegen(); @@ -229,7 +237,6 @@ } private: - std::string mangle(const std::string &Name) { std::string MangledName; raw_string_ostream MangledNameStream(MangledName); @@ -255,7 +262,6 @@ return M; } - }; } // end namespace orc Index: examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h +++ examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h @@ -15,8 +15,10 @@ #define LLVM_TOOLS_LLI_REMOTEJITUTILS_H #include "llvm/ExecutionEngine/Orc/RPCByteChannel.h" -#include "llvm/ExecutionEngine/RTDyldMemoryManager.h" -#include +#include "llvm/Support/Error.h" +#include +#include +#include #if !defined(_MSC_VER) && !defined(__MINGW32__) #include @@ -71,4 +73,4 @@ int InFD, OutFD; }; -#endif +#endif // LLVM_TOOLS_LLI_REMOTEJITUTILS_H Index: examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp =================================================================== --- examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp +++ examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp @@ -7,29 +7,30 @@ #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/CommandLine.h" #include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.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 "RemoteJITUtils.h" +#include #include #include #include #include #include +#include #include #include #include #include #include - #include -#include #include #include @@ -155,7 +156,8 @@ /// ExprAST - Base class for all expression nodes. class ExprAST { public: - virtual ~ExprAST() {} + virtual ~ExprAST() = default; + virtual Value *codegen() = 0; }; @@ -165,6 +167,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -174,8 +177,9 @@ 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. @@ -186,6 +190,7 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -198,6 +203,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -210,6 +216,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -221,6 +228,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -235,6 +243,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -248,6 +257,7 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -265,6 +275,7 @@ 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; } @@ -1229,9 +1240,9 @@ } sockaddr_in servAddr; - bzero(&servAddr, sizeof(servAddr)); + memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = PF_INET; - bcopy(server->h_addr, &servAddr.sin_addr.s_addr, server->h_length); + memcpy(&servAddr.sin_addr.s_addr, server->h_addr, server->h_length); servAddr.sin_port = htons(Port); if (connect(sockfd, reinterpret_cast(&servAddr), sizeof(servAddr)) < 0) { Index: examples/Kaleidoscope/Chapter2/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter2/toy.cpp +++ examples/Kaleidoscope/Chapter2/toy.cpp @@ -1,4 +1,5 @@ #include "llvm/ADT/STLExtras.h" +#include #include #include #include @@ -82,11 +83,13 @@ //===----------------------------------------------------------------------===// // Abstract Syntax Tree (aka Parse Tree) //===----------------------------------------------------------------------===// + namespace { + /// ExprAST - Base class for all expression nodes. class ExprAST { public: - virtual ~ExprAST() {} + virtual ~ExprAST() = default; }; /// NumberExprAST - Expression class for numeric literals like "1.0". @@ -149,6 +152,7 @@ std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter3/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter3/toy.cpp +++ examples/Kaleidoscope/Chapter3/toy.cpp @@ -9,6 +9,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" +#include #include #include #include @@ -94,11 +95,14 @@ //===----------------------------------------------------------------------===// // 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; }; @@ -108,6 +112,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -117,6 +122,7 @@ public: VariableExprAST(const std::string &Name) : Name(Name) {} + Value *codegen() override; }; @@ -129,6 +135,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -141,6 +148,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -154,6 +162,7 @@ public: PrototypeAST(const std::string &Name, std::vector Args) : Name(Name), Args(std::move(Args)) {} + Function *codegen(); const std::string &getName() const { return Name; } }; @@ -167,8 +176,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter4/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter4/toy.cpp +++ 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 #include #include #include @@ -103,11 +104,14 @@ //===----------------------------------------------------------------------===// // 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 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -126,6 +131,7 @@ public: VariableExprAST(const std::string &Name) : Name(Name) {} + Value *codegen() override; }; @@ -138,6 +144,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -150,6 +157,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -163,6 +171,7 @@ public: PrototypeAST(const std::string &Name, std::vector Args) : Name(Name), Args(std::move(Args)) {} + Function *codegen(); const std::string &getName() const { return Name; } }; @@ -176,8 +185,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter5/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter5/toy.cpp +++ examples/Kaleidoscope/Chapter5/toy.cpp @@ -16,6 +16,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "../include/KaleidoscopeJIT.h" +#include #include #include #include @@ -121,11 +122,14 @@ //===----------------------------------------------------------------------===// // 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; }; @@ -135,6 +139,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -144,6 +149,7 @@ public: VariableExprAST(const std::string &Name) : Name(Name) {} + Value *codegen() override; }; @@ -156,6 +162,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -168,6 +175,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -179,6 +187,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -193,6 +202,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -206,6 +216,7 @@ public: PrototypeAST(const std::string &Name, std::vector Args) : Name(Name), Args(std::move(Args)) {} + Function *codegen(); const std::string &getName() const { return Name; } }; @@ -219,8 +230,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter6/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter6/toy.cpp +++ examples/Kaleidoscope/Chapter6/toy.cpp @@ -16,6 +16,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "../include/KaleidoscopeJIT.h" +#include #include #include #include @@ -129,11 +130,14 @@ //===----------------------------------------------------------------------===// // 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; }; @@ -143,6 +147,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -152,6 +157,7 @@ public: VariableExprAST(const std::string &Name) : Name(Name) {} + Value *codegen() override; }; @@ -163,6 +169,7 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -175,6 +182,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -187,6 +195,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -198,6 +207,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -212,6 +222,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -229,6 +240,7 @@ 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; } @@ -252,8 +264,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter7/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter7/toy.cpp +++ examples/Kaleidoscope/Chapter7/toy.cpp @@ -16,6 +16,7 @@ #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "../include/KaleidoscopeJIT.h" +#include #include #include #include @@ -135,11 +136,14 @@ //===----------------------------------------------------------------------===// // 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 +153,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -158,8 +163,9 @@ 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 +176,7 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -182,6 +189,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -194,6 +202,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -205,6 +214,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -219,6 +229,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -232,6 +243,7 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -249,6 +261,7 @@ 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 +285,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===// Index: examples/Kaleidoscope/Chapter8/toy.cpp =================================================================== --- examples/Kaleidoscope/Chapter8/toy.cpp +++ examples/Kaleidoscope/Chapter8/toy.cpp @@ -1,26 +1,33 @@ #include "llvm/ADT/APFloat.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/Analysis/Passes.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/LegacyPassManager.h" -#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" -#include "llvm/Transforms/Scalar.h" +#include +#include #include #include #include #include #include #include +#include #include #include @@ -132,11 +139,14 @@ //===----------------------------------------------------------------------===// // 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; }; @@ -146,6 +156,7 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; }; @@ -155,8 +166,9 @@ 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. @@ -167,6 +179,7 @@ public: UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} + Value *codegen() override; }; @@ -179,6 +192,7 @@ BinaryExprAST(char Op, std::unique_ptr LHS, std::unique_ptr RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} + Value *codegen() override; }; @@ -191,6 +205,7 @@ CallExprAST(const std::string &Callee, std::vector> Args) : Callee(Callee), Args(std::move(Args)) {} + Value *codegen() override; }; @@ -202,6 +217,7 @@ IfExprAST(std::unique_ptr Cond, std::unique_ptr Then, std::unique_ptr Else) : Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} + Value *codegen() override; }; @@ -216,6 +232,7 @@ std::unique_ptr Body) : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -229,6 +246,7 @@ std::vector>> VarNames, std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} + Value *codegen() override; }; @@ -246,6 +264,7 @@ 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; } @@ -269,8 +288,10 @@ FunctionAST(std::unique_ptr Proto, std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} + Function *codegen(); }; + } // end anonymous namespace //===----------------------------------------------------------------------===//