diff --git a/LLVM/cplusplus/KaleidoscopeJIT.h b/LLVM/cplusplus/KaleidoscopeJIT.h index eb2d21c50b9a09fd178d22c441b1f6c65cf6c713..18a4c111a5275e2388b21280df47d5f3f2d82314 100644 --- a/LLVM/cplusplus/KaleidoscopeJIT.h +++ b/LLVM/cplusplus/KaleidoscopeJIT.h @@ -18,10 +18,10 @@ #include "llvm/ExecutionEngine/Orc/CompileUtils.h" #include "llvm/ExecutionEngine/Orc/Core.h" #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" +#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h" #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h" #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" -#include "llvm/ExecutionEngine/Orc/TargetProcessControl.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/LLVMContext.h" @@ -32,7 +32,6 @@ namespace orc { class KaleidoscopeJIT { private: - std::unique_ptr<TargetProcessControl> TPC; std::unique_ptr<ExecutionSession> ES; DataLayout DL; @@ -44,11 +43,9 @@ private: JITDylib &MainJD; public: - KaleidoscopeJIT(std::unique_ptr<TargetProcessControl> TPC, - std::unique_ptr<ExecutionSession> ES, + KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES, JITTargetMachineBuilder JTMB, DataLayout DL) - : TPC(std::move(TPC)), ES(std::move(ES)), DL(std::move(DL)), - Mangle(*this->ES, this->DL), + : ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL), ObjectLayer(*this->ES, []() { return std::make_unique<SectionMemoryManager>(); }), CompileLayer(*this->ES, ObjectLayer, @@ -65,21 +62,21 @@ public: } static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() { - auto SSP = std::make_shared<SymbolStringPool>(); - auto TPC = SelfTargetProcessControl::Create(SSP); - if (!TPC) - return TPC.takeError(); + auto EPC = SelfExecutorProcessControl::Create(); + if (!EPC) + return EPC.takeError(); - auto ES = std::make_unique<ExecutionSession>(std::move(SSP)); + auto ES = std::make_unique<ExecutionSession>(std::move(*EPC)); - JITTargetMachineBuilder JTMB((*TPC)->getTargetTriple()); + JITTargetMachineBuilder JTMB( + ES->getExecutorProcessControl().getTargetTriple()); auto DL = JTMB.getDefaultDataLayoutForTarget(); if (!DL) return DL.takeError(); - return std::make_unique<KaleidoscopeJIT>(std::move(*TPC), std::move(ES), - std::move(JTMB), std::move(*DL)); + return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB), + std::move(*DL)); } const DataLayout &getDataLayout() const { return DL; } diff --git a/LLVM/cplusplus/Makefile b/LLVM/cplusplus/Makefile index 106485a0f26bb9d1698d7abc1f1745cacbdb1c18..9a1f81658c526689c5bffc52fa8956f9d158e5f6 100644 --- a/LLVM/cplusplus/Makefile +++ b/LLVM/cplusplus/Makefile @@ -55,7 +55,8 @@ $(PROGS): %: %.cpp $(CC) -g $< $(CFLAGS) -o $@ clean: testclean - $(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test9 + -$(RM) -fv *~ $(PROGS) ModuleMaker.bc fib test8 test9 + -$(RM) -rfv *.dSYM testclean: rm -fv *~ *.output test8.o test9.o @@ -102,9 +103,15 @@ test8: toy8 tests/test8.kal tests/test8.cpp -clang++ tests/test8.cpp test8.o -o test8 -./test8 +## This next test calls "toy9" and then pipes STDERR to clang. +# With bash, this can be done with |& ("pipe ampersand"). +# Make uses "sh". Under Linux, sh and bash are the same thing, +# but under (e.g.) MacOS, they aren't, and with sh, "|&" doesn't work. +# The current version uses "2>&1" to redirect STDERR to STDOUT, +# and then pipe STDOUT to clang. test9: toy9 tests/test9.kal tests/test9.cpp echo && echo "\n===================> Testing toy9...(expect fib(12) == 144)\n" - -./toy9 <tests/test9.kal |& clang -x ir -c - -o test9.o + -./toy9 <tests/test9.kal 2>&1 | clang -x ir -c - -o test9.o -clang++ tests/test9.cpp test9.o -o test9 -./test9 diff --git a/LLVM/cplusplus/toy7.cpp b/LLVM/cplusplus/toy7.cpp index 2c2519eb847eadc4d0219d2ba03008ba65301594..32eba0cf20c1b9e1ae0a38802512ff436dc06fb4 100644 --- a/LLVM/cplusplus/toy7.cpp +++ b/LLVM/cplusplus/toy7.cpp @@ -746,12 +746,12 @@ Value *NumberExprAST::codegen() { Value *VariableExprAST::codegen() { // Look this variable up in the function. - Value *V = NamedValues[Name]; - if (!V) + AllocaInst *A = NamedValues[Name]; + if (!A) return LogErrorV("Unknown variable name"); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(A->getAllocatedType(), A, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -963,7 +963,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = + Builder->CreateLoad(Alloca->getAllocatedType(), Alloca, VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca); diff --git a/LLVM/cplusplus/toy8.cpp b/LLVM/cplusplus/toy8.cpp index a1fe89a9f8440f751b19143165e40de3b5107913..fca54f2b976a58883be2a12d0bfbed918f0b777f 100644 --- a/LLVM/cplusplus/toy8.cpp +++ b/LLVM/cplusplus/toy8.cpp @@ -749,7 +749,7 @@ Value *VariableExprAST::codegen() { return LogErrorV("Unknown variable name"); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(Type::getDoubleTy(*TheContext), V, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -961,7 +961,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = Builder->CreateLoad(Type::getDoubleTy(*TheContext), Alloca, + VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca); diff --git a/LLVM/cplusplus/toy9.cpp b/LLVM/cplusplus/toy9.cpp index fa1fe3909eaf7e36172f9cced320b4d080ff0f81..a34d70c17b3ccb6218138b6a65fd46d650dfa16e 100644 --- a/LLVM/cplusplus/toy9.cpp +++ b/LLVM/cplusplus/toy9.cpp @@ -912,7 +912,7 @@ Value *VariableExprAST::codegen() { KSDbgInfo.emitLocation(this); // Load the value. - return Builder->CreateLoad(V, Name.c_str()); + return Builder->CreateLoad(Type::getDoubleTy(*TheContext), V, Name.c_str()); } Value *UnaryExprAST::codegen() { @@ -1133,7 +1133,8 @@ Value *ForExprAST::codegen() { // Reload, increment, and restore the alloca. This handles the case where // the body of the loop mutates the variable. - Value *CurVar = Builder->CreateLoad(Alloca, VarName.c_str()); + Value *CurVar = Builder->CreateLoad(Type::getDoubleTy(*TheContext), Alloca, + VarName.c_str()); Value *NextVar = Builder->CreateFAdd(CurVar, StepVal, "nextvar"); Builder->CreateStore(NextVar, Alloca);