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 | fd1ec5e68b593a4f4d5497b150e677ebef36c231 (patch) | |
tree | 027e6b4a079e3a7330849ffd5422cd52adb301c2 /docs/tutorial/LangImpl5.html | |
parent | 7815d71167e7ba7f0e4b0c54936c1a18a5f7b94d (diff) | |
download | external_llvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.zip external_llvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.tar.gz external_llvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.tar.bz2 |
Sync c++ kaleidoscope tutorial with test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82572 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs/tutorial/LangImpl5.html')
-rw-r--r-- | docs/tutorial/LangImpl5.html | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/docs/tutorial/LangImpl5.html b/docs/tutorial/LangImpl5.html index ea70e2c..f93b59b 100644 --- a/docs/tutorial/LangImpl5.html +++ b/docs/tutorial/LangImpl5.html @@ -472,7 +472,8 @@ are emitted, we can finish up with the merge code:</p> // Emit merge block. TheFunction->getBasicBlockList().push_back(MergeBB); Builder.SetInsertPoint(MergeBB); - PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), "iftmp"); + PHINode *PN = Builder.CreatePHI(Type::getDoubleTy(getGlobalContext()), + "iftmp"); PN->addIncoming(ThenV, ThenBB); PN->addIncoming(ElseV, ElseBB); @@ -1062,7 +1063,8 @@ public: }; /// PrototypeAST - This class represents the "prototype" for a function, -/// which captures its argument names as well as if it is an operator. +/// which captures its name, and its argument names (thus implicitly the number +/// of arguments the function takes). class PrototypeAST { std::string Name; std::vector<std::string> Args; @@ -1089,7 +1091,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() { @@ -1137,9 +1139,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(); @@ -1239,7 +1241,6 @@ static ExprAST *ParseForExpr() { return new ForExprAST(IdName, Start, End, Step, Body); } - /// primary /// ::= identifierexpr /// ::= numberexpr @@ -1550,7 +1551,7 @@ Value *ForExprAST::Codegen() { // for expr always returns 0.0. - return getGlobalContext().getNullValue(Type::getDoubleTy(getGlobalContext())); + return Constant::getNullValue(Type::getDoubleTy(getGlobalContext())); } Function *PrototypeAST::Codegen() { @@ -1655,7 +1656,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. @@ -1678,7 +1679,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; @@ -1686,8 +1687,6 @@ static void MainLoop() { } } - - //===----------------------------------------------------------------------===// // "Library" functions that can be "extern'd" from user code. //===----------------------------------------------------------------------===// @@ -1704,6 +1703,9 @@ double putchard(double X) { //===----------------------------------------------------------------------===// int main() { + InitializeNativeTarget(); + LLVMContext &Context = getGlobalContext(); + // Install standard binary operators. // 1 is lowest precedence. BinopPrecedence['<'] = 10; @@ -1716,7 +1718,7 @@ int main() { getNextToken(); // Make the module, which holds all the code. - TheModule = new Module("my cool jit", getGlobalContext()); + TheModule = new Module("my cool jit", Context); ExistingModuleProvider *OurModuleProvider = new ExistingModuleProvider(TheModule); |