创建raw_ostream对象并将其用于打印的正确方法是什么?我阅读了各种文章,我能找到的唯一示例是(How to redirect llvm::outs() to file?)
raw_ostream *output = &outs();
它利用了llvm::out。
很抱歉问这个问题,因为我不太熟悉C++,但必须了解LLVM是如何工作的。
创建raw_ostream对象并将其用于打印的正确方法是什么?我阅读了各种文章,我能找到的唯一示例是(How to redirect llvm::outs() to file?)
raw_ostream *output = &outs();
它利用了llvm::out。
很抱歉问这个问题,因为我不太熟悉C++,但必须了解LLVM是如何工作的。
1条答案
按热度按时间hmae6n7t1#
llvm::raw_ostream
is an abstract class with two important pure virtual functions implemented by subclasses;write_impl()
which holds the logic for writing data to the underlying stream andcurrent_pos()
which returns the position currently being written to in the stream.LLVM provides the following output stream implementations:
outs()
for writing to stdouterrs()
for writing to stderrnulls()
which discards the output (like writing to /dev/null)raw_fd_ostream(StringRef, std::error_code)
for writing to a file descriptorraw_string_ostream(std::string)
for writing to a std::stringThe first 3 streams directly return a reference to their stream objects. For example:
For the other streams, you construct objects the old way. For example:
For printing, every
llvm::Value*
has aprint
method that accepts araw_ostream
object.