summaryrefslogtreecommitdiffstats
path: root/llvm/docs/tutorial/LangImpl7.rst
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-08-19 18:15:58 +0000
committerLang Hames <lhames@gmail.com>2015-08-19 18:15:58 +0000
commit59b0da886efd85ed8b93c74d3e32da7e7252e4a0 (patch)
tree0f55d1804f4c34aa4bdfa43ce9a8fb80fd2b4ab9 /llvm/docs/tutorial/LangImpl7.rst
parentbe6e0539381fa5aab0de22bd598688973b72ab85 (diff)
downloadbcm5719-llvm-59b0da886efd85ed8b93c74d3e32da7e7252e4a0.tar.gz
bcm5719-llvm-59b0da886efd85ed8b93c74d3e32da7e7252e4a0.zip
[Kaleidoscope] Clang-format the Kaleidoscope tutorials.
Also reduces changes between tutorial chapters. llvm-svn: 245472
Diffstat (limited to 'llvm/docs/tutorial/LangImpl7.rst')
-rw-r--r--llvm/docs/tutorial/LangImpl7.rst58
1 files changed, 39 insertions, 19 deletions
diff --git a/llvm/docs/tutorial/LangImpl7.rst b/llvm/docs/tutorial/LangImpl7.rst
index 33f48535f16..8c35f2ac019 100644
--- a/llvm/docs/tutorial/LangImpl7.rst
+++ b/llvm/docs/tutorial/LangImpl7.rst
@@ -358,7 +358,8 @@ from the stack slot:
Value *VariableExprAST::Codegen() {
// Look this variable up in the function.
Value *V = NamedValues[Name];
- if (V == 0) return ErrorV("Unknown variable name");
+ if (!V)
+ return ErrorV("Unknown variable name");
// Load the value.
return Builder.CreateLoad(V, Name.c_str());
@@ -378,7 +379,8 @@ the unabridged code):
// Emit the start code first, without 'variable' in scope.
Value *StartVal = Start->Codegen();
- if (StartVal == 0) return 0;
+ if (!StartVal)
+ return nullptr;
// Store the value into the alloca.
Builder.CreateStore(StartVal, Alloca);
@@ -386,7 +388,8 @@ the unabridged code):
// Compute the end condition.
Value *EndCond = End->Codegen();
- if (EndCond == 0) return EndCond;
+ if (!EndCond)
+ return nullptr;
// Reload, increment, and restore the alloca. This handles the case where
// the body of the loop mutates the variable.
@@ -588,11 +591,13 @@ allowed.
// Codegen the RHS.
Value *Val = RHS->Codegen();
- if (Val == 0) return 0;
+ if (!Val)
+ return nullptr;
// Look up the name.
Value *Variable = NamedValues[LHSE->getName()];
- if (Variable == 0) return ErrorV("Unknown variable name");
+ if (!Variable)
+ return ErrorV("Unknown variable name");
Builder.CreateStore(Val, Variable);
return Val;
@@ -649,10 +654,14 @@ this:
...
static int gettok() {
...
- if (IdentifierStr == "in") return tok_in;
- if (IdentifierStr == "binary") return tok_binary;
- if (IdentifierStr == "unary") return tok_unary;
- if (IdentifierStr == "var") return tok_var;
+ if (IdentifierStr == "in")
+ return tok_in;
+ if (IdentifierStr == "binary")
+ return tok_binary;
+ if (IdentifierStr == "unary")
+ return tok_unary;
+ if (IdentifierStr == "var")
+ return tok_var;
return tok_identifier;
...
@@ -665,6 +674,7 @@ var/in, it looks like this:
class VarExprAST : public ExprAST {
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames;
std::unique_ptr<ExprAST> Body;
+
public:
VarExprAST(std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> body)
@@ -692,13 +702,20 @@ do is add it as a primary expression:
/// ::= varexpr
static std::unique_ptr<ExprAST> ParsePrimary() {
switch (CurTok) {
- default: return Error("unknown token when expecting an expression");
- case tok_identifier: return ParseIdentifierExpr();
- case tok_number: return ParseNumberExpr();
- case '(': return ParseParenExpr();
- case tok_if: return ParseIfExpr();
- case tok_for: return ParseForExpr();
- case tok_var: return ParseVarExpr();
+ default:
+ return Error("unknown token when expecting an expression");
+ case tok_identifier:
+ return ParseIdentifierExpr();
+ case tok_number:
+ return ParseNumberExpr();
+ case '(':
+ return ParseParenExpr();
+ case tok_if:
+ return ParseIfExpr();
+ case tok_for:
+ return ParseForExpr();
+ case tok_var:
+ return ParseVarExpr();
}
}
@@ -756,7 +773,8 @@ AST node:
getNextToken(); // eat 'in'.
auto Body = ParseExpression();
- if (!Body) return nullptr;
+ if (!Body)
+ return nullptr;
return llvm::make_unique<VarExprAST>(std::move(VarNames),
std::move(Body));
@@ -791,7 +809,8 @@ previous value that we replace in OldBindings.
Value *InitVal;
if (Init) {
InitVal = Init->Codegen();
- if (InitVal == 0) return 0;
+ if (!InitVal)
+ return nullptr;
} else { // If not specified, use 0.0.
InitVal = ConstantFP::get(getGlobalContext(), APFloat(0.0));
}
@@ -816,7 +835,8 @@ we evaluate the body of the var/in expression:
// Codegen the body, now that all vars are in scope.
Value *BodyVal = Body->Codegen();
- if (BodyVal == 0) return 0;
+ if (!BodyVal)
+ return nullptr;
Finally, before returning, we restore the previous variable bindings:
OpenPOWER on IntegriCloud