Unverified Commit f6a578b4 authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

add toggle to compiler diagnostic output (#388)

parent 981dabef
...@@ -123,6 +123,7 @@ static std::string GetExecutablePath(const char* Argv0) ...@@ -123,6 +123,7 @@ static std::string GetExecutablePath(const char* Argv0)
StaticCompiler::StaticCompiler() StaticCompiler::StaticCompiler()
: m_precompiled_header_valid(false) : m_precompiled_header_valid(false)
, m_debuginfo_enabled(false) , m_debuginfo_enabled(false)
, m_enable_diag_output((std::getenv("NGRAPH_COMPILER_DIAG_ENABLE") != nullptr))
, m_source_name("code.cpp") , m_source_name("code.cpp")
{ {
initialize(); initialize();
...@@ -150,19 +151,27 @@ void StaticCompiler::initialize() ...@@ -150,19 +151,27 @@ void StaticCompiler::initialize()
args.push_back("-inline-threshold=1000000"); args.push_back("-inline-threshold=1000000");
// Prepare DiagnosticEngine // Prepare DiagnosticEngine
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); IntrusiveRefCntPtr<DiagnosticOptions> diag_options = new DiagnosticOptions();
DiagOpts->ErrorLimit = 20; diag_options->ErrorLimit = 20;
TextDiagnosticPrinter* textDiagPrinter = new clang::TextDiagnosticPrinter(errs(), &*DiagOpts); IntrusiveRefCntPtr<DiagnosticIDs> diag_id(new DiagnosticIDs());
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs()); DiagnosticsEngine diag_engine(diag_id, &*diag_options);
DiagnosticsEngine DiagEngine(DiagID, &*DiagOpts, textDiagPrinter);
// Create and initialize CompilerInstance // Create and initialize CompilerInstance
m_compiler = std::unique_ptr<CompilerInstance>(new CompilerInstance()); m_compiler = std::unique_ptr<CompilerInstance>(new CompilerInstance());
m_compiler->createDiagnostics(); DiagnosticConsumer* diag_consumer;
if (m_enable_diag_output)
{
diag_consumer = new TextDiagnosticPrinter(errs(), &*diag_options);
}
else
{
diag_consumer = new IgnoringDiagConsumer();
}
m_compiler->createDiagnostics(diag_consumer);
// Initialize CompilerInvocation // Initialize CompilerInvocation
CompilerInvocation::CreateFromArgs( CompilerInvocation::CreateFromArgs(
m_compiler->getInvocation(), &args[0], &args[0] + args.size(), DiagEngine); m_compiler->getInvocation(), &args[0], &args[0] + args.size(), diag_engine);
configure_search_path(); configure_search_path();
......
...@@ -86,6 +86,7 @@ private: ...@@ -86,6 +86,7 @@ private:
std::unique_ptr<clang::CompilerInstance> m_compiler; std::unique_ptr<clang::CompilerInstance> m_compiler;
bool m_precompiled_header_valid; bool m_precompiled_header_valid;
bool m_debuginfo_enabled; bool m_debuginfo_enabled;
bool m_enable_diag_output;
std::string m_source_name; std::string m_source_name;
std::vector<std::string> m_extra_search_path_list; std::vector<std::string> m_extra_search_path_list;
std::string m_pch_path; std::string m_pch_path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment