From 1356c7901a9edaaff445bd9a9eaa667cefbac043 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 19 Aug 2015 18:32:58 +0000 Subject: [PATCH] [Kaleidoscope] More inter-chapter diff reduction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245474 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/LangImpl3.rst | 4 +++- examples/Kaleidoscope/Chapter3/toy.cpp | 4 +++- examples/Kaleidoscope/Chapter4/toy.cpp | 4 +++- examples/Kaleidoscope/Chapter5/toy.cpp | 4 +++- examples/Kaleidoscope/Chapter6/toy.cpp | 1 - 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/tutorial/LangImpl3.rst b/docs/tutorial/LangImpl3.rst index a2d23e7bcf9..d80140ef241 100644 --- a/docs/tutorial/LangImpl3.rst +++ b/docs/tutorial/LangImpl3.rst @@ -131,7 +131,9 @@ are all uniqued together and shared. For this reason, the API uses the Value *VariableExprAST::Codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; - return V ? V : ErrorV("Unknown variable name"); + if (!V) + ErrorV("Unknown variable name"); + return V; } References to variables are also quite simple using LLVM. In the simple diff --git a/examples/Kaleidoscope/Chapter3/toy.cpp b/examples/Kaleidoscope/Chapter3/toy.cpp index 29914aa0331..cb4f75f7917 100644 --- a/examples/Kaleidoscope/Chapter3/toy.cpp +++ b/examples/Kaleidoscope/Chapter3/toy.cpp @@ -398,7 +398,9 @@ Value *NumberExprAST::Codegen() { Value *VariableExprAST::Codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; - return V ? V : ErrorV("Unknown variable name"); + if (!V) + return ErrorV("Unknown variable name"); + return V; } Value *BinaryExprAST::Codegen() { diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp index eba0ab1f27d..9b0d2ecf67c 100644 --- a/examples/Kaleidoscope/Chapter4/toy.cpp +++ b/examples/Kaleidoscope/Chapter4/toy.cpp @@ -642,7 +642,9 @@ Value *NumberExprAST::Codegen() { Value *VariableExprAST::Codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; - return V ? V : ErrorV("Unknown variable name"); + if (!V) + return ErrorV("Unknown variable name"); + return V; } Value *BinaryExprAST::Codegen() { diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp index c191d61d562..da7a81c6776 100644 --- a/examples/Kaleidoscope/Chapter5/toy.cpp +++ b/examples/Kaleidoscope/Chapter5/toy.cpp @@ -532,7 +532,9 @@ Value *NumberExprAST::Codegen() { Value *VariableExprAST::Codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; - return V ? V : ErrorV("Unknown variable name"); + if (!V) + return ErrorV("Unknown variable name"); + return V; } Value *BinaryExprAST::Codegen() { diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp index 87048bb2da4..b4e8397e9e6 100644 --- a/examples/Kaleidoscope/Chapter6/toy.cpp +++ b/examples/Kaleidoscope/Chapter6/toy.cpp @@ -626,7 +626,6 @@ Value *VariableExprAST::Codegen() { Value *V = NamedValues[Name]; if (!V) return ErrorV("Unknown variable name"); - return V; } -- 2.34.1