<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=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* 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;}
span.EmailStyle17
        {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">This is a backward compatibility feature to an older compiler for those who do not have (or can’t use) debugger; but want to have an easy way of seeing the
 generated instructions for each C statement in simple text form.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Of course this problem may also be handled in a separate utility but since it is traditionally done in the compiler, I wanted to see if anyone in the llvm community
 has any solution other than the trivial one.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">(file + line) is enough for debugger, but for my case I need to know if the statement is multi-line in which case I would need to emit all lines before the
 instructions are emited for that statement; so some parsing would be needed to figure out that information.<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">A.<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"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Eli Bendersky [mailto:eliben@google.com]
<br>
<b>Sent:</b> Monday, April 15, 2013 3:31 PM<br>
<b>To:</b> Alireza Moshtaghi<br>
<b>Cc:</b> LLVM Developers Mailing List<br>
<b>Subject:</b> Re: [LLVMdev] Annotating output assembly with input C statements<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Mon, Apr 15, 2013 at 3:17 PM, Alireza Moshtaghi <<a href="mailto:Alireza.Moshtaghi@synopsys.com" target="_blank">Alireza.Moshtaghi@synopsys.com</a>> wrote:<o:p></o:p></p>
<p class="MsoNormal">Hi,<br>
I'm trying to annotate the final assembly output of my llvm codegen with the corresponding input C statements.<br>
It would've been super easy if the source information were included in the IR debug info. But obviously they are not, and there are good reasons why not !<br>
So I'm bound to collecting all my information in the back-end from the existing debug pseudo instructions. As you know, the debug instructions only have file name and line number information. But without actually parsing the input file and collecting the C
 statement and function start and end line numbers in the file, it would be a non-trivial task to emit proper source line information in the output assembly. Obviously, it is not recommended to use clang objects in the backend either, so I was wondering if
 anyone in the llvm community has attempted this before. Currently, I'm planning on writing my own parser but if someone has better solutions, please let me know.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">What, specifically, do you need a parser for? Specifying file+line pairs in debug info is standard practice. The debugger should then have access to the original C source file to show the code. Including input C code into every binary with
 debug info would blow up its size considerably (C files include a lot of code from include files...) and is unnecessary. Why is displaying a line of C code corresponding to some file+line pair more than just reading a specific line from a given file?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Eli<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>