Printing textual module to a std::string

Hi:
I have built/constructed mlir ops in memory and for testing I would like to print out the textual mlir module/ops to a std::string. Can it be done and how?

On a similar note, what would be the best way in mlir to test that in-memory created mlir matches the textual. Any suggestions would really help.

Thanks a lot.

Most IR construct have a print method that takes a raw_ostream. You can instantiate a raw_string_ostream and use it like here: llvm-project/Diagnostics.cpp at main · llvm/llvm-project · GitHub