// Standard includes #include //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 static typename std::enable_if::value, std::unique_ptr>::type make_unique(Args &&... args) { return std::unique_ptr(new T(std::forward(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(); 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(*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; }