[cfe-dev] Using clang for c code control flow manipulations

Rachel HaCohen (rahacohe) via cfe-dev cfe-dev at lists.llvm.org
Mon Mar 20 07:35:22 PDT 2017


Thanks.

Let’s say I want to create a tool that simply replaces every “while” block with an “if” block (and a goto in the end – to make it work the same).
Is it possible to create such a tool with clang, that will work on any compilable c file?

Rachel

From: mats.o.petersson at googlemail.com [mailto:mats.o.petersson at googlemail.com] On Behalf Of mats petersson
Sent: Monday, March 20, 2017 16:28
To: Rachel HaCohen (rahacohe) <rahacohe at cisco.com>
Cc: cfe-dev at lists.llvm.org; Alon Shaltiel (ashaltie) <ashaltie at cisco.com>
Subject: Re: [cfe-dev] Using clang for c code control flow manipulations

With this sort of thing, "the devil is in the detail". Yes, clang has tools to do things to source-code, and there are other tools to do things with the intermediate form in llvm.
But without fully understanding more in detail what changes you are wanting to do, and how those are meant to interact with the overall source code, it's hard to say exactly what is the best approach.
(I'm far from sure I can give any appropriate advice, but I know enough about the subject to know that there can be difficulties, and the exact details is what makes the difference between "approach A is good", "approach B" is good and "it's impossible no matter what".)

--
Mats

On 19 March 2017 at 13:07, Rachel HaCohen (rahacohe) via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:
Hello all,
In a project we’re working on, we wish to build a tool that automatically manipulates c code.
We wish to be able to track the control flow of the program and manipulate it (flattening, adding blocks of code etc.).
We want the tool to be very general and automatic and be able to work properly for every c file and generate compilable code.

Do you think this is achievable using clang? Do you have any tips for implementing this tool?
Many thanks,
Rachel.

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170320/7f8285a7/attachment.html>


More information about the cfe-dev mailing list