Commit 703719f6 authored by Christian Dietrich's avatar Christian Dietrich
Browse files

Update to new clang plugin infrastructure

parent 9c7a0edf
......@@ -28,55 +28,60 @@ public:
}
llvm::errs() << "top-level-hash: " << Visitor.GetHash() << "\n";
}
private:
private:
raw_ostream *toplevel_hash_stream;
TranslationUnitHashVisitor Visitor;
};
class HashTranslationUnitAction : public PluginASTAction {
protected:
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) {
// Write hash database to .o.hash if the compiler produces a object file
llvm::raw_ostream *Out = nullptr;
if (CI.getFrontendOpts().OutputFile != "") {
std::error_code Error;
std::string HashFile = CI.getFrontendOpts().OutputFile + ".hash";
Out = new llvm::raw_fd_ostream(HashFile, Error, llvm::sys::fs::F_Text);
errs() << "dump-ast-file: " << CI.getFrontendOpts().OutputFile << " " << HashFile << "\n";
if (Error) {
errs() << "Could not open ast-hash file: " << CI.getFrontendOpts().OutputFile << "\n";
}
}
return llvm::make_unique<HashTranslationUnitConsumer>(Out);
}
bool ParseArgs(const CompilerInstance &CI,
const std::vector<std::string> &args) {
for (unsigned i = 0, e = args.size(); i != e; ++i) {
llvm::errs() << " arg = " << args[i] << "\n";
// Example error handling.
if (args[i] == "-an-error") {
DiagnosticsEngine &D = CI.getDiagnostics();
unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error,
"invalid argument '%0'");
D.Report(DiagID) << args[i];
return false;
}
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) override {
// Write hash database to .o.hash if the compiler produces a object file
llvm::raw_ostream *Out = nullptr;
if (CI.getFrontendOpts().OutputFile != "") {
std::error_code Error;
std::string HashFile = CI.getFrontendOpts().OutputFile + ".hash";
Out = new llvm::raw_fd_ostream(HashFile, Error, llvm::sys::fs::F_Text);
errs() << "dump-ast-file: " << CI.getFrontendOpts().OutputFile << " " << HashFile << "\n";
if (Error) {
errs() << "Could not open ast-hash file: " << CI.getFrontendOpts().OutputFile << "\n";
}
}
return llvm::make_unique<HashTranslationUnitConsumer>(Out);
}
if (args.size() && args[0] == "help") {
// FIXME
PrintHelp(llvm::errs());
bool ParseArgs(const CompilerInstance &CI,
const std::vector<std::string> &args) override {
for (unsigned i = 0, e = args.size(); i != e; ++i) {
llvm::errs() << " arg = " << args[i] << "\n";
// Example error handling.
if (args[i] == "-an-error") {
DiagnosticsEngine &D = CI.getDiagnostics();
unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error,
"invalid argument '%0'");
D.Report(DiagID) << args[i];
return false;
}
}
if (args.size() && args[0] == "help") {
// FIXME
PrintHelp(llvm::errs());
}
return true;
}
return true;
}
void PrintHelp(llvm::raw_ostream &ros) {
ros << "Help for PrintFunctionNames plugin goes here\n";
}
PluginASTAction::ActionType getActionType() override {
return AddBeforeMainAction;
}
void PrintHelp(llvm::raw_ostream &ros) {
ros << "Help for PrintFunctionNames plugin goes here\n";
}
};
static FrontendPluginRegistry::Add<HashTranslationUnitAction>
......
......@@ -3,4 +3,4 @@
printf -v ARGS "%q " "$@"
${CMAKE_C_COMPILER} -Xclang -load -Xclang ${PROJECT_BINARY_DIR}/src/libclang-hash.so -Xclang -plugin -Xclang hash-unit $ARGS
${CMAKE_C_COMPILER} -fplugin=${PROJECT_BINARY_DIR}/src/libclang-hash.so $ARGS
Supports Markdown
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