Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in out of tree build #2

Open
unphased opened this issue Sep 20, 2014 · 3 comments
Open

Does not work in out of tree build #2

unphased opened this issue Sep 20, 2014 · 3 comments

Comments

@unphased
Copy link

The build should not be performed as you instruct, where you svn co to llvm, cd llvm; make.

With such a configuration (with a build directory and a llvm source directory), the makefile breaks.

@unphased
Copy link
Author

I have worked on this some more, and the good news is that not many changes are needed to make it work.

I can't test the build the way you describe (in-tree build), but for an out-of-tree build one simply needs to add this example into the makefile found in the clang/tools directory.

Here's a patch of the changes to get this working on latest clang. There were a few small api changes and stuff. maybe I will make a pull request.

diff --git a/Example.cpp b/Example.cpp
index de10c6b..d95e918 100644
--- a/Example.cpp
+++ b/Example.cpp
@@ -104,8 +104,8 @@ public:

 class ExampleFrontendAction : public ASTFrontendAction {
 public:
-    virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, StringRef file) {
-        return new ExampleASTConsumer(&CI); // pass CI pointer to ASTConsumer
+    virtual unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef file) {
+        return make_unique<ExampleASTConsumer>(&CI); // pass CI pointer to ASTConsumer
     }
 };

@@ -113,12 +113,12 @@ public:

 int main(int argc, const char **argv) {
     // parse the command-line args passed to your code
-    CommonOptionsParser op(argc, argv);
+    CommonOptionsParser op(argc, argv, llvm::cl::GeneralCategory);
     // create a new Clang Tool instance (a LibTooling environment)
     ClangTool Tool(op.getCompilations(), op.getSourcePathList());

     // run the Clang Tool, creating a new FrontendAction (explained below)
-    int result = Tool.run(newFrontendActionFactory<ExampleFrontendAction>());
+    int result = Tool.run(newFrontendActionFactory<ExampleFrontendAction>().get());

     errs() << "\nFound " << numFunctions << " functions.\n\n";
     // print out the rewritten source code ("rewriter" is a global var.)
diff --git a/Makefile b/Makefile
index f7c7cc2..7c7c99e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 CLANG_LEVEL := ../..

-TOOLNAME = example  #the name of your tool's executable
+TOOLNAME = kevinaboos_example  #the name of your tool's executable

 SOURCES := Example.cpp  #the Clang source files you want to compile

@@ -10,7 +10,7 @@ LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader support mc option

 USEDLIBS = clangFrontend.a clangSerialization.a clangDriver.a \
            clangTooling.a clangParse.a clangSema.a \
-           clangAnalysis.a clangRewriteFrontend.a clangRewriteCore.a \
+           clangAnalysis.a clangRewriteFrontend.a clangRewrite.a \
           clangEdit.a clangAST.a clangLex.a clangBasic.a

 include $(CLANG_LEVEL)/Makefile

@dmitris
Copy link

dmitris commented Oct 22, 2014

thanks @unphased - your diff was helpful, please do submit a PR! :)

@dmitris
Copy link

dmitris commented Oct 22, 2014

never mind - noticed the PR from https://github.com/showgood/LibToolingExample (Kevin, please merge it or @unphased's one!) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants