LLVM String Value objects: How can I retrieve the String from a Value?

给你一囗甜甜゛ 提交于 2019-12-04 02:19:26

Yes, ConstantArray is what you should use here. In order to retrieve the value later just use ConstantArray::getAsCString(). If you have assertions turned on, it will assert if something will went wrong (e.g. you will try to grab string from the array w/o zero terminator).

Running http://llvm.org/demo/ on the C code char *x = "asdf"; gives:

@.str = private unnamed_addr constant [5 x i8] c"asdf\00"
@x = global i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0), align 8

Basically, to get the address of a string, you have to build a global containing it. You can switch http://llvm.org/demo/ to output C++ API calls if you have trouble figuring out how to do that.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!