Hello everyone,
I am trying to "parse" a part of LLVM IR. More exactly, from
@.str = private unnamed_addr constant [3 x i8] c"DS\00", section
"llvm.metadata"
I want to get "DS". It is the single place in the whole bytecode from
where
I can get it. I have :
...
Value *VV = cast<Value>(LD100->getOperand(1)->getOperand(0));
errs()<<"\n VV "<<*(VV)<<"\n";
RESULT : VV @.str = private unnamed_addr constant [3 x i8]
c"DS\00",
section "llvm.metadata"
if(VV->getValueID() == Value::GlobalVariableVal){
GlobalVariable* FD = cast<GlobalVariable>(VV);
Value *VVV = cast<Value>(FD->getOperand(0));
errs()<<"\n VVV "<<*(VVV)<<"\n";
RESULT : VVV [3 x i8] c"DS\00"
if(VVV->getValueID() == Value::ConstantDataArrayVal){
ConstantArray *caa = (ConstantArray *)VVV;
errs()<<"\n
"<<(caa->getNumOperands())<<"\n";
errs()<<"\n
"<<*(caa->getType())<<"\n";
RESULT : 0
[3 x i8]
}
>From this point, I tried to cast to every `enum llvm::Value::ValueTy` in
order to try to iterate through [3 X i8], in order to get "DS" (as a
StringRef or std::string would be nice), but I cannot. How I can parse this
structure?
Thank you for any help !
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20130304/fc99e5c5/attachment.html>
Alexandru Ionut Diaconescu <alexandruionutdiaconescu at gmail.com> writes:> Hello everyone, > > I am trying to "parse" a part of LLVM IR. More exactly, from > > @.str = private unnamed_addr constant [3 x i8] c"DS\00", section > "llvm.metadata" > > I want to get "DS". It is the single place in the whole bytecode from where > I can get it. I have :[snip] No specific help for your problem, but a generic one: pass your LLVM bytecode to llc -march=cpp <your-llvm-bytecode-file> you'll obtain a C++ file with the API calls for *generating* the bytecode. Seeing how the IR is generated, hopefully you will easily figure out how to access it.
Hi, On 04/03/13 11:23, Alexandru Ionut Diaconescu wrote:> Hello everyone, > > I am trying to "parse" a part of LLVM IR. More exactly, from > > @.str = private unnamed_addr constant [3 x i8] c"DS\00", section > "llvm.metadata" > > I want to get "DS". It is the single place in the whole bytecode from where I > can get it. I have : > > ... > Value *VV = cast<Value>(LD100->getOperand(1)->getOperand(0)); > errs()<<"\n VV "<<*(VV)<<"\n"; > RESULT : VV @.str = private unnamed_addr constant [3 x i8] c"DS\00", > section "llvm.metadata" > > if(VV->getValueID() == Value::GlobalVariableVal){ > GlobalVariable* FD = cast<GlobalVariable>(VV); > Value *VVV = cast<Value>(FD->getOperand(0)); > errs()<<"\n VVV "<<*(VVV)<<"\n"; > RESULT : VVV [3 x i8] c"DS\00" > > if(VVV->getValueID() == Value::ConstantDataArrayVal){ > ConstantArray *caa = (ConstantArray *)VVV; > errs()<<"\n "<<(caa->getNumOperands())<<"\n"; > errs()<<"\n "<<*(caa->getType())<<"\n"; > RESULT : 0 > [3 x i8] > } > > > From this point, I tried to cast to every `enum llvm::Value::ValueTy` in order > to try to iterate through [3 X i8], in order to get "DS" (as a StringRef or > std::string would be nice), but I cannot. How I can parse this structure? > > Thank you for any help !I think you are looking for ConstantDataSequential::getAsCString Note that ConstantDataArray derives from ConstantDataSequential. Ciao, Duncan. PS: rather than doing "VVV->getValueID() == Value::ConstantDataArrayVal" you can do: isa<ConstantDataArray>(VVV) Ciao, Duncan.