Index: llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter2/toy.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -15,7 +16,7 @@ make_unique(Args &&... args) { return std::unique_ptr(new T(std::forward(args)...)); } -} +} // end namespace helper //===----------------------------------------------------------------------===// // Lexer @@ -234,7 +235,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -277,7 +278,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -407,7 +408,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter3/toy.cpp @@ -1,11 +1,19 @@ +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" #include #include +#include #include +#include #include #include @@ -237,7 +245,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -280,7 +288,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -538,7 +546,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter4/toy.cpp @@ -1,19 +1,29 @@ +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h" +#include #include +#include #include +#include #include +#include #include #include -#include "../include/KaleidoscopeJIT.h" using namespace llvm; using namespace llvm::orc; @@ -244,7 +254,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -287,7 +297,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -577,7 +587,6 @@ // Evaluate a top-level expression into an anonymous function. if (auto FnAST = ParseTopLevelExpr()) { if (FnAST->codegen()) { - // JIT the module containing the anonymous expression, keeping a handle so // we can free it later. auto H = TheJIT->addModule(std::move(TheModule)); @@ -603,7 +612,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter5/toy.cpp @@ -1,19 +1,30 @@ +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h" +#include #include +#include #include +#include #include +#include #include #include -#include "../include/KaleidoscopeJIT.h" using namespace llvm; using namespace llvm::orc; @@ -286,7 +297,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -411,7 +422,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -680,7 +691,7 @@ // Start the PHI node with an entry for Start. PHINode *Variable = - Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str()); + Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName); Variable->addIncoming(StartVal, PreheaderBB); // Within the loop, the variable is defined equal to the PHI node. If it @@ -848,7 +859,6 @@ // Evaluate a top-level expression into an anonymous function. if (auto FnAST = ParseTopLevelExpr()) { if (FnAST->codegen()) { - // JIT the module containing the anonymous expression, keeping a handle so // we can free it later. auto H = TheJIT->addModule(std::move(TheModule)); @@ -874,7 +884,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter6/toy.cpp @@ -1,19 +1,30 @@ +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h" +#include #include +#include #include +#include #include +#include #include #include -#include "../include/KaleidoscopeJIT.h" using namespace llvm; using namespace llvm::orc; @@ -319,7 +330,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -460,7 +471,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -791,7 +802,7 @@ // Start the PHI node with an entry for Start. PHINode *Variable = - Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str()); + Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName); Variable->addIncoming(StartVal, PreheaderBB); // Within the loop, the variable is defined equal to the PHI node. If it @@ -966,7 +977,6 @@ // Evaluate a top-level expression into an anonymous function. if (auto FnAST = ParseTopLevelExpr()) { if (FnAST->codegen()) { - // JIT the module containing the anonymous expression, keeping a handle so // we can free it later. auto H = TheJIT->addModule(std::move(TheModule)); @@ -992,7 +1002,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter7/toy.cpp @@ -1,19 +1,31 @@ +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h" +#include #include +#include #include +#include #include +#include #include +#include #include -#include "../include/KaleidoscopeJIT.h" using namespace llvm; using namespace llvm::orc; @@ -338,7 +350,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -446,7 +458,7 @@ if (CurTok != tok_identifier) return LogError("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -530,7 +542,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -706,8 +718,7 @@ const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, - VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName); } Value *NumberExprAST::codegen() { @@ -1132,7 +1143,6 @@ // Evaluate a top-level expression into an anonymous function. if (auto FnAST = ParseTopLevelExpr()) { if (FnAST->codegen()) { - // JIT the module containing the anonymous expression, keeping a handle so // we can free it later. auto H = TheJIT->addModule(std::move(TheModule)); @@ -1158,7 +1168,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: Index: llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Chapter8/toy.cpp @@ -1,20 +1,36 @@ +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/Analysis/BasicAliasAnalysis.h" -#include "llvm/Analysis/Passes.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DebugLoc.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DIBuilder.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/Host.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Target/TargetMachine.h" +#include "../include/KaleidoscopeJIT.h" +#include #include #include +#include #include +#include #include +#include #include -#include "../include/KaleidoscopeJIT.h" using namespace llvm; using namespace llvm::orc; @@ -84,9 +100,9 @@ } namespace { -class PrototypeAST; class ExprAST; -} +} // end anonymous namespace + static LLVMContext TheContext; static IRBuilder<> Builder(TheContext); struct DebugInfo { @@ -207,6 +223,7 @@ virtual Value *codegen() = 0; int getLine() const { return Loc.Line; } int getCol() const { return Loc.Col; } + virtual raw_ostream &dump(raw_ostream &out, int ind) { return out << ':' << getLine() << ':' << getCol() << '\n'; } @@ -218,10 +235,11 @@ public: NumberExprAST(double Val) : Val(Val) {} + Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { return ExprAST::dump(out << Val, ind); } - Value *codegen() override; }; /// VariableExprAST - Expression class for referencing a variable, like "a". @@ -233,6 +251,7 @@ : ExprAST(Loc), Name(Name) {} const std::string &getName() const { return Name; } Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { return ExprAST::dump(out << Name, ind); } @@ -247,6 +266,7 @@ UnaryExprAST(char Opcode, std::unique_ptr Operand) : Opcode(Opcode), Operand(std::move(Operand)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "unary" << Opcode, ind); Operand->dump(out, ind + 1); @@ -264,6 +284,7 @@ std::unique_ptr RHS) : ExprAST(Loc), Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "binary" << Op, ind); LHS->dump(indent(out, ind) << "LHS:", ind + 1); @@ -282,6 +303,7 @@ std::vector> Args) : ExprAST(Loc), Callee(Callee), Args(std::move(Args)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "call " << Callee, ind); for (const auto &Arg : Args) @@ -300,6 +322,7 @@ : ExprAST(Loc), Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "if", ind); Cond->dump(indent(out, ind) << "Cond:", ind + 1); @@ -321,6 +344,7 @@ : VarName(VarName), Start(std::move(Start)), End(std::move(End)), Step(std::move(Step)), Body(std::move(Body)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "for", ind); Start->dump(indent(out, ind) << "Cond:", ind + 1); @@ -342,6 +366,7 @@ std::unique_ptr Body) : VarNames(std::move(VarNames)), Body(std::move(Body)) {} Value *codegen() override; + raw_ostream &dump(raw_ostream &out, int ind) override { ExprAST::dump(out << "var", ind); for (const auto &NamedVar : VarNames) @@ -392,6 +417,7 @@ std::unique_ptr Body) : Proto(std::move(Proto)), Body(std::move(Body)) {} Function *codegen(); + raw_ostream &dump(raw_ostream &out, int ind) { indent(out, ind) << "FunctionAST\n"; ++ind; @@ -477,7 +503,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { if (auto Arg = ParseExpression()) Args.push_back(std::move(Arg)); else @@ -587,7 +613,7 @@ if (CurTok != tok_identifier) return LogError("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -671,7 +697,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -887,8 +913,7 @@ const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), TheFunction->getEntryBlock().begin()); - return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, - VarName.c_str()); + return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName); } Value *NumberExprAST::codegen() { @@ -1355,7 +1380,7 @@ /// top ::= definition | external | expression | ';' static void MainLoop() { - while (1) { + while (true) { switch (CurTok) { case tok_eof: return; @@ -1430,7 +1455,7 @@ // Currently down as "fib.ks" as a filename since we're redirecting stdin // but we'd like actual source locations. KSDbgInfo.TheCU = DBuilder->createCompileUnit( - dwarf::DW_LANG_C, "fib.ks", ".", "Kaleidoscope Compiler", 0, "", 0); + dwarf::DW_LANG_C, "fib.ks", ".", "Kaleidoscope Compiler", false, "", 0); // Run the main "interpreter loop" now. MainLoop(); Index: llvm/trunk/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp @@ -1,25 +1,44 @@ -#include "llvm/Analysis/Passes.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/RuntimeDyld.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" +#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" +#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #include "llvm/ExecutionEngine/Orc/OrcABISupport.h" -#include "llvm/IR/DataLayout.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IRBuilder.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Target/TargetMachine.h" +#include #include +#include +#include +#include #include #include #include +#include #include #include +#include #include using namespace llvm; @@ -304,7 +323,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { auto Arg = ParseExpression(); if (!Arg) return nullptr; Args.push_back(std::move(Arg)); @@ -430,7 +449,7 @@ if (CurTok != tok_identifier) return ErrorU("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -506,7 +525,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -688,6 +707,7 @@ TargetMachine& getTarget() { return *TM; } void addPrototypeAST(std::unique_ptr P); PrototypeAST* getPrototypeAST(const std::string &Name); + private: typedef std::map> PrototypeMap; @@ -710,7 +730,6 @@ class IRGenContext { public: - IRGenContext(SessionContext &S) : Session(S), M(new Module(GenerateUniqueName("jit_module_"), @@ -727,6 +746,7 @@ Function* getPrototype(const std::string &Name); std::map NamedValues; + private: SessionContext &Session; std::unique_ptr M; @@ -746,9 +766,9 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), - TheFunction->getEntryBlock().begin()); + TheFunction->getEntryBlock().begin()); return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()), - nullptr, VarName.c_str()); + nullptr, VarName); } Value *NumberExprAST::IRGen(IRGenContext &C) const { @@ -1227,7 +1247,6 @@ } private: - // This method searches the FunctionDefs map for a definition of 'Name'. If it // finds one it generates a stub for it and returns the address of the stub. RuntimeDyld::SymbolInfo searchFunctionASTs(const std::string &Name) { @@ -1371,7 +1390,7 @@ SessionContext S(TheContext); KaleidoscopeJIT J(S); - while (1) { + while (true) { switch (CurTok) { case tok_eof: return; case ';': getNextToken(); continue; // ignore top-level semicolons. Index: llvm/trunk/examples/Kaleidoscope/Orc/initial/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Orc/initial/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Orc/initial/toy.cpp @@ -1,24 +1,41 @@ -#include "llvm/Analysis/Passes.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/RuntimeDyld.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" +#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" -#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IRBuilder.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Target/TargetMachine.h" +#include #include +#include +#include +#include #include #include #include +#include #include #include +#include #include using namespace llvm; @@ -177,6 +194,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 *IRGen(IRGenContext &C) const override; std::unique_ptr Cond, Then, Else; @@ -303,7 +321,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { auto Arg = ParseExpression(); if (!Arg) return nullptr; Args.push_back(std::move(Arg)); @@ -429,7 +447,7 @@ if (CurTok != tok_identifier) return ErrorU("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -505,7 +523,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -687,6 +705,7 @@ TargetMachine& getTarget() { return *TM; } void addPrototypeAST(std::unique_ptr P); PrototypeAST* getPrototypeAST(const std::string &Name); + private: typedef std::map> PrototypeMap; @@ -709,7 +728,6 @@ class IRGenContext { public: - IRGenContext(SessionContext &S) : Session(S), M(new Module(GenerateUniqueName("jit_module_"), @@ -726,6 +744,7 @@ Function* getPrototype(const std::string &Name); std::map NamedValues; + private: SessionContext &Session; std::unique_ptr M; @@ -745,9 +764,9 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), - TheFunction->getEntryBlock().begin()); + TheFunction->getEntryBlock().begin()); return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()), - nullptr, VarName.c_str()); + nullptr, VarName); } Value *NumberExprAST::IRGen(IRGenContext &C) const { @@ -1266,7 +1285,7 @@ SessionContext S(TheContext); KaleidoscopeJIT J(S); - while (1) { + while (true) { switch (CurTok) { case tok_eof: return; case ';': getNextToken(); continue; // ignore top-level semicolons. Index: llvm/trunk/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp @@ -1,24 +1,42 @@ -#include "llvm/Analysis/Passes.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/RuntimeDyld.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" +#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.h" +#include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/IRBuilder.h" -#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Target/TargetMachine.h" +#include #include +#include +#include +#include #include #include #include +#include #include #include +#include #include using namespace llvm; @@ -177,6 +195,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 *IRGen(IRGenContext &C) const override; std::unique_ptr Cond, Then, Else; @@ -303,7 +322,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { auto Arg = ParseExpression(); if (!Arg) return nullptr; Args.push_back(std::move(Arg)); @@ -429,7 +448,7 @@ if (CurTok != tok_identifier) return ErrorU("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -505,7 +524,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -687,6 +706,7 @@ TargetMachine& getTarget() { return *TM; } void addPrototypeAST(std::unique_ptr P); PrototypeAST* getPrototypeAST(const std::string &Name); + private: typedef std::map> PrototypeMap; @@ -709,7 +729,6 @@ class IRGenContext { public: - IRGenContext(SessionContext &S) : Session(S), M(new Module(GenerateUniqueName("jit_module_"), @@ -726,6 +745,7 @@ Function* getPrototype(const std::string &Name); std::map NamedValues; + private: SessionContext &Session; std::unique_ptr M; @@ -745,9 +765,9 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), - TheFunction->getEntryBlock().begin()); + TheFunction->getEntryBlock().begin()); return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()), - nullptr, VarName.c_str()); + nullptr, VarName); } Value *NumberExprAST::IRGen(IRGenContext &C) const { @@ -1270,7 +1290,7 @@ SessionContext S(TheContext); KaleidoscopeJIT J(S); - while (1) { + while (true) { switch (CurTok) { case tok_eof: return; case ';': getNextToken(); continue; // ignore top-level semicolons. Index: llvm/trunk/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp =================================================================== --- llvm/trunk/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp +++ llvm/trunk/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp @@ -1,24 +1,41 @@ -#include "llvm/Analysis/Passes.h" +#include "llvm/ADT/APFloat.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/RuntimeDyld.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" +#include "llvm/ExecutionEngine/Orc/JITSymbol.h" #include "llvm/ExecutionEngine/Orc/LambdaResolver.h" #include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h" #include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" -#include "llvm/IR/DataLayout.h" +#include "llvm/IR/BasicBlock.h" +#include "llvm/IR/Constant.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/LegacyPassManager.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/IR/Verifier.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TargetSelect.h" -#include "llvm/Transforms/Scalar.h" +#include "llvm/Target/TargetMachine.h" +#include #include +#include +#include +#include #include #include #include +#include #include #include +#include #include using namespace llvm; @@ -177,6 +194,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 *IRGen(IRGenContext &C) const override; std::unique_ptr Cond, Then, Else; @@ -303,7 +321,7 @@ getNextToken(); // eat ( std::vector> Args; if (CurTok != ')') { - while (1) { + while (true) { auto Arg = ParseExpression(); if (!Arg) return nullptr; Args.push_back(std::move(Arg)); @@ -429,7 +447,7 @@ if (CurTok != tok_identifier) return ErrorU("expected identifier after var"); - while (1) { + while (true) { std::string Name = IdentifierStr; getNextToken(); // eat identifier. @@ -505,7 +523,7 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, std::unique_ptr LHS) { // If this is a binop, find its precedence. - while (1) { + while (true) { int TokPrec = GetTokPrecedence(); // If this is a binop that binds at least as tightly as the current binop, @@ -687,6 +705,7 @@ TargetMachine& getTarget() { return *TM; } void addPrototypeAST(std::unique_ptr P); PrototypeAST* getPrototypeAST(const std::string &Name); + private: typedef std::map> PrototypeMap; @@ -709,7 +728,6 @@ class IRGenContext { public: - IRGenContext(SessionContext &S) : Session(S), M(new Module(GenerateUniqueName("jit_module_"), @@ -726,6 +744,7 @@ Function* getPrototype(const std::string &Name); std::map NamedValues; + private: SessionContext &Session; std::unique_ptr M; @@ -745,9 +764,9 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, const std::string &VarName) { IRBuilder<> TmpB(&TheFunction->getEntryBlock(), - TheFunction->getEntryBlock().begin()); + TheFunction->getEntryBlock().begin()); return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()), - nullptr, VarName.c_str()); + nullptr, VarName); } Value *NumberExprAST::IRGen(IRGenContext &C) const { @@ -1216,7 +1235,6 @@ } private: - // This method searches the FunctionDefs map for a definition of 'Name'. If it // finds one it generates a stub for it and returns the address of the stub. RuntimeDyld::SymbolInfo searchFunctionASTs(const std::string &Name) { @@ -1301,7 +1319,7 @@ SessionContext S(TheContext); KaleidoscopeJIT J(S); - while (1) { + while (true) { switch (CurTok) { case tok_eof: return; case ';': getNextToken(); continue; // ignore top-level semicolons.