Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, const char** argv)
- {
- llvm::LLVMContext c;
- clang::CompilerInstance CI;
- llvm::Module m("", c);
- clang::EmitLLVMOnlyAction emit(&c);
- emit.setLinkModule(&m);
- std::string errors;
- llvm::raw_string_ostream error_stream(errors);
- clang::DiagnosticOptions diagopts;
- clang::TextDiagnosticPrinter printer(error_stream, &diagopts);
- llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagids(new clang::DiagnosticIDs);
- clang::DiagnosticsEngine engine(diagids, &diagopts, &printer, false);
- CI.setDiagnostics(&engine);
- clang::TargetOptions target;
- target.Triple = llvm::sys::getDefaultTargetTriple();
- CI.setTarget(clang::TargetInfo::CreateTargetInfo(engine, &target));
- /*auto preprocopts = llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions>(new clang::PreprocessorOptions);
- clang::LangOptions langopts;
- auto hsopts = llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions>(new clang::HeaderSearchOptions);
- clang::HeaderSearch hs(hsopts, CI.getFileManager(), CI.getDiagnostics(), langopts, &CI.getTarget());
- auto p = new clang::Preprocessor(preprocopts, engine, langopts, &CI.getTarget(), CI.getSourceManager(), hs, CI);
- CI.setPreprocessor(p);
- CI.createASTContext();
- clang::SemaConsumer* cons = new clang::SemaConsumer();
- CI.setASTConsumer(cons);
- llvm::raw_null_ostream empty;
- clang::PrintingCodeCompleteConsumer print(CodeCompleteOptions(), empty);
- clang::Sema s(*p, CI.getASTContext(), CI.getASTConsumer(), clang::TranslationUnitKind::TU_Complete, &print);
- CI.setSema(&s);
- cons->InitializeSema(CI.getSema());*/
- CI.getHeaderSearchOpts().AddPath(
- "D:\\Backups\\unsorted\\x86_64-w64-mingw32-gcc-4.7.0-release-win64_rubenvb\\mingw64\\x86_64-w64-mingw32\\include",
- clang::frontend::IncludeDirGroup::System,
- false,
- false,
- false
- );
- CI.getLangOpts().CPlusPlus0x = true;
- CI.getLangOpts().CPlusPlus = true;
- clang::FrontendInputFile f("main.cpp", clang::InputKind::IK_CXX, true);
- emit.BeginSourceFile(CI, f);
- CI.getPreprocessor().setMacroInfo(CI.getPreprocessor().getIdentifierInfo("__x86_64"), CI.getPreprocessor().AllocateMacroInfo(clang::SourceLocation()));
- emit.Execute();
- auto sema = CI.takeSema();
- auto ast = &CI.getASTContext();
- CI.resetAndLeakASTContext();
- emit.EndSourceFile();
- emit.takeModule();
- auto identinfo = CI.getPreprocessor().getIdentifierInfo("WriteConsoleW");
- clang::LookupResult lr(*sema, clang::DeclarationName(identinfo), clang::SourceLocation(), clang::Sema::LookupNameKind::LookupOrdinaryName);
- auto result = sema->LookupName(lr, sema->TUScope);
- std::string temp;
- llvm::raw_string_ostream out(temp);
- ast->createMangleContext()->mangleName(lr.getFoundDecl(), out);
- auto fun = m.getFunction(temp);
- std::cout << fun->getName().str();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement