@@ -79,10 +79,6 @@ void registerFromSPIRVTranslation() {
7979// Serialization registration
8080// ===----------------------------------------------------------------------===//
8181
82- // Static variable is probably not ideal, but it lets us have unique files names
83- // without taking additional parameters from `mlir-translate`.
84- static size_t validationFileCounter = 0 ;
85-
8682static LogicalResult
8783serializeModule (spirv::ModuleOp moduleOp, raw_ostream &output,
8884 const spirv::SerializationOptions &options) {
@@ -106,18 +102,22 @@ serializeModule(spirv::ModuleOp moduleOp, raw_ostream &output,
106102 return failure ();
107103 }
108104 }
109- std::string errorMessage;
110- std::string filename =
111- options.validationFilePrefix + std::to_string (validationFileCounter++);
112- std::unique_ptr<llvm::ToolOutputFile> validationOutput =
113- openOutputFile (filename, &errorMessage);
114- if (!validationOutput) {
115- llvm::errs () << errorMessage << " \n " ;
105+
106+ SmallString<128 > filename;
107+ int fd;
108+
109+ std::error_code errorCode = llvm::sys::fs::createUniqueFile (
110+ options.validationFilePrefix + " %%%%%%" , fd, filename);
111+ if (errorCode) {
112+ llvm::errs () << " error creating validation output file: "
113+ << errorCode.message () << " \n " ;
116114 return failure ();
117115 }
118- validationOutput->os ().write (reinterpret_cast <char *>(binary.data ()),
119- sizeInBytes);
120- validationOutput->keep ();
116+
117+ llvm::raw_fd_ostream validationOutput (fd, /* shouldClose=*/ true );
118+ validationOutput.write (reinterpret_cast <char *>(binary.data ()),
119+ sizeInBytes);
120+ validationOutput.flush ();
121121 }
122122
123123 return mlir::success ();
0 commit comments