1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[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
This commit is contained in:
Lang Hames 2016-09-19 23:00:27 +00:00
parent f2d341bf96
commit 5bc3b7d901
2 changed files with 15 additions and 22 deletions

View File

@ -1,3 +1,7 @@
set(LLVM_LINK_COMPONENTS
Support
)
add_kaleidoscope_chapter(Kaleidoscope-Ch2
toy.cpp
)

View File

@ -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;
}