diff options
author | Erick Tryzelaar <idadesub@users.sourceforge.net> | 2009-09-22 21:14:49 +0000 |
---|---|---|
committer | Erick Tryzelaar <idadesub@users.sourceforge.net> | 2009-09-22 21:14:49 +0000 |
commit | 6e2b34bc14cccfc7194c6fec2e6b134cef64c129 (patch) | |
tree | 9cdb74c7b12d9363dce0d1f4246918689303d880 /llvm/examples | |
parent | ea9b03e6e23408325145ca089e4d7d6386b65a2d (diff) | |
download | bcm5719-llvm-6e2b34bc14cccfc7194c6fec2e6b134cef64c129.tar.gz bcm5719-llvm-6e2b34bc14cccfc7194c6fec2e6b134cef64c129.zip |
Sync c++ kaleidoscope tutorial with test.
llvm-svn: 82572
Diffstat (limited to 'llvm/examples')
-rw-r--r-- | llvm/examples/Kaleidoscope/toy.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/llvm/examples/Kaleidoscope/toy.cpp b/llvm/examples/Kaleidoscope/toy.cpp index 8e02e9ab61f..8b0c321c06c 100644 --- a/llvm/examples/Kaleidoscope/toy.cpp +++ b/llvm/examples/Kaleidoscope/toy.cpp @@ -235,7 +235,7 @@ public: //===----------------------------------------------------------------------===// /// CurTok/getNextToken - Provide a simple token buffer. CurTok is the current -/// token the parser it looking at. getNextToken reads another token from the +/// token the parser is looking at. getNextToken reads another token from the /// lexer and updates CurTok with its results. static int CurTok; static int getNextToken() { @@ -283,9 +283,9 @@ static ExprAST *ParseIdentifierExpr() { ExprAST *Arg = ParseExpression(); if (!Arg) return 0; Args.push_back(Arg); - + if (CurTok == ')') break; - + if (CurTok != ',') return Error("Expected ')' or ',' in argument list"); getNextToken(); @@ -430,7 +430,6 @@ static ExprAST *ParseVarExpr() { return new VarExprAST(VarNames, Body); } - /// primary /// ::= identifierexpr /// ::= numberexpr @@ -516,7 +515,7 @@ static ExprAST *ParseExpression() { static PrototypeAST *ParsePrototype() { std::string FnName; - unsigned Kind = 0; // 0 = identifier, 1 = unary, 2 = binary. + unsigned Kind = 0; // 0 = identifier, 1 = unary, 2 = binary. unsigned BinaryPrecedence = 30; switch (CurTok) { @@ -622,7 +621,6 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction, VarName.c_str()); } - Value *NumberExprAST::Codegen() { return ConstantFP::get(getGlobalContext(), APFloat(Val)); } @@ -647,7 +645,6 @@ Value *UnaryExprAST::Codegen() { return Builder.CreateCall(F, OperandV, "unop"); } - Value *BinaryExprAST::Codegen() { // Special case '=' because we don't want to emit the LHS as an expression. if (Op == '=') { @@ -667,7 +664,6 @@ Value *BinaryExprAST::Codegen() { return Val; } - Value *L = LHS->Codegen(); Value *R = RHS->Codegen(); if (L == 0 || R == 0) return 0; @@ -908,7 +904,6 @@ Value *VarExprAST::Codegen() { return BodyVal; } - Function *PrototypeAST::Codegen() { // Make the function type: double(double,double) etc. std::vector<const Type*> Doubles(Args.size(), @@ -963,7 +958,6 @@ void PrototypeAST::CreateArgumentAllocas(Function *F) { } } - Function *FunctionAST::Codegen() { NamedValues.clear(); @@ -981,7 +975,7 @@ Function *FunctionAST::Codegen() { // Add all arguments to the symbol table and create their allocas. Proto->CreateArgumentAllocas(TheFunction); - + if (Value *RetVal = Body->Codegen()) { // Finish off the function. Builder.CreateRet(RetVal); @@ -1034,7 +1028,7 @@ static void HandleExtern() { } static void HandleTopLevelExpression() { - // Evaluate a top level expression into an anonymous function. + // Evaluate a top-level expression into an anonymous function. if (FunctionAST *F = ParseTopLevelExpr()) { if (Function *LF = F->Codegen()) { // JIT the function, returning a function pointer. @@ -1057,7 +1051,7 @@ static void MainLoop() { fprintf(stderr, "ready> "); switch (CurTok) { case tok_eof: return; - case ';': getNextToken(); break; // ignore top level semicolons. + case ';': getNextToken(); break; // ignore top-level semicolons. case tok_def: HandleDefinition(); break; case tok_extern: HandleExtern(); break; default: HandleTopLevelExpression(); break; @@ -1065,8 +1059,6 @@ static void MainLoop() { } } - - //===----------------------------------------------------------------------===// // "Library" functions that can be "extern'd" from user code. //===----------------------------------------------------------------------===// @@ -1092,7 +1084,7 @@ double printd(double X) { int main() { InitializeNativeTarget(); LLVMContext &Context = getGlobalContext(); - + // Install standard binary operators. // 1 is lowest precedence. BinopPrecedence['='] = 2; |