From bb6805d2632b0737e21a7a8987da9264b62d1452 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Sat, 11 Feb 2017 21:26:52 +0000 Subject: Update Kaleidoscope tutorial and improve Windows support Many quoted code blocks were not in sync with the actual toy.cpp files. Improve tutorial text slightly in several places. Added some step descriptions crucial to avoid crashes (like InitializeNativeTarget* calls). Solve/workaround problems with Windows (JIT'ed method not found, using custom and standard library functions from host process). Patch by: Moritz Kroll Differential Revision: https://reviews.llvm.org/D29864 llvm-svn: 294870 --- llvm/examples/Kaleidoscope/Chapter7/toy.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'llvm/examples/Kaleidoscope/Chapter7/toy.cpp') diff --git a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp index 7e723ba0397..2f8cb682a84 100644 --- a/llvm/examples/Kaleidoscope/Chapter7/toy.cpp +++ b/llvm/examples/Kaleidoscope/Chapter7/toy.cpp @@ -639,7 +639,7 @@ static std::unique_ptr ParsePrototype() { // Read the precedence if present. if (CurTok == tok_number) { if (NumVal < 1 || NumVal > 100) - return LogErrorP("Invalid precedecnce: must be 1..100"); + return LogErrorP("Invalid precedence: must be 1..100"); BinaryPrecedence = (unsigned)NumVal; getNextToken(); } @@ -840,7 +840,7 @@ Value *IfExprAST::codegen() { if (!CondV) return nullptr; - // Convert condition to a bool by comparing equal to 0.0. + // Convert condition to a bool by comparing non-equal to 0.0. CondV = Builder.CreateFCmpONE( CondV, ConstantFP::get(TheContext, APFloat(0.0)), "ifcond"); @@ -963,7 +963,7 @@ Value *ForExprAST::codegen() { Value *NextVar = Builder.CreateFAdd(CurVar, StepVal, "nextvar"); Builder.CreateStore(NextVar, Alloca); - // Convert condition to a bool by comparing equal to 0.0. + // Convert condition to a bool by comparing non-equal to 0.0. EndCond = Builder.CreateFCmpONE( EndCond, ConstantFP::get(TheContext, APFloat(0.0)), "loopcond"); @@ -1115,6 +1115,8 @@ static void InitializeModuleAndPassManager() { // Create a new pass manager attached to it. TheFPM = llvm::make_unique(TheModule.get()); + // Promote allocas to registers. + TheFPM->add(createPromoteMemoryToRegisterPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. TheFPM->add(createInstructionCombiningPass()); // Reassociate expressions. @@ -1210,14 +1212,20 @@ static void MainLoop() { // "Library" functions that can be "extern'd" from user code. //===----------------------------------------------------------------------===// +#ifdef LLVM_ON_WIN32 +#define DLLEXPORT __declspec(dllexport) +#else +#define DLLEXPORT +#endif + /// putchard - putchar that takes a double and returns 0. -extern "C" double putchard(double X) { +extern "C" DLLEXPORT double putchard(double X) { fputc((char)X, stderr); return 0; } /// printd - printf that takes a double prints it as "%f\n", returning 0. -extern "C" double printd(double X) { +extern "C" DLLEXPORT double printd(double X) { fprintf(stderr, "%f\n", X); return 0; } -- cgit v1.2.3