how can I parse a Value* ?

Hello everyone,

I have the following LLVM IR :

@.str = private unnamed_addr constant [3 x i8] c"DS\00", section “llvm.metadata”

@llvm.global.annotations = appending global [1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f to i8*), i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str1, i32 0, i32 0), i32 18 }], section “llvm.metadata”

I need to get @f (or maybe I can get somehow the definition of @f = global i32 0, align 4 ) and also I need to get “DS” from @.str. In my target code I have :

attribute((annotate(“DS”))) int f=0;

I have problems to parse @llvm.global.annotations and I assume I will have with @.str. What I tried:

for (Module::global_iterator I = F.global_begin(), E = F.global_end(); I != E; ++I) {
if (I->getName() == “llvm.global.annotations”) {
Value V = cast(I->getOperand(0));
errs()<<"\n "<<
(V)<<“\n”;
errs()<<“\n “<<*(V->getType())<<”\n”;

RESULT :

[1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f to i8*), i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str1, i32 0, i32 0), i32 18 }]

[1 x { i8*, i8*, i8*, i32 }]

errs()<<“\n “<<(V->getValueID())<<”\n”;
if(V->getValueID() == Value::ConstantArrayVal) {
ConstantArray *ca = (ConstantArray *)V;
errs()<<“\n “<<(ca[0])<<”\n”; }

RESULT :

[1 x { i8*, i8*, i8*, i32 }] [{ i8*, i8*, i8*, i32 } { i8* bitcast (i32* @f to i8*), i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8]* @.str1, i32 0, i32 0), i32 18 }]

Any help is welcomed ! Thank you !