本文整理汇总了C++中raw_fd_ostream::close方法的典型用法代码示例。如果您正苦于以下问题:C++ raw_fd_ostream::close方法的具体用法?C++ raw_fd_ostream::close怎么用?C++ raw_fd_ostream::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类raw_fd_ostream
的用法示例。
在下文中一共展示了raw_fd_ostream::close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteBundleEnd
bool WriteBundleEnd(raw_fd_ostream &OS, StringRef TargetTriple) final {
assert(NumberOfProcessedInputs <= NumberOfInputs &&
"Processing more inputs that actually exist!");
assert(HostInputIndex != ~0u && "Host input index not defined.");
// If this is not the last output, we don't have to do anything.
if (NumberOfProcessedInputs != NumberOfInputs)
return false;
// Create the bitcode file name to write the resulting code to. Keep it if
// save-temps is active.
SmallString<128> BitcodeFileName;
if (sys::fs::createTemporaryFile("clang-offload-bundler", "bc",
BitcodeFileName)) {
errs() << "error: unable to create temporary file.\n";
return true;
}
// Dump the contents of the temporary file if that was requested.
if (DumpTemporaryFiles) {
errs() << ";\n; Object file bundler IR file.\n;\n";
AuxModule.get()->print(errs(), nullptr,
/*ShouldPreserveUseListOrder=*/false,
/*IsForDebug=*/true);
errs() << '\n';
}
// Find clang in order to create the bundle binary.
StringRef Dir = sys::path::parent_path(BundlerExecutable);
auto ClangBinary = sys::findProgramByName("clang", Dir);
if (ClangBinary.getError()) {
// Remove bitcode file.
sys::fs::remove(BitcodeFileName);
errs() << "error: unable to find 'clang' in path.\n";
return true;
}
// Do the incremental linking. We write to the output file directly. So, we
// close it and use the name to pass down to clang.
OS.close();
SmallString<128> TargetName = getTriple(TargetNames[HostInputIndex]);
std::vector<StringRef> ClangArgs = {"clang",
"-r",
"-target",
TargetName.c_str(),
"-o",
OutputFileNames.front().c_str(),
InputFileNames[HostInputIndex].c_str(),
BitcodeFileName.c_str(),
"-nostdlib"};
// If the user asked for the commands to be printed out, we do that instead
// of executing it.
if (PrintExternalCommands) {
errs() << "\"" << ClangBinary.get() << "\"";
for (StringRef Arg : ClangArgs)
errs() << " \"" << Arg << "\"";
errs() << "\n";
} else {
// Write the bitcode contents to the temporary file.
{
std::error_code EC;
raw_fd_ostream BitcodeFile(BitcodeFileName, EC, sys::fs::F_None);
if (EC) {
errs() << "error: unable to open temporary file.\n";
return true;
}
WriteBitcodeToFile(*AuxModule, BitcodeFile);
}
bool Failed = sys::ExecuteAndWait(ClangBinary.get(), ClangArgs);
// Remove bitcode file.
sys::fs::remove(BitcodeFileName);
if (Failed) {
errs() << "error: incremental linking by external tool failed.\n";
return true;
}
}
return false;
}