Hi, I'm currently trying to translate LLVM IR language to VPO .dec file specification. I'm using LLVM source parser in the same way that it is used in tools llc or llvm-as. One issue I'm having is I cannot find any static values. For example, in a global declaration i.e. '@a = global i32 7, align 4' I cannot get '7' from the parsed structure. Similarly (sort of), once I'm looking at a parsed Function, and I go into a BasicBlock, and get say and add Instruction, and I get its operands, I can't get static values. If for example the Instruction was '%add = add i32 %tmp, 60', I can get the name of value 'tmp' which is enough, but I can't get the value '60'. Thank you for any help. -Brandon D ---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
On Sat, Sep 24, 2011 at 12:21 PM, <bdavis at cs.fsu.edu> wrote:> Hi, > > I'm currently trying to translate LLVM IR language to VPO .dec file > specification. I'm using LLVM source parser in the same way that it is > used in tools llc or llvm-as. One issue I'm having is I cannot find > any static values. For example, in a global declaration i.e. '@a > global i32 7, align 4' I cannot get '7' from the parsed structure.llvm::GlobalVariable::getInitializer()?> Similarly (sort of), once I'm looking at a parsed Function, and I go > into a BasicBlock, and get say and add Instruction, and I get its > operands, I can't get static values. If for example the Instruction > was '%add = add i32 %tmp, 60', I can get the name of value 'tmp' which > is enough, but I can't get the value '60'.60 is an llvm::ConstantInt. If you're still having trouble, feel free to ask more questions. -Eli
On 09/24/2011 12:21 PM, bdavis at cs.fsu.edu wrote:> Hi, > > I'm currently trying to translate LLVM IR language to VPO .dec file > specification. I'm using LLVM source parser in the same way that it is > used in tools llc or llvm-as. One issue I'm having is I cannot find > any static values. For example, in a global declaration i.e. '@a > global i32 7, align 4' I cannot get '7' from the parsed structure.GlobalVariable has the method getInitializer() which will return a Constant*. You can then dyn_cast<ConstantInt*>(...) that value to turn it into a ConstantInt and retrieve the concrete number from it. If it's not an integer, the dyn_cast will return NULL.> > Similarly (sort of), once I'm looking at a parsed Function, and I go > into a BasicBlock, and get say and add Instruction, and I get its > operands, I can't get static values. If for example the Instruction > was '%add = add i32 %tmp, 60', I can get the name of value 'tmp' which > is enough, but I can't get the value '60'.I->getOperand(1) retrieves the second operand as a Value*. If a dyn_cast to ConstantInt* is successful, then it's a constant integer and you can read off the value with getValue(). In general, I recommend familiarizing yourself with the class hierarchies for Value and Type. I keep this page bookmarked: http://llvm.org/doxygen/hierarchy.html for these sorts of questions. Nick