diff options
Diffstat (limited to 'llvm/examples/Kaleidoscope')
-rw-r--r-- | llvm/examples/Kaleidoscope/Chapter6/toy.cpp | 50 | ||||
-rw-r--r-- | llvm/examples/Kaleidoscope/Chapter7/toy.cpp | 62 | ||||
-rw-r--r-- | llvm/examples/Kaleidoscope/Chapter8/toy.cpp | 62 |
3 files changed, 87 insertions, 87 deletions
diff --git a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp index bc6ffb77668..532a59a0c91 100644 --- a/llvm/examples/Kaleidoscope/Chapter6/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter6/toy.cpp @@ -272,13 +272,13 @@ static int GetTokPrecedence() { } /// Error* - These are little helper functions for error handling. -std::unique_ptr<ExprAST> Error(const char *Str) { +std::unique_ptr<ExprAST> LogError(const char *Str) { fprintf(stderr, "Error: %s\n", Str); return nullptr; } -std::unique_ptr<PrototypeAST> ErrorP(const char *Str) { - Error(Str); +std::unique_ptr<PrototypeAST> LogErrorP(const char *Str) { + LogError(Str); return nullptr; } @@ -299,7 +299,7 @@ static std::unique_ptr<ExprAST> ParseParenExpr() { return nullptr; if (CurTok != ')') - return Error("expected ')'"); + return LogError("expected ')'"); getNextToken(); // eat ). return V; } @@ -329,7 +329,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() { break; if (CurTok != ',') - return Error("Expected ')' or ',' in argument list"); + return LogError("Expected ')' or ',' in argument list"); getNextToken(); } } @@ -350,7 +350,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_then) - return Error("expected then"); + return LogError("expected then"); getNextToken(); // eat the then auto Then = ParseExpression(); @@ -358,7 +358,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_else) - return Error("expected else"); + return LogError("expected else"); getNextToken(); @@ -375,20 +375,20 @@ static std::unique_ptr<ExprAST> ParseForExpr() { getNextToken(); // eat the for. if (CurTok != tok_identifier) - return Error("expected identifier after for"); + return LogError("expected identifier after for"); std::string IdName = IdentifierStr; getNextToken(); // eat identifier. if (CurTok != '=') - return Error("expected '=' after for"); + return LogError("expected '=' after for"); getNextToken(); // eat '='. auto Start = ParseExpression(); if (!Start) return nullptr; if (CurTok != ',') - return Error("expected ',' after for start value"); + return LogError("expected ',' after for start value"); getNextToken(); auto End = ParseExpression(); @@ -405,7 +405,7 @@ static std::unique_ptr<ExprAST> ParseForExpr() { } if (CurTok != tok_in) - return Error("expected 'in' after for"); + return LogError("expected 'in' after for"); getNextToken(); // eat 'in'. auto Body = ParseExpression(); @@ -425,7 +425,7 @@ static std::unique_ptr<ExprAST> ParseForExpr() { static std::unique_ptr<ExprAST> ParsePrimary() { switch (CurTok) { default: - return Error("unknown token when expecting an expression"); + return LogError("unknown token when expecting an expression"); case tok_identifier: return ParseIdentifierExpr(); case tok_number: @@ -515,7 +515,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { switch (CurTok) { default: - return ErrorP("Expected function name in prototype"); + return LogErrorP("Expected function name in prototype"); case tok_identifier: FnName = IdentifierStr; Kind = 0; @@ -524,7 +524,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_unary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected unary operator"); + return LogErrorP("Expected unary operator"); FnName = "unary"; FnName += (char)CurTok; Kind = 1; @@ -533,7 +533,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_binary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected binary operator"); + return LogErrorP("Expected binary operator"); FnName = "binary"; FnName += (char)CurTok; Kind = 2; @@ -542,7 +542,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { // Read the precedence if present. if (CurTok == tok_number) { if (NumVal < 1 || NumVal > 100) - return ErrorP("Invalid precedecnce: must be 1..100"); + return LogErrorP("Invalid precedecnce: must be 1..100"); BinaryPrecedence = (unsigned)NumVal; getNextToken(); } @@ -550,20 +550,20 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { } if (CurTok != '(') - return ErrorP("Expected '(' in prototype"); + return LogErrorP("Expected '(' in prototype"); std::vector<std::string> ArgNames; while (getNextToken() == tok_identifier) ArgNames.push_back(IdentifierStr); if (CurTok != ')') - return ErrorP("Expected ')' in prototype"); + return LogErrorP("Expected ')' in prototype"); // success. getNextToken(); // eat ')'. // Verify right number of names for operator. if (Kind && ArgNames.size() != Kind) - return ErrorP("Invalid number of operands for operator"); + return LogErrorP("Invalid number of operands for operator"); return llvm::make_unique<PrototypeAST>(FnName, ArgNames, Kind != 0, BinaryPrecedence); @@ -609,8 +609,8 @@ static std::unique_ptr<legacy::FunctionPassManager> TheFPM; static std::unique_ptr<KaleidoscopeJIT> TheJIT; static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos; -Value *ErrorV(const char *Str) { - Error(Str); +Value *LogErrorV(const char *Str) { + LogError(Str); return nullptr; } @@ -637,7 +637,7 @@ Value *VariableExprAST::codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; if (!V) - return ErrorV("Unknown variable name"); + return LogErrorV("Unknown variable name"); return V; } @@ -648,7 +648,7 @@ Value *UnaryExprAST::codegen() { Function *F = getFunction(std::string("unary") + Opcode); if (!F) - return ErrorV("Unknown unary operator"); + return LogErrorV("Unknown unary operator"); return Builder.CreateCall(F, OperandV, "unop"); } @@ -688,11 +688,11 @@ Value *CallExprAST::codegen() { // Look up the name in the global module table. Function *CalleeF = getFunction(Callee); if (!CalleeF) - return ErrorV("Unknown function referenced"); + return LogErrorV("Unknown function referenced"); // If argument mismatch error. if (CalleeF->arg_size() != Args.size()) - return ErrorV("Incorrect # arguments passed"); + return LogErrorV("Incorrect # arguments passed"); std::vector<Value *> ArgsV; for (unsigned i = 0, e = Args.size(); i != e; ++i) { diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp index 6c208792756..5cd062a1b5b 100644 --- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp @@ -290,14 +290,14 @@ static int GetTokPrecedence() { return TokPrec; } -/// Error* - These are little helper functions for error handling. -std::unique_ptr<ExprAST> Error(const char *Str) { +/// LogError* - These are little helper functions for error handling. +std::unique_ptr<ExprAST> LogError(const char *Str) { fprintf(stderr, "Error: %s\n", Str); return nullptr; } -std::unique_ptr<PrototypeAST> ErrorP(const char *Str) { - Error(Str); +std::unique_ptr<PrototypeAST> LogErrorP(const char *Str) { + LogError(Str); return nullptr; } @@ -318,7 +318,7 @@ static std::unique_ptr<ExprAST> ParseParenExpr() { return nullptr; if (CurTok != ')') - return Error("expected ')'"); + return LogError("expected ')'"); getNextToken(); // eat ). return V; } @@ -348,7 +348,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() { break; if (CurTok != ',') - return Error("Expected ')' or ',' in argument list"); + return LogError("Expected ')' or ',' in argument list"); getNextToken(); } } @@ -369,7 +369,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_then) - return Error("expected then"); + return LogError("expected then"); getNextToken(); // eat the then auto Then = ParseExpression(); @@ -377,7 +377,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_else) - return Error("expected else"); + return LogError("expected else"); getNextToken(); @@ -394,20 +394,20 @@ static std::unique_ptr<ExprAST> ParseForExpr() { getNextToken(); // eat the for. if (CurTok != tok_identifier) - return Error("expected identifier after for"); + return LogError("expected identifier after for"); std::string IdName = IdentifierStr; getNextToken(); // eat identifier. if (CurTok != '=') - return Error("expected '=' after for"); + return LogError("expected '=' after for"); getNextToken(); // eat '='. auto Start = ParseExpression(); if (!Start) return nullptr; if (CurTok != ',') - return Error("expected ',' after for start value"); + return LogError("expected ',' after for start value"); getNextToken(); auto End = ParseExpression(); @@ -424,7 +424,7 @@ static std::unique_ptr<ExprAST> ParseForExpr() { } if (CurTok != tok_in) - return Error("expected 'in' after for"); + return LogError("expected 'in' after for"); getNextToken(); // eat 'in'. auto Body = ParseExpression(); @@ -444,7 +444,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { // At least one variable name is required. if (CurTok != tok_identifier) - return Error("expected identifier after var"); + return LogError("expected identifier after var"); while (1) { std::string Name = IdentifierStr; @@ -468,12 +468,12 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { getNextToken(); // eat the ','. if (CurTok != tok_identifier) - return Error("expected identifier list after var"); + return LogError("expected identifier list after var"); } // At this point, we have to have 'in'. if (CurTok != tok_in) - return Error("expected 'in' keyword after 'var'"); + return LogError("expected 'in' keyword after 'var'"); getNextToken(); // eat 'in'. auto Body = ParseExpression(); @@ -493,7 +493,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { static std::unique_ptr<ExprAST> ParsePrimary() { switch (CurTok) { default: - return Error("unknown token when expecting an expression"); + return LogError("unknown token when expecting an expression"); case tok_identifier: return ParseIdentifierExpr(); case tok_number: @@ -585,7 +585,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { switch (CurTok) { default: - return ErrorP("Expected function name in prototype"); + return LogErrorP("Expected function name in prototype"); case tok_identifier: FnName = IdentifierStr; Kind = 0; @@ -594,7 +594,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_unary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected unary operator"); + return LogErrorP("Expected unary operator"); FnName = "unary"; FnName += (char)CurTok; Kind = 1; @@ -603,7 +603,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_binary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected binary operator"); + return LogErrorP("Expected binary operator"); FnName = "binary"; FnName += (char)CurTok; Kind = 2; @@ -612,7 +612,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { // Read the precedence if present. if (CurTok == tok_number) { if (NumVal < 1 || NumVal > 100) - return ErrorP("Invalid precedecnce: must be 1..100"); + return LogErrorP("Invalid precedecnce: must be 1..100"); BinaryPrecedence = (unsigned)NumVal; getNextToken(); } @@ -620,20 +620,20 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { } if (CurTok != '(') - return ErrorP("Expected '(' in prototype"); + return LogErrorP("Expected '(' in prototype"); std::vector<std::string> ArgNames; while (getNextToken() == tok_identifier) ArgNames.push_back(IdentifierStr); if (CurTok != ')') - return ErrorP("Expected ')' in prototype"); + return LogErrorP("Expected ')' in prototype"); // success. getNextToken(); // eat ')'. // Verify right number of names for operator. if (Kind && ArgNames.size() != Kind) - return ErrorP("Invalid number of operands for operator"); + return LogErrorP("Invalid number of operands for operator"); return llvm::make_unique<PrototypeAST>(FnName, ArgNames, Kind != 0, BinaryPrecedence); @@ -679,8 +679,8 @@ static std::unique_ptr<legacy::FunctionPassManager> TheFPM; static std::unique_ptr<KaleidoscopeJIT> TheJIT; static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos; -Value *ErrorV(const char *Str) { - Error(Str); +Value *LogErrorV(const char *Str) { + LogError(Str); return nullptr; } @@ -717,7 +717,7 @@ Value *VariableExprAST::codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; if (!V) - return ErrorV("Unknown variable name"); + return LogErrorV("Unknown variable name"); // Load the value. return Builder.CreateLoad(V, Name.c_str()); @@ -730,7 +730,7 @@ Value *UnaryExprAST::codegen() { Function *F = getFunction(std::string("unary") + Opcode); if (!F) - return ErrorV("Unknown unary operator"); + return LogErrorV("Unknown unary operator"); return Builder.CreateCall(F, OperandV, "unop"); } @@ -744,7 +744,7 @@ Value *BinaryExprAST::codegen() { // dynamic_cast for automatic error checking. VariableExprAST *LHSE = static_cast<VariableExprAST *>(LHS.get()); if (!LHSE) - return ErrorV("destination of '=' must be a variable"); + return LogErrorV("destination of '=' must be a variable"); // Codegen the RHS. Value *Val = RHS->codegen(); if (!Val) @@ -753,7 +753,7 @@ Value *BinaryExprAST::codegen() { // Look up the name. Value *Variable = NamedValues[LHSE->getName()]; if (!Variable) - return ErrorV("Unknown variable name"); + return LogErrorV("Unknown variable name"); Builder.CreateStore(Val, Variable); return Val; @@ -793,11 +793,11 @@ Value *CallExprAST::codegen() { // Look up the name in the global module table. Function *CalleeF = getFunction(Callee); if (!CalleeF) - return ErrorV("Unknown function referenced"); + return LogErrorV("Unknown function referenced"); // If argument mismatch error. if (CalleeF->arg_size() != Args.size()) - return ErrorV("Incorrect # arguments passed"); + return LogErrorV("Incorrect # arguments passed"); std::vector<Value *> ArgsV; for (unsigned i = 0, e = Args.size(); i != e; ++i) { diff --git a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp index 289209b3df4..31a83861a10 100644 --- a/llvm/examples/Kaleidoscope/Chapter8/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter8/toy.cpp @@ -426,14 +426,14 @@ static int GetTokPrecedence() { return TokPrec; } -/// Error* - These are little helper functions for error handling. -std::unique_ptr<ExprAST> Error(const char *Str) { +/// LogError* - These are little helper functions for error handling. +std::unique_ptr<ExprAST> LogError(const char *Str) { fprintf(stderr, "Error: %s\n", Str); return nullptr; } -std::unique_ptr<PrototypeAST> ErrorP(const char *Str) { - Error(Str); +std::unique_ptr<PrototypeAST> LogErrorP(const char *Str) { + LogError(Str); return nullptr; } @@ -454,7 +454,7 @@ static std::unique_ptr<ExprAST> ParseParenExpr() { return nullptr; if (CurTok != ')') - return Error("expected ')'"); + return LogError("expected ')'"); getNextToken(); // eat ). return V; } @@ -486,7 +486,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() { break; if (CurTok != ',') - return Error("Expected ')' or ',' in argument list"); + return LogError("Expected ')' or ',' in argument list"); getNextToken(); } } @@ -509,7 +509,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_then) - return Error("expected then"); + return LogError("expected then"); getNextToken(); // eat the then auto Then = ParseExpression(); @@ -517,7 +517,7 @@ static std::unique_ptr<ExprAST> ParseIfExpr() { return nullptr; if (CurTok != tok_else) - return Error("expected else"); + return LogError("expected else"); getNextToken(); @@ -534,20 +534,20 @@ static std::unique_ptr<ExprAST> ParseForExpr() { getNextToken(); // eat the for. if (CurTok != tok_identifier) - return Error("expected identifier after for"); + return LogError("expected identifier after for"); std::string IdName = IdentifierStr; getNextToken(); // eat identifier. if (CurTok != '=') - return Error("expected '=' after for"); + return LogError("expected '=' after for"); getNextToken(); // eat '='. auto Start = ParseExpression(); if (!Start) return nullptr; if (CurTok != ',') - return Error("expected ',' after for start value"); + return LogError("expected ',' after for start value"); getNextToken(); auto End = ParseExpression(); @@ -564,7 +564,7 @@ static std::unique_ptr<ExprAST> ParseForExpr() { } if (CurTok != tok_in) - return Error("expected 'in' after for"); + return LogError("expected 'in' after for"); getNextToken(); // eat 'in'. auto Body = ParseExpression(); @@ -584,7 +584,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { // At least one variable name is required. if (CurTok != tok_identifier) - return Error("expected identifier after var"); + return LogError("expected identifier after var"); while (1) { std::string Name = IdentifierStr; @@ -608,12 +608,12 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { getNextToken(); // eat the ','. if (CurTok != tok_identifier) - return Error("expected identifier list after var"); + return LogError("expected identifier list after var"); } // At this point, we have to have 'in'. if (CurTok != tok_in) - return Error("expected 'in' keyword after 'var'"); + return LogError("expected 'in' keyword after 'var'"); getNextToken(); // eat 'in'. auto Body = ParseExpression(); @@ -633,7 +633,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() { static std::unique_ptr<ExprAST> ParsePrimary() { switch (CurTok) { default: - return Error("unknown token when expecting an expression"); + return LogError("unknown token when expecting an expression"); case tok_identifier: return ParseIdentifierExpr(); case tok_number: @@ -728,7 +728,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { switch (CurTok) { default: - return ErrorP("Expected function name in prototype"); + return LogErrorP("Expected function name in prototype"); case tok_identifier: FnName = IdentifierStr; Kind = 0; @@ -737,7 +737,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_unary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected unary operator"); + return LogErrorP("Expected unary operator"); FnName = "unary"; FnName += (char)CurTok; Kind = 1; @@ -746,7 +746,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { case tok_binary: getNextToken(); if (!isascii(CurTok)) - return ErrorP("Expected binary operator"); + return LogErrorP("Expected binary operator"); FnName = "binary"; FnName += (char)CurTok; Kind = 2; @@ -755,7 +755,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { // Read the precedence if present. if (CurTok == tok_number) { if (NumVal < 1 || NumVal > 100) - return ErrorP("Invalid precedecnce: must be 1..100"); + return LogErrorP("Invalid precedecnce: must be 1..100"); BinaryPrecedence = (unsigned)NumVal; getNextToken(); } @@ -763,20 +763,20 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() { } if (CurTok != '(') - return ErrorP("Expected '(' in prototype"); + return LogErrorP("Expected '(' in prototype"); std::vector<std::string> ArgNames; while (getNextToken() == tok_identifier) ArgNames.push_back(IdentifierStr); if (CurTok != ')') - return ErrorP("Expected ')' in prototype"); + return LogErrorP("Expected ')' in prototype"); // success. getNextToken(); // eat ')'. // Verify right number of names for operator. if (Kind && ArgNames.size() != Kind) - return ErrorP("Invalid number of operands for operator"); + return LogErrorP("Invalid number of operands for operator"); return llvm::make_unique<PrototypeAST>(FnLoc, FnName, ArgNames, Kind != 0, BinaryPrecedence); @@ -860,8 +860,8 @@ static std::map<std::string, AllocaInst *> NamedValues; static std::unique_ptr<KaleidoscopeJIT> TheJIT; static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos; -Value *ErrorV(const char *Str) { - Error(Str); +Value *LogErrorV(const char *Str) { + LogError(Str); return nullptr; } @@ -899,7 +899,7 @@ Value *VariableExprAST::codegen() { // Look this variable up in the function. Value *V = NamedValues[Name]; if (!V) - return ErrorV("Unknown variable name"); + return LogErrorV("Unknown variable name"); KSDbgInfo.emitLocation(this); // Load the value. @@ -913,7 +913,7 @@ Value *UnaryExprAST::codegen() { Function *F = getFunction(std::string("unary") + Opcode); if (!F) - return ErrorV("Unknown unary operator"); + return LogErrorV("Unknown unary operator"); KSDbgInfo.emitLocation(this); return Builder.CreateCall(F, OperandV, "unop"); @@ -930,7 +930,7 @@ Value *BinaryExprAST::codegen() { // dynamic_cast for automatic error checking. VariableExprAST *LHSE = static_cast<VariableExprAST *>(LHS.get()); if (!LHSE) - return ErrorV("destination of '=' must be a variable"); + return LogErrorV("destination of '=' must be a variable"); // Codegen the RHS. Value *Val = RHS->codegen(); if (!Val) @@ -939,7 +939,7 @@ Value *BinaryExprAST::codegen() { // Look up the name. Value *Variable = NamedValues[LHSE->getName()]; if (!Variable) - return ErrorV("Unknown variable name"); + return LogErrorV("Unknown variable name"); Builder.CreateStore(Val, Variable); return Val; @@ -981,11 +981,11 @@ Value *CallExprAST::codegen() { // Look up the name in the global module table. Function *CalleeF = getFunction(Callee); if (!CalleeF) - return ErrorV("Unknown function referenced"); + return LogErrorV("Unknown function referenced"); // If argument mismatch error. if (CalleeF->arg_size() != Args.size()) - return ErrorV("Incorrect # arguments passed"); + return LogErrorV("Incorrect # arguments passed"); std::vector<Value *> ArgsV; for (unsigned i = 0, e = Args.size(); i != e; ++i) { |