Ive added clang to my music application to compile audio plugins.
Using the interpreter example as a base code, how do I get to the
error messages array buffer so can add the messages to my code
compiler window?
Thanks.
Ive added clang to my music application to compile audio plugins.
Using the interpreter example as a base code, how do I get to the
error messages array buffer so can add the messages to my code
compiler window?
Thanks.
Check the Diagnostics section of Doxygen, in particular, the
DiagnosticClient
http://clang.llvm.org/doxygen/classclang_1_1DiagnosticClient.html
Remember you can create your own to suit your own format. Pass the
DiagnosticClient to your compiler instance.
ok, i have changed from:
TextDiagnosticPrinter *DiagClient =
new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
Diagnostic Diags(DiagClient);
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
"a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
Diags);
to:
TextDiagnosticBuffer *DiagClient =
new TextDiagnosticBuffer();
Diagnostic Diags(DiagClient);
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
"a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
Diags);
but when i add the following code, I get get no errors reported even
though I have added some errors to my c code.
if (!Clang.ExecuteAction(*Act))
{
TextDiagnosticBuffer::const_iterator itTextDiagnosticBuffer;
{
vector<std::String> vWarnings;
int iTotalWarnings = 0;
for (itTextDiagnosticBuffer = DiagClient->warn_begin();
itTextDiagnosticBuffer != DiagClient->warn_end();
++itTextDiagnosticBuffer)
{
vWarnings.push_back(itTextDiagnosticBuffer->second.data());
iTotalWarnings++;
}
char cErrorText[255];
sprintf (cErrorText, "Total %d warnings!", iTotalWarnings);
}
{
vector<std::String> vErrors;
int iTotalErrors = 0;
for (itTextDiagnosticBuffer = DiagClient->err_begin();
itTextDiagnosticBuffer != DiagClient->err_end();
++itTextDiagnosticBuffer)
{
vErrors.push_back(itTextDiagnosticBuffer->second.data());
iTotalErrors++;
}
char cErrorText[255];
sprintf (cErrorText, "Total %d errors!", iTotalErrors);
}
}
what am i doing wrong?
No matter what I try I can't get at the compiler error messages buffer.
I have tried using code ive found on the net but due to the changing
api, I can't get this to work.
This is what ive got, based on the interpreter example.
Please, someone point me in the right direction.
void LLVMErrorHandler(void *UserData, const std::string &Message)
{
Diagnostic &Diags = *static_cast<Diagnostic*>(UserData);
Diags.Report(diag::err_fe_error_backend) << Message;
:
// We cannot recover from llvm errors.
exit(1);
}
TextDiagnosticBuffer *DiagClient = new TextDiagnosticBuffer();
Diagnostic Diags(DiagClient);
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
"a.out", /*IsProduction=*/false, /*CXXIsProduction=*/false,
Diags);
llvm::llvm_install_error_handler(LLVMErrorHandler,
static_cast<void*>(&Clang.getDiagnostics()));
if (!Clang.ExecuteAction(*Act))
{
TextDiagnosticBuffer::const_iterator itTextDiagnosticBuffer;
{
vector<std::String> vWarnings;
int iTotalWarnings = 0;
for (itTextDiagnosticBuffer = DiagClient->warn_begin();
itTextDiagnosticBuffer != DiagClient->warn_end();
++itTextDiagnosticBuffer)
{
vWarnings.push_back(itTextDiagnosticBuffer->second.data());
iTotalWarnings++;
}
char cErrorText[255];
sprintf (cErrorText, "Total %d warnings!", iTotalWarnings);
}
{
vector<std::String> vErrors;
int iTotalErrors = 0;
for (itTextDiagnosticBuffer = DiagClient->err_begin();
itTextDiagnosticBuffer != DiagClient->err_end();
++itTextDiagnosticBuffer)
{
vErrors.push_back(itTextDiagnosticBuffer->second.data());
iTotalErrors++;
}
char cErrorText[255];
sprintf (cErrorText, "Total %d errors!", iTotalErrors);
}
}