forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible for AST plugins to enable themselves by default
Currently when an AST plugin is loaded it must then be enabled by passing -plugin pluginname or -add-plugin pluginname to the -cc1 command line. This patch adds a method to PluginASTAction which allows it to declare that the action happens before, instead of, or after the main AST action, plus the relevant changes to make the plugin action happen at that time automatically. Differential Revision: http://reviews.llvm.org/D17959 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263546 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
1 parent
8518d88
commit f6603f2
Showing
10 changed files
with
158 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===- AnnotateFunctions.cpp ----------------------------------------------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Example clang plugin which adds an annotation to every function. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/Frontend/FrontendPluginRegistry.h" | ||
#include "clang/AST/AST.h" | ||
#include "clang/AST/ASTConsumer.h" | ||
using namespace clang; | ||
|
||
namespace { | ||
|
||
class AnnotateFunctionsConsumer : public ASTConsumer { | ||
public: | ||
bool HandleTopLevelDecl(DeclGroupRef DG) override { | ||
for (auto D : DG) | ||
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) | ||
FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(), | ||
"example_annotation")); | ||
return true; | ||
} | ||
}; | ||
|
||
class AnnotateFunctionsAction : public PluginASTAction { | ||
public: | ||
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, | ||
llvm::StringRef) override { | ||
return llvm::make_unique<AnnotateFunctionsConsumer>(); | ||
} | ||
|
||
bool ParseArgs(const CompilerInstance &CI, | ||
const std::vector<std::string> &args) override { | ||
return true; | ||
} | ||
|
||
PluginASTAction::ActionType getActionType() override { | ||
return AddBeforeMainAction; | ||
} | ||
}; | ||
|
||
} | ||
|
||
static FrontendPluginRegistry::Add<AnnotateFunctionsAction> | ||
X("annotate-fns", "annotate functions"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_llvm_loadable_module(AnnotateFunctions AnnotateFunctions.cpp) | ||
|
||
if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) | ||
target_link_libraries(AnnotateFunctions ${cmake_2_8_12_PRIVATE} | ||
clangAST | ||
clangFrontend | ||
LLVMSupport | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %clang -fplugin=%llvmshlibdir/AnnotateFunctions%pluginext -emit-llvm -S %s -o - | FileCheck %s | ||
// REQUIRES: plugins, examples | ||
|
||
// CHECK: [[STR_VAR:@.+]] = private unnamed_addr constant [19 x i8] c"example_annotation\00" | ||
// CHECK: @llvm.global.annotations = {{.*}}@fn1{{.*}}[[STR_VAR]]{{.*}}@fn2{{.*}}[[STR_VAR]] | ||
void fn1() { } | ||
void fn2() { } |