From 5bc3b7d90137fda1d039a0ee5b32ccfbc4522696 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 19 Sep 2016 23:00:27 +0000 Subject: [PATCH] [Kaleidoscope] Make Chapter 2 use llvm::make_unique, rather than a helper. This essentially reverts r251936, minimizing the difference between Chapter2 and Chapter 3, and making Chapter 2's code match the tutorial text. llvm-svn: 281945 --- examples/Kaleidoscope/Chapter2/CMakeLists.txt | 4 +++ examples/Kaleidoscope/Chapter2/toy.cpp | 33 +++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/examples/Kaleidoscope/Chapter2/CMakeLists.txt b/examples/Kaleidoscope/Chapter2/CMakeLists.txt index 6224d9ac864..e4f275d01d4 100644 --- a/examples/Kaleidoscope/Chapter2/CMakeLists.txt +++ b/examples/Kaleidoscope/Chapter2/CMakeLists.txt @@ -1,3 +1,7 @@ +set(LLVM_LINK_COMPONENTS + Support + ) + add_kaleidoscope_chapter(Kaleidoscope-Ch2 toy.cpp ) diff --git a/examples/Kaleidoscope/Chapter2/toy.cpp b/examples/Kaleidoscope/Chapter2/toy.cpp index 31a998faadc..bab34adefde 100644 --- a/examples/Kaleidoscope/Chapter2/toy.cpp +++ b/examples/Kaleidoscope/Chapter2/toy.cpp @@ -1,3 +1,4 @@ +#include "llvm/ADT/STLExtras.h" #include #include #include @@ -6,18 +7,6 @@ #include #include -namespace helper { -// Cloning make_unique here until it's standard in C++14. -// Using a namespace to avoid conflicting with MSVC's std::make_unique (which -// ADL can sometimes find in unqualified calls). -template -static - typename std::enable_if::value, std::unique_ptr>::type - make_unique(Args &&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} -} // end namespace helper - //===----------------------------------------------------------------------===// // Lexer //===----------------------------------------------------------------------===// @@ -202,7 +191,7 @@ static std::unique_ptr ParseExpression(); /// numberexpr ::= number static std::unique_ptr ParseNumberExpr() { - auto Result = helper::make_unique(NumVal); + auto Result = llvm::make_unique(NumVal); getNextToken(); // consume the number return std::move(Result); } @@ -229,7 +218,7 @@ static std::unique_ptr ParseIdentifierExpr() { getNextToken(); // eat identifier. if (CurTok != '(') // Simple variable ref. - return helper::make_unique(IdName); + return llvm::make_unique(IdName); // Call. getNextToken(); // eat ( @@ -253,7 +242,7 @@ static std::unique_ptr ParseIdentifierExpr() { // Eat the ')'. getNextToken(); - return helper::make_unique(IdName, std::move(Args)); + return llvm::make_unique(IdName, std::move(Args)); } /// primary @@ -305,8 +294,8 @@ static std::unique_ptr ParseBinOpRHS(int ExprPrec, } // Merge LHS/RHS. - LHS = helper::make_unique(BinOp, std::move(LHS), - std::move(RHS)); + LHS = llvm::make_unique(BinOp, std::move(LHS), + std::move(RHS)); } } @@ -342,7 +331,7 @@ static std::unique_ptr ParsePrototype() { // success. getNextToken(); // eat ')'. - return helper::make_unique(FnName, std::move(ArgNames)); + return llvm::make_unique(FnName, std::move(ArgNames)); } /// definition ::= 'def' prototype expression @@ -353,7 +342,7 @@ static std::unique_ptr ParseDefinition() { return nullptr; if (auto E = ParseExpression()) - return helper::make_unique(std::move(Proto), std::move(E)); + return llvm::make_unique(std::move(Proto), std::move(E)); return nullptr; } @@ -361,9 +350,9 @@ static std::unique_ptr ParseDefinition() { static std::unique_ptr ParseTopLevelExpr() { if (auto E = ParseExpression()) { // Make an anonymous proto. - auto Proto = helper::make_unique("__anon_expr", - std::vector()); - return helper::make_unique(std::move(Proto), std::move(E)); + auto Proto = llvm::make_unique("__anon_expr", + std::vector()); + return llvm::make_unique(std::move(Proto), std::move(E)); } return nullptr; }