unique_ptrify CompilerInstance::OutputFile(s) and remove a unique_ptr around a non-owning raw_ostream in CodeGenAction::CreateASTConsumer
llvm-svn: 215331
This commit is contained in:
parent
3a908a0bfc
commit
3b0e32bf61
|
@ -144,11 +144,11 @@ class CompilerInstance : public ModuleLoader {
|
||||||
struct OutputFile {
|
struct OutputFile {
|
||||||
std::string Filename;
|
std::string Filename;
|
||||||
std::string TempFilename;
|
std::string TempFilename;
|
||||||
raw_ostream *OS;
|
std::unique_ptr<raw_ostream> OS;
|
||||||
|
|
||||||
OutputFile(const std::string &filename, const std::string &tempFilename,
|
OutputFile(const std::string &filename, const std::string &tempFilename,
|
||||||
raw_ostream *os)
|
std::unique_ptr<raw_ostream> OS)
|
||||||
: Filename(filename), TempFilename(tempFilename), OS(os) { }
|
: Filename(filename), TempFilename(tempFilename), OS(std::move(OS)) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The list of active output files.
|
/// The list of active output files.
|
||||||
|
@ -508,7 +508,7 @@ public:
|
||||||
/// addOutputFile - Add an output file onto the list of tracked output files.
|
/// addOutputFile - Add an output file onto the list of tracked output files.
|
||||||
///
|
///
|
||||||
/// \param OutFile - The output file info.
|
/// \param OutFile - The output file info.
|
||||||
void addOutputFile(const OutputFile &OutFile);
|
void addOutputFile(OutputFile OutFile);
|
||||||
|
|
||||||
/// clearOutputFiles - Clear the output file list, destroying the contained
|
/// clearOutputFiles - Clear the output file list, destroying the contained
|
||||||
/// output streams.
|
/// output streams.
|
||||||
|
@ -657,14 +657,11 @@ public:
|
||||||
/// stored here on success.
|
/// stored here on success.
|
||||||
/// \param TempPathName [out] - If given, the temporary file path name
|
/// \param TempPathName [out] - If given, the temporary file path name
|
||||||
/// will be stored here on success.
|
/// will be stored here on success.
|
||||||
static llvm::raw_fd_ostream *
|
static std::unique_ptr<llvm::raw_fd_ostream>
|
||||||
createOutputFile(StringRef OutputPath, std::string &Error,
|
createOutputFile(StringRef OutputPath, std::string &Error, bool Binary,
|
||||||
bool Binary, bool RemoveFileOnSignal,
|
bool RemoveFileOnSignal, StringRef BaseInput,
|
||||||
StringRef BaseInput,
|
StringRef Extension, bool UseTemporary,
|
||||||
StringRef Extension,
|
bool CreateMissingDirectories, std::string *ResultPathName,
|
||||||
bool UseTemporary,
|
|
||||||
bool CreateMissingDirectories,
|
|
||||||
std::string *ResultPathName,
|
|
||||||
std::string *TempPathName);
|
std::string *TempPathName);
|
||||||
|
|
||||||
llvm::raw_null_ostream *createNullOutputFile();
|
llvm::raw_null_ostream *createNullOutputFile();
|
||||||
|
|
|
@ -610,7 +610,7 @@ static raw_ostream *GetOutputStream(CompilerInstance &CI,
|
||||||
std::unique_ptr<ASTConsumer>
|
std::unique_ptr<ASTConsumer>
|
||||||
CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||||
BackendAction BA = static_cast<BackendAction>(Act);
|
BackendAction BA = static_cast<BackendAction>(Act);
|
||||||
std::unique_ptr<raw_ostream> OS(GetOutputStream(CI, InFile, BA));
|
raw_ostream *OS = GetOutputStream(CI, InFile, BA);
|
||||||
if (BA != Backend_EmitNothing && !OS)
|
if (BA != Backend_EmitNothing && !OS)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
@ -649,7 +649,7 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
|
||||||
std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
|
std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
|
||||||
BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(),
|
BA, CI.getDiagnostics(), CI.getCodeGenOpts(), CI.getTargetOpts(),
|
||||||
CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
|
CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
|
||||||
LinkModuleToUse, OS.release(), *VMContext, CoverageInfo));
|
LinkModuleToUse, OS, *VMContext, CoverageInfo));
|
||||||
BEConsumer = Result.get();
|
BEConsumer = Result.get();
|
||||||
return std::move(Result);
|
return std::move(Result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -518,15 +518,15 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind,
|
||||||
|
|
||||||
// Output Files
|
// Output Files
|
||||||
|
|
||||||
void CompilerInstance::addOutputFile(const OutputFile &OutFile) {
|
void CompilerInstance::addOutputFile(OutputFile OutFile) {
|
||||||
assert(OutFile.OS && "Attempt to add empty stream to output list!");
|
assert(OutFile.OS && "Attempt to add empty stream to output list!");
|
||||||
OutputFiles.push_back(OutFile);
|
OutputFiles.push_back(std::move(OutFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompilerInstance::clearOutputFiles(bool EraseFiles) {
|
void CompilerInstance::clearOutputFiles(bool EraseFiles) {
|
||||||
for (std::list<OutputFile>::iterator
|
for (std::list<OutputFile>::iterator
|
||||||
it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
|
it = OutputFiles.begin(), ie = OutputFiles.end(); it != ie; ++it) {
|
||||||
delete it->OS;
|
it->OS.reset();
|
||||||
if (!it->TempFilename.empty()) {
|
if (!it->TempFilename.empty()) {
|
||||||
if (EraseFiles) {
|
if (EraseFiles) {
|
||||||
llvm::sys::fs::remove(it->TempFilename);
|
llvm::sys::fs::remove(it->TempFilename);
|
||||||
|
@ -561,9 +561,10 @@ CompilerInstance::createDefaultOutputFile(bool Binary,
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() {
|
llvm::raw_null_ostream *CompilerInstance::createNullOutputFile() {
|
||||||
llvm::raw_null_ostream *OS = new llvm::raw_null_ostream();
|
auto OS = llvm::make_unique<llvm::raw_null_ostream>();
|
||||||
addOutputFile(OutputFile("", "", OS));
|
auto *Res = OS.get();
|
||||||
return OS;
|
addOutputFile(OutputFile("", "", std::move(OS)));
|
||||||
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::raw_fd_ostream *
|
llvm::raw_fd_ostream *
|
||||||
|
@ -574,7 +575,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
bool UseTemporary,
|
bool UseTemporary,
|
||||||
bool CreateMissingDirectories) {
|
bool CreateMissingDirectories) {
|
||||||
std::string Error, OutputPathName, TempPathName;
|
std::string Error, OutputPathName, TempPathName;
|
||||||
llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
|
auto OS = createOutputFile(OutputPath, Error, Binary,
|
||||||
RemoveFileOnSignal,
|
RemoveFileOnSignal,
|
||||||
InFile, Extension,
|
InFile, Extension,
|
||||||
UseTemporary,
|
UseTemporary,
|
||||||
|
@ -587,15 +588,16 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto *Res = OS.get();
|
||||||
// Add the output file -- but don't try to remove "-", since this means we are
|
// Add the output file -- but don't try to remove "-", since this means we are
|
||||||
// using stdin.
|
// using stdin.
|
||||||
addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "",
|
addOutputFile(OutputFile((OutputPathName != "-") ? OutputPathName : "",
|
||||||
TempPathName, OS));
|
TempPathName, std::move(OS)));
|
||||||
|
|
||||||
return OS;
|
return Res;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::raw_fd_ostream *
|
std::unique_ptr<llvm::raw_fd_ostream>
|
||||||
CompilerInstance::createOutputFile(StringRef OutputPath,
|
CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
std::string &Error,
|
std::string &Error,
|
||||||
bool Binary,
|
bool Binary,
|
||||||
|
@ -663,7 +665,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!EC) {
|
if (!EC) {
|
||||||
OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
|
OS = llvm::make_unique<llvm::raw_fd_ostream>(fd, /*shouldClose=*/true);
|
||||||
OSFile = TempFile = TempPath.str();
|
OSFile = TempFile = TempPath.str();
|
||||||
}
|
}
|
||||||
// If we failed to create the temporary, fallback to writing to the file
|
// If we failed to create the temporary, fallback to writing to the file
|
||||||
|
@ -673,9 +675,9 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
|
|
||||||
if (!OS) {
|
if (!OS) {
|
||||||
OSFile = OutFile;
|
OSFile = OutFile;
|
||||||
OS.reset(new llvm::raw_fd_ostream(
|
OS = llvm::make_unique<llvm::raw_fd_ostream>(
|
||||||
OSFile.c_str(), Error,
|
OSFile.c_str(), Error,
|
||||||
(Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text)));
|
(Binary ? llvm::sys::fs::F_None : llvm::sys::fs::F_Text));
|
||||||
if (!Error.empty())
|
if (!Error.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -689,7 +691,7 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
|
||||||
if (TempPathName)
|
if (TempPathName)
|
||||||
*TempPathName = TempFile;
|
*TempPathName = TempFile;
|
||||||
|
|
||||||
return OS.release();
|
return OS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization Utilities
|
// Initialization Utilities
|
||||||
|
|
Loading…
Reference in New Issue