[llvm-dev] Accessing constant contents

Krzysztof Parzyszek via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 3 10:05:34 PDT 2020


The "hello" string is a part of the GlobalVariable's initializer.  You can use GlobalVariable::getInitializer to get a Constant with the initializer value, and then, depending on the actual type of it you can get the contents of it.

--
Krzysztof Parzyszek  kparzysz at quicinc.com   AI tools development

-----Original Message-----
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of James Courtier-Dutton via llvm-dev
Sent: Saturday, August 1, 2020 3:25 PM
To: llvm-dev <llvm-dev at lists.llvm.org>
Subject: [EXT] [llvm-dev] Accessing constant contents

Hi,

I have a global variable in LLVM IR:

@mem8 = private unnamed_addr constant [9 x i8] c"Hello12\0A\00", align 1

I have loaded the module, so now have:
llvm::Value *value1;
...
value1->print(llvm::outs());
That will output:
@mem8 = private unnamed_addr constant [9 x i8] c"Hello12\0A\00", align 1

What method should I use to access the contents of the constant.
I.e. I want the "Hello12" bytes contained in @mem8 to be put in a std::vector<int8_t>

I can access the Type hierarchy, but cannot find how to access the value contents.

Kind Regards

James
_______________________________________________
LLVM Developers mailing list
llvm-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list