<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Danny,<div><br><div><div>On 2007-12-26, at 15:39, Danny wrote:</div><div><br class="webkit-block-placeholder"></div><div><div><blockquote type="cite" class="">I've noticed that the BitcodeReader appears to be an internal module, but the BitstreamReader is public. Should I be using the BitstreamReader? If so how.<br></blockquote><br></div><div>The generic <font class="Apple-style-span" face="Courier">BitstreamReader</font> class is public because it's used in other projects, including clang, to serialize data structures other than LLVM IR. The coding of the LLVM IR within the bitstream are private to the reader and writer modules. The functions exposed in <font class="Apple-style-span" face="Courier">ReaderWriter.h</font> are the public interface to that functionality.</div><div><br class="webkit-block-placeholder"></div></div><blockquote type="cite">I tried to get a module out of a file that I'd read in to it using this code:<br><br>MemoryBuffer* memBuf = MemoryBuffer::getFile(filename, sizeof  <br>filename, &errStr);<br>printf("errStr: %s\n", errStr.c_str());<br>BitcodeReader::BitcodeReader bcReader(memBuf);<br>Module* Mod = bcReader.materializeModule(&errInfo);<br>printf("errInfo: %s\n", errInfo.c_str());<br><span class="Apple-tab-span" style="white-space: pre; ">   </span><br>verifyModule(*Mod, PrintMessageAction);<br><br>The errStr and the errInfo strings were empty, but I got a crash on the verifyModule call.<br></blockquote></div><div><br></div></div><div>Try this:<br><div apple-content-edited="true"><div><br></div></div></div></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF">#include</font> <font class="Apple-style-span" color="#999999">"llvm/Bitcode/ReaderWriter.h"</font></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: Courier; ">...</span></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: Courier; ">std::string &Message;</span><br><span class="Apple-style-span" style="font-family: Courier; ">llvm::Module* Mod = llvm::ParseBitcodeFile(MemBuf, &Message);</span></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier"><font class="Apple-style-span" color="#0000FF">if</font> (!Mod) {</font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: Courier; "><font class="Apple-style-span" color="#FF0000">  // Message contains an error message.</font></span></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier">  std::cerr << "error reading bitcode: " << Message << "\n";</font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier">  exit(1);  <span class="Apple-style-span" style="color: rgb(255, 0, 0); ">// Don't segfault!</span></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: Courier; ">}</span></blockquote><blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 40px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span class="Apple-style-span" style="font-family: Courier; "><font class="Apple-style-span" color="#FF0000">// Okay, Mod is valid.</font></span></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier">...</font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><font class="Apple-style-span" face="Courier"><br class="webkit-block-placeholder"></font></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: Courier; "><font class="Apple-style-span" color="#0000FF">delete</font> Mod;</span></blockquote><div><div><div apple-content-edited="true"><div><div><div><br></div><div>Also note that the primary error indicator is not the string, but the return pointer, so you should always check that (not the error string) and stop if it's null in order to avoid segfaulting.</div></div></div></div></div></div><div><div><div apple-content-edited="true"><div><div><div><br class="webkit-block-placeholder"></div><div><span class="Apple-style-span" style="-webkit-text-stroke-width: -1; ">— Gordon</span></div></div></div></div></div><br></div></body></html>