Hi,
I'm writing some code that prints to std::ostream. However, it seems that all of the LLVM objects can only print to llvm::raw_ostream, so I can't do this:
void write(std::ostream &out) {
...
for (BasicBlock::iterator i = block->begin(), e = block->end(); i != e; ++i) {
Instruction *instruction = i;
out << *instruction << std::endl;
...
}
...
}
I tried working around this problem using the raw_os_ostream adapter:
#include <llvm/Support/raw_os_ostream.h>
...
raw_os_ostream raw_out(out);
raw_out << *instruction << std::endl;
It compiles fine, but opt gives a runtime error when trying to load the pass:
Symbol not found: __ZTVN4llvm14raw_os_ostreamE
Any thoughts on why this is happening? And is there a workaround that doesn't involve raw_os_ostream? Thanks,
Trevor
It's hard to say: __ZTVN4llvm14raw_os_ostreamE is the vtable for raw_os_ostream. This should be provided by lib/Support/raw_os_ostream.cpp. Perhaps you're not linking in that .o file for some reason. A workaround would be to use raw_ostream in your code instead of ostream 
-Chris
raw_os_ostream is definitely linked into Debug/lib/libLLVMSupport.a in my LLVM build. (Confirmed with otool.) I'm using the 2.7 release branch from a couple weeks ago.
Just for kicks, I added some code to my pass that creates a circular_raw_ostream object, and it runs without errors. I wonder what's different about raw_os_ostream... Any other possibilities?
Trevor
I can't think of anything special about it,
-Chris
Hi Trevor,
Just for kicks, I added some code to my pass that creates a
circular_raw_ostream object, and it runs without errors. I wonder
what's different about raw_os_ostream... Any other possibilities?
try to use "\n" instead of std::endl, AFAIK raw_ostream is not
overloaded for stuff like std::endl
Ciao, Fabian