<div>For those targets supported by LLVM, you can get their TargetData by creating TargetMachine first (take X86 as example):</div><div><div><br></div><div>==== BEGIN CODE SNIPPET ====</div><div><div>    const std::string TripleStr = "i686-unknown-linux"; // hard coded for example</div>


<div>    const std::string FeatureStr = ""; // hard coded for example</div><div>    std::string Err;</div><div>    const Target* T;</div><div>    TargetMachine* TM = NULL;</div><div>    const TargetData* TD;</div>


<div><br></div><div>    // Or just call InitializeAllTargetInfos() and InitializeAllTargets() for all targets enabled by your LLVM build.</div><div>    LLVMInitializeX86TargetInfo();</div><div>    LLVMInitializeX86Target();</div>


<div><br></div><div>    T = TargetRegistry::lookupTarget(TripleStr, Err);</div><div>    if(!Err.empty())</div><div>        // error handling</div><div><br></div><div>    // Create TargetMachine</div><div>    TM = T->createTargetMachine(TripleStr, FeatureStr);</div>


<div>    if(TM == NULL)</div><div>        // error handling</div><div><br></div><div>    // TD is what you want.</div><div>    TD = TM->getTargetData();</div><div><br></div><div>    [...]</div><div><br></div><div>    // Free TM</div>


<div>    delete TM;</div><div>==== END CODE SNIPPET ====</div><div><br></div><div>For your case, you should be able to find TripleStr and FeatureStr in somewhere.</div><div><br></div><div>And also there's a constructor in TargetData (<a href="http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707" target="_blank">http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707</a>) takeing a string "TargetDescription". The string specifies the data layout of a target and its format is described here <a href="http://llvm.org/docs/LangRef.html#datalayout" target="_blank">http://llvm.org/docs/LangRef.html#datalayout</a>. Thus, if you are developing a customized target and/or you are really know the data layout specification about your target, you can get a TargetData instance by simply passing the hand-coded data layout string to the constructor of TargetData.</div>


<div><br></div><div>Hope this will be helpful to you.</div><div><br></div><div>Zonr</div><div><br></div></div><div><div><div><div><br><div class="gmail_quote">On Fri, May 28, 2010 at 11:27 PM, Victor Zverovich <span dir="ltr"><<a href="mailto:victor.zverovich@googlemail.com" target="_blank">victor.zverovich@googlemail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all<div><br></div><div>I am trying to get the size of an LLVM pointer type.</div><div>getPrimitiveSizeInBits() returns 0 for it and the documentation for isSized() suggest to use TargetData.</div>




<div>I figured out from Kaleidoscope example that one can get a pointer to TagetData object through the execution engine but it seems to be an overkill.</div><div>What is the right way to do it?</div><div><br></div><div>



Best regards,</div>
<div>Victor</div><font color="#888888"><div><br></div>
</font><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div></div></div></div>