1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- // Standard includes
- #include <cstdio>
- //LLVM includes
- #include "llvm/Support/TargetSelect.h"
- #include "KaleidoscopeJIT.h"
- // Local includes
- #include "Ast.h"
- #include "Parser.h"
- #include "JIT.h"
- using namespace parser;
- using namespace jit;
- namespace helper {
- // Cloning make_unique here until it's standard in C++14.
- // Using a namespace to avoid conflicting with MSVC's std::make_unique (which
- // ADL can sometimes find in unqualified calls).
- template <class T, class... Args>
- static
- typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
- make_unique(Args &&... args) {
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
- }
- }
- //===----------------------------------------------------------------------===//
- // "Library" functions that can be "extern'd" from user code.
- //===----------------------------------------------------------------------===//
- /// putchard - putchar that takes a double and returns 0.
- extern "C" 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) {
- fprintf(stderr, "%f\n", X);
- return 0;
- }
- //===----------------------------------------------------------------------===//
- // Main driver code.
- //===----------------------------------------------------------------------===//
- int main() {
- InitializeNativeTarget();
- InitializeNativeTargetAsmPrinter();
- InitializeNativeTargetAsmParser();
- JITObjects::TheJIT = llvm::make_unique<llvm::orc::KaleidoscopeJIT>();
- jit::InitializeModuleAndPassManager();
- // Prime the first token.
- fprintf(stderr, "ready> ");
- getNextToken();
- // Run the main "interpreter loop" now.
- MainLoop();
- AstObjects::TheModule->dump();
- return 0;
- }
|