Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "llvm/Option/Arg.h"
- #include "clang/Driver/DriverDiagnostic.h"
- #include "clang/Driver/Options.h"
- #include "clang/Basic/TargetOptions.h"
- #include "clang/Basic/TargetInfo.h"
- #include "clang/Frontend/CompilerInstance.h"
- #include "clang/Frontend/CompilerInvocation.h"
- #include "clang/Frontend/FrontendDiagnostic.h"
- #include "clang/Frontend/TextDiagnosticBuffer.h"
- #include "clang/Frontend/TextDiagnosticPrinter.h"
- #include "clang/Lex/Preprocessor.h"
- #include "clang/Parse/ParseAST.h"
- #include "clang/Rewrite/Core/Rewriter.h"
- #include "clang/Rewrite/Frontend/Rewriters.h"
- #include "clang/FrontendTool/Utils.h"
- #include "llvm/ADT/Statistic.h"
- #include "llvm/ADT/STLExtras.h"
- #include "llvm/LinkAllPasses.h"
- #include "llvm/Option/ArgList.h"
- #include "llvm/Option/OptTable.h"
- #include "llvm/Support/ErrorHandling.h"
- #include "llvm/Support/ManagedStatic.h"
- #include "llvm/Support/Signals.h"
- #include "llvm/Support/TargetSelect.h"
- #include "llvm/Support/Timer.h"
- #include "llvm/Support/raw_ostream.h"
- using namespace clang;
- using namespace clang::vfs;
- using namespace llvm;
- using namespace llvm::opt;
- static std::vector<const char*> win32_defaults = {
- "-triple",
- "i686-pc-windows-msvc",
- "-emit-obj",
- "-mrelax-all",
- "-disable-free",
- "-disable-llvm-verifier",
- "-mrelocation-model",
- "static",
- "-mdisable-fp-elim",
- "-std=c++14",
- "-masm-verbose",
- "-mconstructor-aliases",
- "-target-cpu",
- "pentium4",
- "-D_MT",
- "--dependent-lib=libcmt",
- "--dependent-lib=oldnames",
- "-fms-extensions",
- "-fms-compatibility",
- "-fms-compatibility-version=19.0.24215",
- "-fdiagnostics-format",
- "msvc",
- "-D_HAS_EXCEPTIONS=1",
- "-fno-dwarf-directory-asm",
- "-ferror-limit",
- "19",
- "-fmessage-length",
- "80",
- "-mstackrealign",
- "-mstack-alignment=16",
- "-target-feature",
- "+sse4.2",
- "-fobjc-runtime=gcc",
- "-fdiagnostics-show-option",
- "-fcolor-diagnostics",
- "-fdelayed-template-parsing",
- "-fcxx-exceptions",
- "-fexceptions",
- "-internal-isystem",
- "E:\\Microsoft Visual Studio 14.0\\VC\\include",
- "-internal-isystem",
- "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10240.0\\ucrt",
- "-internal-isystem",
- "E:\\work\\git\\scripta\\trunk\\include",
- "-internal-isystem",
- "F:\\Libraries\\eigen\\Eigen"
- };
- #if defined(WIN32)
- #include <windows.h>
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD Reason, LPVOID pReserved)
- {
- switch (Reason)
- {
- case DLL_PROCESS_ATTACH:
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
- #endif
- extern "C"
- {
- __declspec (dllexport) int test()
- {
- std::vector<const char*> compiler_args = win32_defaults;
- compiler_args.push_back("-o");
- compiler_args.push_back("out");
- compiler_args.push_back("-x");
- compiler_args.push_back("c++");
- compiler_args.push_back("Editor.cpp");
- compiler_args.push_back("-v");
- LLVMInitializeX86TargetInfo();
- LLVMInitializeX86Target();
- LLVMInitializeX86TargetMC();
- LLVMInitializeX86AsmPrinter();
- LLVMInitializeX86AsmParser();
- CompilerInstance m_compilerParseInstance;
- //m_compilerParseInstance.createFileManager();
- DiagnosticIDs m_diagIDsParse;
- DiagnosticOptions m_diagOptsParse;
- clang::TextDiagnosticBuffer m_diagsBufferParse;
- new clang::DiagnosticsEngine(&m_diagIDsParse, &m_diagOptsParse, &m_diagsBufferParse, false);
- m_compilerParseInstance.createDiagnostics(&m_diagsBufferParse, false);
- LangOptions &lo = m_compilerParseInstance.getLangOpts();
- lo.CPlusPlus = 1;
- // m_compilerParseInstance.createSourceManager(m_compilerParseInstance.getFileManager());
- bool Success = CompilerInvocation::CreateFromArgs(m_compilerParseInstance.getInvocation(),
- &compiler_args.front(), &compiler_args.back(), m_compilerParseInstance.getDiagnostics());
- // Execute the frontend actions.
- Success = ExecuteCompilerInvocation(&m_compilerParseInstance);
- if (!Success) printf("WE FAILED TO RUN THE COMPILER\n");
- clang::SourceManager& source_manager = m_compilerParseInstance.getSourceManager();
- printf("Number of errors: %d\n", m_diagsBufferParse.getNumErrors());
- printf("Number of warnings: %d\n", m_diagsBufferParse.getNumWarnings());
- for (clang::TextDiagnosticBuffer::const_iterator it = m_diagsBufferParse.err_begin(); it != m_diagsBufferParse.err_end(); ++it)
- {
- clang::PresumedLoc presumed_location = source_manager.getPresumedLoc(it->first);
- if (it->first.isValid())
- {
- clang::PresumedLoc presumed_location = source_manager.getPresumedLoc(it->first);
- size_t fileSize = strlen(presumed_location.getFilename());
- size_t msgSize = it->second.size();
- printf("Error message: %s\n", it->second.c_str());
- }
- else // compiler error (not specific to any file)
- {
- size_t fileSize = 14;
- size_t msgSize = it->second.size();
- printf("Error message: %s\n", it->second.c_str());
- }
- }
- getchar();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement