<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">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).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Is it possible to create such a tool with clang, that will work on any compilable c file?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Rachel<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> mats.o.petersson@googlemail.com [mailto:mats.o.petersson@googlemail.com]
<b>On Behalf Of </b>mats petersson<br>
<b>Sent:</b> Monday, March 20, 2017 16:28<br>
<b>To:</b> Rachel HaCohen (rahacohe) <rahacohe@cisco.com><br>
<b>Cc:</b> cfe-dev@lists.llvm.org; Alon Shaltiel (ashaltie) <ashaltie@cisco.com><br>
<b>Subject:</b> Re: [cfe-dev] Using clang for c code control flow manipulations<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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.<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">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.<o:p></o:p></p>
</div>
<p class="MsoNormal">(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".)<br>
<br>
--<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Mats<o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On 19 March 2017 at 13:07, Rachel HaCohen (rahacohe) via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hello all,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">In a project we’re working on, we wish to build a tool that automatically manipulates
 c code.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">We</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E">
 wish to be able to track the control flow of the program and manipulate it (flattening</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#002060">, adding blocks</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E">
</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#002060">of code
</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E">etc.).</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">We want the tool to be very general and automatic an</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#002060;background:white">d</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">
 be able to work properly for every c file</span><i><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#002060;background:white">
</span></i><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#002060;background:white">and generate compilable code</span><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">Do you think this is achievable using clang? Do you have any tips for implementing
 this tool?</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">Many thanks,</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:#24292E;background:white">Rachel.</span><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>