Main.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Standard includes
  2. #include <cstdio>
  3. //LLVM includes
  4. #include "llvm/Support/TargetSelect.h"
  5. #include "KaleidoscopeJIT.h"
  6. // Local includes
  7. #include "Ast.h"
  8. #include "Parser.h"
  9. #include "JIT.h"
  10. using namespace parser;
  11. using namespace jit;
  12. namespace helper {
  13. // Cloning make_unique here until it's standard in C++14.
  14. // Using a namespace to avoid conflicting with MSVC's std::make_unique (which
  15. // ADL can sometimes find in unqualified calls).
  16. template <class T, class... Args>
  17. static
  18. typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
  19. make_unique(Args &&... args) {
  20. return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
  21. }
  22. }
  23. //===----------------------------------------------------------------------===//
  24. // "Library" functions that can be "extern'd" from user code.
  25. //===----------------------------------------------------------------------===//
  26. /// putchard - putchar that takes a double and returns 0.
  27. extern "C" double putchard(double X) {
  28. fputc((char)X, stderr);
  29. return 0;
  30. }
  31. /// printd - printf that takes a double prints it as "%f\n", returning 0.
  32. extern "C" double printd(double X) {
  33. fprintf(stderr, "%f\n", X);
  34. return 0;
  35. }
  36. //===----------------------------------------------------------------------===//
  37. // Main driver code.
  38. //===----------------------------------------------------------------------===//
  39. int main() {
  40. InitializeNativeTarget();
  41. InitializeNativeTargetAsmPrinter();
  42. InitializeNativeTargetAsmParser();
  43. JITObjects::TheJIT = llvm::make_unique<llvm::orc::KaleidoscopeJIT>();
  44. jit::InitializeModuleAndPassManager();
  45. // Prime the first token.
  46. fprintf(stderr, "ready> ");
  47. getNextToken();
  48. // Run the main "interpreter loop" now.
  49. MainLoop();
  50. AstObjects::TheModule->dump();
  51. return 0;
  52. }