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

后端 未结 2 838
野趣味
野趣味 2021-02-20 16:30

When building the IR from an existing AST, my AST has some string values (at compile-time they are built from std::string) and I want to set them safely as ll

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-20 16:40

    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.

提交回复
热议问题