summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorErick Tryzelaar <idadesub@users.sourceforge.net>2009-09-22 21:14:49 +0000
committerErick Tryzelaar <idadesub@users.sourceforge.net>2009-09-22 21:14:49 +0000
commitfd1ec5e68b593a4f4d5497b150e677ebef36c231 (patch)
tree027e6b4a079e3a7330849ffd5422cd52adb301c2 /examples
parent7815d71167e7ba7f0e4b0c54936c1a18a5f7b94d (diff)
downloadllvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.tar.gz
llvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.tar.bz2
llvm-fd1ec5e68b593a4f4d5497b150e677ebef36c231.tar.xz
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 'examples')
-rw-r--r--examples/Kaleidoscope/toy.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/examples/Kaleidoscope/toy.cpp b/examples/Kaleidoscope/toy.cpp
index 8e02e9ab61..8b0c321c06 100644
--- a/examples/Kaleidoscope/toy.cpp
+++ b/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;