[LLVMdev] LLVMContext: Suggestions for API Changes

Albert Graef Dr.Graef at t-online.de
Sun Aug 23 17:06:26 PDT 2009


Dan Gohman wrote:
> Are you printing to stderr or errs()? If so, be aware that it's no
> longer buffered, so it isn't well suited for bulk output.  Stdout and
> normal file output are still buffered though.

I'm using raw_fd_ostream. It gets initialized like this:

  string error;
  llvm::raw_ostream *codep = file_target?
    new llvm::raw_fd_ostream(target.c_str(), error,
			     llvm::raw_fd_ostream::F_Force):
    new llvm::raw_stdout_ostream();
  if (!error.empty()) {
    std::cerr << "Error opening " << target << '\n';
    exit(1);
  }
  llvm::raw_ostream &code = *codep;

(Yeah, it's a bit convoluted, since I'm allowing output to either stdout
or a disk file here.)

Lateron I then iterate over the global variables and functions of my
module, decide which ones to keep, and output code for these using
something like f->print(code).

Anything wrong with that?

Albert

-- 
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email:  Dr.Graef at t-online.de, ag at muwiinfa.geschichte.uni-mainz.de
WWW:    http://www.musikinformatik.uni-mainz.de/ag



More information about the llvm-dev mailing list