12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- // Standard includes
- #include <cstdio>
- //LLVM includes
- #include "llvm/Support/TargetSelect.h"
- #include "KaleidoscopeJIT.h"
- #include "llvm/IR/DIBuilder.h"
- // Local includes
- #include "JIT.h"
- #include "Ast.h"
- #include "Lexer.h"
- #include "Parser.h"
- #include "Debug.h"
- 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.
- //===----------------------------------------------------------------------===//
- //===----------------------------------------------------------------------===//
- // Main driver code.
- //===----------------------------------------------------------------------===//
- int main() {
- InitializeNativeTarget();
- InitializeNativeTargetAsmPrinter();
- InitializeNativeTargetAsmParser();
- jit::JITObjects::TheJIT = llvm::make_unique<llvm::orc::KaleidoscopeJIT>();
- jit::InitializeModule();
- // Prime the first token.
- parser::getNextToken();
- // Add the current debug info version into the module.
- AstObjects::TheModule->addModuleFlag(Module::Warning, "Debug Info Version",
- DEBUG_METADATA_VERSION);
- // Darwin only supports dwarf2.
- if (Triple(sys::getProcessTriple()).isOSDarwin()) {
- AstObjects::TheModule->addModuleFlag(llvm::Module::Warning, "Dwarf Version",
- 2);
- }
- // Construct the DIBuilder, we do this here because we need the module.
- debugger::DebugObjects::DBuilder =
- llvm::make_unique<DIBuilder>(*AstObjects::TheModule);
- // Create the compile unit for the module.
- // Currently down as "fib.ks" as a filename since we're redirecting stdin
- // but we'd like actual source locations.
- debugger::KSDbgInfo.TheCU = debugger::DebugObjects::DBuilder->createCompileUnit(
- dwarf::DW_LANG_C, "fib.ks", ".", "Kaleidoscope Compiler", 0, "", 0);
- // Run the main "interpreter loop" now.
- parser::MainLoop();
- // Finalize the debug info.
- debugger::DebugObjects::DBuilder->finalize();
- AstObjects::TheModule->dump();
- return 0;
- }
- }
|