[LLVMdev] int to StringRed conversion
Logan Chien
tzuhsiang.chien at gmail.com
Thu May 2 07:42:33 PDT 2013
Hi,
I think you may try to use llvm::Twine(int). For example, to convert 30
to string, you can use:
Twine(30).str()
To convert the string back to integer, you can try the
StringRef::getAsInteger(unsigned, APInt &). For example:
APInt i;
str.getAsInteger(/*radix=*/ 10, /*output=*/ i);
Sincerely,
Logan
On Thu, May 2, 2013 at 9:53 PM, Alexandru Ionut Diaconescu <
alexandruionutdiaconescu at gmail.com> wrote:
> Hello everyone,
>
> I have an integer and I want to convert it to StringRef in order to set
> metadata.
> setMetadata->(StringRef, MDNode*);
>
> It is there a native LLVM way to do it?
>
> 1. In the llvm::APSInt Class is toString() method, which seems it is not
> for this purpose
> 2. itoa and string are not part of LLVM
> 3. stringstream is not part of LLVM
> 4. to_string is not part of LLVM
> 5. any casting method?
>
> Also, I would like to get the metadata and convert it back to integer.
>
> Thank you !
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130502/d7a38ca6/attachment.html>
More information about the llvm-dev
mailing list