commit 5006d79ca8ad225b0da277ec910239d4aab16ee7
parent a90c7f9894aec5bf8d0910726a139589339fdb96
Author: Kyle Milz <kyle@0x30.net>
Date: Fri, 12 Aug 2016 19:31:59 -0600
src: use new logger in action
Diffstat:
4 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/src/inst_action.cc b/src/inst_action.cc
@@ -42,14 +42,14 @@ InstrumentAction::write_modified_src(clang::FileID const &fid)
if (m_is_citruninst) {
out_file += ".citrun";
- *m_log << m_pfx << "Writing modified source to '"
+ *m_log << "Writing modified source to '"
<< out_file << "'.\n";
}
std::error_code ec;
llvm::raw_fd_ostream output(out_file, ec, llvm::sys::fs::F_None);
if (ec.value()) {
- *m_log << m_pfx << "Error writing modified source: "
+ *m_log << "Error writing modified source: "
<< ec.message() << "\n";
warnx("'%s': %s", out_file.c_str(), ec.message().c_str());
return;
@@ -57,7 +57,7 @@ InstrumentAction::write_modified_src(clang::FileID const &fid)
// Write the instrumented source file
m_TheRewriter.getEditBuffer(fid).write(output);
- *m_log << m_pfx << "Modified source written successfully.\n";
+ *m_log << "Modified source written successfully.\n";
}
void
@@ -102,23 +102,23 @@ InstrumentAction::EndSourceFileAction()
unsigned header_sz = count(header.begin(), header.end(), '\n');
if (!m_is_citruninst && m_TheRewriter.InsertTextAfter(start, header)) {
- *m_log << m_pfx << "Failed inserting " << header_sz
+ *m_log << "Failed inserting " << header_sz
<< " lines of instrumentation preabmle.";
return;
}
- *m_log << m_pfx << "Instrumentation of '" << m_compiler_file_name << "' finished:\n";
- *m_log << m_pfx << " " << num_lines << " Lines of source code\n";
- *m_log << m_pfx << " " << header_sz << " Lines of instrumentation header\n";
+ *m_log << "Instrumentation of '" << m_compiler_file_name << "' finished:\n";
+ *m_log << " " << num_lines << " Lines of source code\n";
+ *m_log << " " << header_sz << " Lines of instrumentation header\n";
//
// Write out statistics from the AST visitor.
//
RewriteASTVisitor v = m_InstrumentASTConsumer->get_visitor();
- for (int i = 0; i < NCOUNTERS; i++) {
+ for (int i = 0; i < NCOUNTERS; ++i) {
if (v.m_counters[i] == 0)
continue;
- *m_log << m_pfx << " " << v.m_counters[i] << " "
+ *m_log << " " << v.m_counters[i] << " "
<< v.m_counter_descr[i] << "\n";
}
diff --git a/src/inst_action.h b/src/inst_action.h
@@ -1,4 +1,5 @@
#include "inst_visitor.h"
+#include "inst_log.h"
#include <clang/AST/ASTConsumer.h>
#include <clang/Frontend/FrontendActions.h>
@@ -29,10 +30,9 @@ private:
// For each source file provided to the tool, a new FrontendAction is created.
class InstrumentAction : public clang::ASTFrontendAction {
public:
- InstrumentAction(llvm::raw_fd_ostream *log, std::string const &pfx,
- bool citruninst, std::string const &filename) :
+ InstrumentAction(InstrumentLogger *log, bool citruninst,
+ std::string const &filename) :
m_log(log),
- m_pfx(pfx),
m_is_citruninst(citruninst),
m_compiler_file_name(filename)
{};
@@ -45,8 +45,7 @@ private:
clang::Rewriter m_TheRewriter;
RewriteASTConsumer *m_InstrumentASTConsumer;
- llvm::raw_fd_ostream *m_log;
- std::string m_pfx;
+ InstrumentLogger *m_log;
bool m_is_citruninst;
std::string m_compiler_file_name;
};
diff --git a/src/inst_log.h b/src/inst_log.h
@@ -1,4 +1,9 @@
+#ifndef __INST_LOG_H_
+#define __INST_LOG_H_
+
+#include <err.h>
#include <llvm/Support/raw_ostream.h>
+#include <unistd.h> // getpid
class InstrumentLogger {
public:
@@ -6,8 +11,8 @@ public:
m_pid(getpid()),
m_needs_prefix(true)
{};
- ~InstrumentLogger()
- { std::cerr << "~InstrumentLogger()" << std::endl; };
+ //~InstrumentLogger()
+ //{ llvm::errs() << "~InstrumentLogger()\n"; };
void set_output(const bool &is_citruninst) {
@@ -63,3 +68,5 @@ private:
bool m_needs_prefix;
};
+
+#endif // _INST_LOG_H_
diff --git a/src/inst_main.h b/src/inst_main.h
@@ -40,7 +40,7 @@ public:
{};
clang::ASTFrontendAction *create() {
- return new InstrumentAction((llvm::raw_fd_ostream*)m_log->m_output, "", m_is_citruninst, m_source_files[m_i++]);
+ return new InstrumentAction(m_log, m_is_citruninst, m_source_files[m_i++]);
}
private: