<div dir="ltr"><div>I think the better solution should be:<br><br>LLVMContext& C = is->getContext();<br></div><div>Value *values[] = {<br></div><div> ConstantInt::getSigned(Type::getInt64Ty(C), <b>scsr</b>),<br></div>
<div> MDString::get(C, <b>"path"</b>)<br></div><div>};<br><br></div><div>lnstr.setMetadata(<b>"your_analysis_name"</b>, MDNode::get(C, values));<br><br></div><div>So that you can take advantage of the type system of LLVM bitcode, and don't have to cast the integers from/to strings by yourself.<br>
<br></div><div>Logan<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 2, 2013 at 11:10 PM, Alexandru Ionut Diaconescu <span dir="ltr"><<a href="mailto:alexandruionutdiaconescu@gmail.com" target="_blank">alexandruionutdiaconescu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>The problem is that I want to pass only srsr which is an int. "marked" was just an example :)</div>
<br><div>Thanks you!</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, May 2, 2013 at 5:06 PM, Logan Chien <span dir="ltr"><<a href="mailto:tzuhsiang.chien@gmail.com" target="_blank">tzuhsiang.chien@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>I'm not familiar with this, but maybe you can try:<br><br></div>StringRef tst = ("marked" + Twine(srsr)).str();<br><br></div><div>It seems that you can't use integer as meta data kind name.<span><font color="#888888"><br>
</font></span></div><span><font color="#888888"><div><br></div>Logan<br></font></span></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 2, 2013 at 10:59 PM, Alexandru Ionut Diaconescu <span dir="ltr"><<a href="mailto:alexandruionutdiaconescu@gmail.com" target="_blank">alexandruionutdiaconescu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Thank you for your help!<br><br></div>Almost solved my problem. Now I don't have any compilation errors. I have only one segfault:<br>
<br>opt: LLVMContext.cpp:147: unsigned int llvm::LLVMContext::getMDKindID(llvm::StringRef) const: Assertion `isValidName(Name) && "Invalid MDNode name"' failed.<br>
<br></div>This is due because when I setMetadata() it failes.<br><br>StringRef tsts = llvm::Twine(srsr).str();<br>....<br>LLVMContext& C = is->getContext();<br>MDNode* N = MDNode::get(C, MDString::get(C, "path"));<br>
is->setMetadata(tsts, N);<br><br><br></div>If I put <br>is->setMetadata("marked", N);, it goes ok and the .bc is modified. But if I directly put tsts it failes...<br><br></div>and the definition is : <br>
<table>
<tbody><tr><td>void Instruction::setMetadata </td>
<td>(</td>
<td><a href="http://llvm.org/docs/doxygen/html/classllvm_1_1StringRef.html" target="_blank">StringRef</a> </td>
<td><em>Kind</em>, </td>
</tr>
<tr>
<td><br></td>
<td><br></td>
<td><a href="http://llvm.org/docs/doxygen/html/classllvm_1_1MDNode.html" target="_blank">MDNode</a> * </td>
<td><em>Node</em> </td>
</tr>
<tr>
<td><br></td>
<td>)</td>
<td><br></td></tr></tbody></table><br><div><div><div>I don't know how I can use the tsts parameter..<br><br></div><div>Thank you again !<br></div></div></div></div><div class="gmail_extra"><div><div>
<br><br><div class="gmail_quote">
On Thu, May 2, 2013 at 4:42 PM, Logan Chien <span dir="ltr"><<a href="mailto:tzuhsiang.chien@gmail.com" target="_blank">tzuhsiang.chien@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div>Hi,<br><br></div> I think you may try to use llvm::Twine(int). For example, to convert 30 to string, you can use:<br><br></div><div>Twine(30).str()<br><br></div><div>To convert the string back to integer, you can try the StringRef::getAsInteger(unsigned, APInt &). For example:<br>
<br></div><div>APInt i;<br></div><div>str.getAsInteger(/*radix=*/ 10, /*output=*/ i);<br></div><div><br></div><div>Sincerely,<br>Logan<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
<div><div>
On Thu, May 2, 2013 at 9:53 PM, Alexandru Ionut Diaconescu <span dir="ltr"><<a href="mailto:alexandruionutdiaconescu@gmail.com" target="_blank">alexandruionutdiaconescu@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div>
<div dir="ltr">Hello everyone,
<div><br></div><div>I have an integer and I want to convert it to StringRef in order to set metadata.</div><div>setMetadata->(StringRef, MDNode*);</div><div><br></div><div>It is there a native LLVM way to do it?</div>
<div><br></div><div>1. In the llvm::APSInt Class is toString() method, which seems it is not for this purpose</div><div>2. itoa and string are not part of LLVM</div><div>3. stringstream is not part of LLVM</div>
<div>4. to_string is not part of LLVM</div><div>5. any casting method?</div><div><br></div><div>Also, I would like to get the metadata and convert it back to integer.</div><div><br></div><div>
Thank you !</div></div>
<br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br></div></div><span><font color="#888888">-- <br><font style="color:rgb(153,153,153)">Best regards,</font><br style="color:rgb(153,153,153)"><font style="color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>
</font></span></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><font style="color:rgb(153,153,153)">Best regards,</font><br style="color:rgb(153,153,153)">
<font style="color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>
</div>
</div></div></blockquote></div><br></div>