I have downloaded LLVM 3.1 and build it successfully. My requirement is to add some few debugging lines in a C++ source code files. I have coded module using CLANG 3.1. But CLANG reports a lot of AST error which gcc does not. Note my code compiles fine with gcc compiler. Further my C++ program has a lot of #include statements. LLVM expects the same to be available in a path and fails at different level again.
Asked
Active
Viewed 892 times
1
-
1It's really unclear to me what you are asking here. Are you trying to understand why Clang reports errors on code that GCC compiles? If so, you better share the code and show us what error(s) you're getting. Are you wondering why GCC succeeds in finding include files while Clang doesn't? Maybe show your command lines you've used for both. Or maybe you are asking how to write an LLVM pass which adds a printf after method calls? Or maybe I misunderstood you completely and you're asking something else entirely? In short, please clarify. – Oak Mar 14 '13 at 12:33
-
I have updated my question as per details asked. Yes, I am looking for way to add debugging statements in my C++ source code file – Programmer Mar 14 '13 at 12:45
-
I still don't understand at all what you are trying to do. Can you provide a few lines of code and give the actual commands you invoke and their error messages? – Christopher Creutzig Mar 15 '13 at 20:31
1 Answers
2
Clang has a new library named libTooling to ease writing source-to-source tools with clang. I suggest you check it out. The most complete example of using it is clang-format, which reformats arbitrary C++ code according to a set of formatting guidelines. It demonstrates how to rewrite C++ code at the source-level while preserving all the semantics. It shouldn't be hard to hack it to add insertion of certain statements at certain places.

Eli Bendersky
- 263,248
- 89
- 350
- 412
-
Thanks for the details but I get the below error when I try via a sample program : ./clang-check t.cpp ---- LLVM ERROR: Error while opening JSON database: No such file or directory – Programmer Mar 18 '13 at 11:30
-
@Prakash: that's not much details... I think you should open a new question with specific details of the steps you've followed and the errors encountered, as well as showing the code. For these issues you may get better/quicker answers in the cfe-dev mailing list, by the way. – Eli Bendersky Mar 18 '13 at 12:56