[cfe-dev] Need Help Printing Preprocessed Code and Modifying CFG

Kevin Boos kevinaboos at gmail.com
Wed Jul 3 11:00:13 PDT 2013


I've looked into the ASTMatcher's abilities, those are very nice but not terribly useful for me. 

I think I've narrowed down what I really need from Clang -- the ability to delete a note from the AST/CFG and then output that modified AST as source code. 

I know that I can printPretty() the source code of an AST or use the Rewriter to generate the code. So basically I just need to know how to remove a Stmt or other node from the AST/CFG. 

Sorry for the multiple followups.

Thanks again,
Kevin


On Jul 3, 2013, at 11:50 AM, Kevin Boos <kevinaboos at gmail.com> wrote:

> David,
> 
> Thanks, I'll take a look at ASTMatchers. 
> 
> The purposes of the analysis is to generate a subset of the source, where this subset is effectively a slice of statements that affect a given CallExpr (with certain extra statements added into that subset). I realize that slicing is better achieved with LLVM; I have already done this. This needs to be at the source level. My problem is merely how to delete a statement or other type of node from an AST or CFG, and then re-write the preprocessed source as output.
> 
> Thanks,
> Kevin
> 
> 
> On Wed, Jul 3, 2013 at 9:47 AM, David Blaikie <dblaikie at gmail.com> wrote:
> Attempting source to source transformations this way (via the ast/cfg) is generally not recommended. These devices are not intended (and thus don't work very well) for this purpose.
> 
> What's the goal of transforming the source in this way? If you're trying to instrument/test the resulting program behavior, consider an approach like the sanitizers (address/memory/thread sanitizer) that instruments code within clang's generation phase. If you're attempting to rewrite code, consider something like the ASTMatchers & tooling library.
> 
> On Jul 2, 2013 7:06 PM, "Kevin Boos" <kevinaboos at gmail.com> wrote:
> Hello all,
> 
> I'm working with a Clang plugin (it must be a plugin for kernel compilation reasons) that analyzes drivers in the Linux kernel for virtualization security purposes. 
> 
> I start by modifying the body of a function in a way that certain statements are deleted. Then I need to print out that modified source code so that it can be compiled and preferably human-readable. However, I want to expand all macros so that there are minimal external symbols in the generated code. I tried using the Rewriter class for this, but the Rewriter apparently prints out original source code only and cannot expand macros... is there an alternative source printer that can print the preprocessed code? 
> For reference, when calling "printPretty()" on the function's body Stmt*, the macros are expanded just like I want. 
> 
> My second question is about actually deleting those certain statement nodes in a CFG. I remember reading somewhere in the Clang docs that the CFG is a constant data structure that can't be modified. Is there a way to delete statements from the underlying AST so that they wouldn't appear in the CFG and also not appear in the re-printed source code?  To be clear, I'm using the CFG for other analysis reasons, but I don't really care if the Stmt nodes are deleted from the AST directly or from inside a CFG basic block.
> 
> Thanks in advance,
> Kevin Boos
> Rice University Ph.D. Candidate
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130703/117847bb/attachment.html>


More information about the cfe-dev mailing list