Advertisement
Guest User

Untitled

a guest
Dec 21st, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. int main(int argc, const char** argv)
  2. {
  3. llvm::LLVMContext c;
  4. clang::CompilerInstance CI;
  5. llvm::Module m("", c);
  6. clang::EmitLLVMOnlyAction emit(&c);
  7. emit.setLinkModule(&m);
  8.  
  9. std::string errors;
  10. llvm::raw_string_ostream error_stream(errors);
  11. clang::DiagnosticOptions diagopts;
  12. clang::TextDiagnosticPrinter printer(error_stream, &diagopts);
  13. llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagids(new clang::DiagnosticIDs);
  14. clang::DiagnosticsEngine engine(diagids, &diagopts, &printer, false);
  15. CI.setDiagnostics(&engine);
  16.  
  17. clang::TargetOptions target;
  18. target.Triple = llvm::sys::getDefaultTargetTriple();
  19. CI.setTarget(clang::TargetInfo::CreateTargetInfo(engine, &target));
  20.  
  21. /*auto preprocopts = llvm::IntrusiveRefCntPtr<clang::PreprocessorOptions>(new clang::PreprocessorOptions);
  22. clang::LangOptions langopts;
  23.  
  24. auto hsopts = llvm::IntrusiveRefCntPtr<clang::HeaderSearchOptions>(new clang::HeaderSearchOptions);
  25. clang::HeaderSearch hs(hsopts, CI.getFileManager(), CI.getDiagnostics(), langopts, &CI.getTarget());
  26.  
  27. auto p = new clang::Preprocessor(preprocopts, engine, langopts, &CI.getTarget(), CI.getSourceManager(), hs, CI);
  28. CI.setPreprocessor(p);
  29. CI.createASTContext();
  30.  
  31. clang::SemaConsumer* cons = new clang::SemaConsumer();
  32.  
  33. CI.setASTConsumer(cons);
  34. llvm::raw_null_ostream empty;
  35. clang::PrintingCodeCompleteConsumer print(CodeCompleteOptions(), empty);
  36. clang::Sema s(*p, CI.getASTContext(), CI.getASTConsumer(), clang::TranslationUnitKind::TU_Complete, &print);
  37. CI.setSema(&s);
  38. cons->InitializeSema(CI.getSema());*/
  39. CI.getHeaderSearchOpts().AddPath(
  40. "D:\\Backups\\unsorted\\x86_64-w64-mingw32-gcc-4.7.0-release-win64_rubenvb\\mingw64\\x86_64-w64-mingw32\\include",
  41. clang::frontend::IncludeDirGroup::System,
  42. false,
  43. false,
  44. false
  45. );
  46. CI.getLangOpts().CPlusPlus0x = true;
  47. CI.getLangOpts().CPlusPlus = true;
  48.  
  49. clang::FrontendInputFile f("main.cpp", clang::InputKind::IK_CXX, true);
  50. emit.BeginSourceFile(CI, f);
  51.  
  52. CI.getPreprocessor().setMacroInfo(CI.getPreprocessor().getIdentifierInfo("__x86_64"), CI.getPreprocessor().AllocateMacroInfo(clang::SourceLocation()));
  53.  
  54. emit.Execute();
  55. auto sema = CI.takeSema();
  56. auto ast = &CI.getASTContext();
  57. CI.resetAndLeakASTContext();
  58. emit.EndSourceFile();
  59.  
  60. emit.takeModule();
  61. auto identinfo = CI.getPreprocessor().getIdentifierInfo("WriteConsoleW");
  62. clang::LookupResult lr(*sema, clang::DeclarationName(identinfo), clang::SourceLocation(), clang::Sema::LookupNameKind::LookupOrdinaryName);
  63. auto result = sema->LookupName(lr, sema->TUScope);
  64.  
  65. std::string temp;
  66. llvm::raw_string_ostream out(temp);
  67. ast->createMangleContext()->mangleName(lr.getFoundDecl(), out);
  68. auto fun = m.getFunction(temp);
  69.  
  70. std::cout << fun->getName().str();
  71.  
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement