JIT.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //LLVM includes
  2. #include "llvm/Analysis/Passes.h"
  3. // Local includes
  4. #include "JIT.h"
  5. using namespace llvm;
  6. using namespace llvm::orc;
  7. namespace jit {
  8. std::unique_ptr<llvm::orc::KaleidoscopeJIT> JITObjects::TheJIT =
  9. std::unique_ptr<llvm::orc::KaleidoscopeJIT>(nullptr);
  10. std::map<std::string, std::unique_ptr<ast::PrototypeAST>> JITObjects::FunctionProtos{};
  11. void InitializeModule(void) {
  12. // Open a new module.
  13. AstObjects::TheModule = llvm::make_unique<Module>("my cool jit", getGlobalContext());
  14. AstObjects::TheModule->setDataLayout(JITObjects::TheJIT->getTargetMachine().createDataLayout());
  15. }
  16. Function *getFunction(std::string Name) {
  17. // First, see if the function has already been added to the current module.
  18. if (auto *F = AstObjects::TheModule->getFunction(Name))
  19. return F;
  20. // If not, check whether we can codegen the declaration from some existing
  21. // prototype.
  22. auto FI = JITObjects::FunctionProtos.find(Name);
  23. if (FI != JITObjects::FunctionProtos.end())
  24. return FI->second->codegen();
  25. // If no existing prototype exists, return null.
  26. return nullptr;
  27. }
  28. }