diff options
author | Lang Hames <lhames@gmail.com> | 2016-09-19 23:00:27 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-09-19 23:00:27 +0000 |
commit | 4cd6605af1889123f28956d411c3ec6ca5651eba (patch) | |
tree | c09e4d40eb8b452f3911b876bc89b251e235866a /examples/Kaleidoscope | |
parent | 10b68a36b45fda26e83b6e6eda482611c9ba01c8 (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281945 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples/Kaleidoscope')
-rw-r--r-- | examples/Kaleidoscope/Chapter2/CMakeLists.txt | 4 | ||||
-rw-r--r-- | 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 <cctype> #include <cstdio> #include <cstdlib> @@ -6,18 +7,6 @@ #include <string> #include <vector> -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 <class T, class... Args> -static - typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type - make_unique(Args &&... args) { - return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); -} -} // end namespace helper - //===----------------------------------------------------------------------===// // Lexer //===----------------------------------------------------------------------===// @@ -202,7 +191,7 @@ static std::unique_ptr<ExprAST> ParseExpression(); /// numberexpr ::= number static std::unique_ptr<ExprAST> ParseNumberExpr() { - auto Result = helper::make_unique<NumberExprAST>(NumVal); + auto Result = llvm::make_unique<NumberExprAST>(NumVal); getNextToken(); // consume the number return std::move(Result); } @@ -229,7 +218,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() { getNextToken(); // eat identifier. if (CurTok != '(') // Simple variable ref. - return helper::make_unique<VariableExprAST>(IdName); + return llvm::make_unique<VariableExprAST>(IdName); // Call. getNextToken(); // eat ( @@ -253,7 +242,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() { // Eat the ')'. getNextToken(); - return helper::make_unique<CallExprAST>(IdName, std::move(Args)); + return llvm::make_unique<CallExprAST>(IdName, std::move(Args)); } /// primary @@ -305,8 +294,8 @@ static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec, } // Merge LHS/RHS. - LHS = helper::make_unique<BinaryExprAST>(BinOp, std::move(LHS), - std::move(RHS)); + LHS = llvm::make_unique<BinaryExprAST>(BinOp, std::move(LHS), + std::move(RHS)); } } @@ -342,7 +331,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { // success. getNextToken(); // eat ')'. - return helper::make_unique<PrototypeAST>(FnName, std::move(ArgNames)); + return llvm::make_unique<PrototypeAST>(FnName, std::move(ArgNames)); } /// definition ::= 'def' prototype expression @@ -353,7 +342,7 @@ static std::unique_ptr<FunctionAST> ParseDefinition() { return nullptr; if (auto E = ParseExpression()) - return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E)); + return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E)); return nullptr; } @@ -361,9 +350,9 @@ static std::unique_ptr<FunctionAST> ParseDefinition() { static std::unique_ptr<FunctionAST> ParseTopLevelExpr() { if (auto E = ParseExpression()) { // Make an anonymous proto. - auto Proto = helper::make_unique<PrototypeAST>("__anon_expr", - std::vector<std::string>()); - return helper::make_unique<FunctionAST>(std::move(Proto), std::move(E)); + auto Proto = llvm::make_unique<PrototypeAST>("__anon_expr", + std::vector<std::string>()); + return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E)); } return nullptr; } |