void prepareCompilerforFile(const char* szSourceCodeFilePath) { // To reuse the source manager we have to create these tables. m_CompilerInstance.getSourceManager().clearIDTables(); //m_CompilerInstance.InitializeSourceManager(clang::FrontendInputFile(szSourceCodeFilePath, clang::InputKind::IK_C));// ger(m_CompilerInstance.getFileManager()); // supply the file to the source manager and set it as main-file const clang::FileEntry * file = m_CompilerInstance.getFileManager().getFile(szSourceCodeFilePath); clang::FileID fileID = m_CompilerInstance.getSourceManager().createFileID(file, clang::SourceLocation(), clang::SrcMgr::CharacteristicKind::C_User); m_CompilerInstance.getSourceManager().setMainFileID(fileID); // CodeGenAction needs this clang::FrontendOptions& feOptions = m_CompilerInstance.getFrontendOpts(); feOptions.Inputs.clear(); feOptions.Inputs.push_back(clang::FrontendInputFile(szSourceCodeFilePath, clang::FrontendOptions::getInputKindForExtension(clang::StringRef(szSourceCodeFilePath).rsplit('.').second), false)); }
TriaAction::CreateAstConsumerResultType TriaAction::CreateASTConsumer (clang::CompilerInstance &ci, llvm::StringRef fileName) { ci.getFrontendOpts().SkipFunctionBodies = true; ci.getPreprocessor().enableIncrementalProcessing (true); ci.getLangOpts().DelayedTemplateParsing = true; // Enable everything for code compatibility ci.getLangOpts().MicrosoftExt = true; ci.getLangOpts().DollarIdents = true; ci.getLangOpts().CPlusPlus11 = true; ci.getLangOpts().GNUMode = true; #if CLANG_VERSION_MINOR < 6 ci.getLangOpts().CPlusPlus1y = true; #else ci.getLangOpts().CPlusPlus14 = true; #endif if (argVerboseTimes) { UNIQUE_COMPAT(PreprocessorHooks, hook, new PreprocessorHooks (ci)); hook->timing ()->name = sourceFileName (this->m_definitions->sourceFiles ()); this->m_definitions->setTimingNode (hook->timing ()); ci.getPreprocessor ().addPPCallbacks (MOVE_COMPAT(hook)); } // QStringList whichInherit; for (const std::string &cur : argInspectBases) { whichInherit.append (QString::fromStdString (cur)); } // TriaASTConsumer *consumer = new TriaASTConsumer (ci, fileName, whichInherit, argInspectAll, argGlobalClass, this->m_definitions); #if CLANG_VERSION_MINOR < 6 return consumer; #else return std::unique_ptr< clang::ASTConsumer > (consumer); #endif }
bool WebCLAction::initialize(clang::CompilerInstance &instance) { reporter_ = new WebCLReporter(instance); if (!reporter_) { llvm::errs() << "Internal error. Can't report errors.\n"; return false; } preprocessor_ = new WebCLPreprocessor(instance, extensions_, usedExtensions_); if (!preprocessor_) { reporter_->fatal("Internal error. Can't create preprocessor callbacks.\n"); return false; } clang::Preprocessor &preprocessor = instance.getPreprocessor(); preprocessor.addPPCallbacks(preprocessor_); if (output_) { // see clang::PrintPreprocessedAction instance.getFrontendOpts().OutputFile = output_; out_ = instance.createDefaultOutputFile(true, getCurrentFile()); if (!out_) { reporter_->fatal("Internal error. Can't create output stream."); return false; } } const clang::FrontendInputFile &file = getCurrentInput(); if (file.getKind() != clang::IK_OpenCL) { static const char *format = "Source file '%0' isn't treated as OpenCL code. Make sure that you " "give the '-x cl' option or that the file has a '.cl' extension.\n"; reporter_->fatal(format) << file.getFile(); return false; } return true; }