mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-21 21:41:43 +00:00
Return a std::unique_ptr from the IRReader.h functions. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216466 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1bfd87a150
commit
81e49922a8
@ -15,6 +15,8 @@
|
|||||||
#ifndef LLVM_IRREADER_IRREADER_H
|
#ifndef LLVM_IRREADER_IRREADER_H
|
||||||
#define LLVM_IRREADER_IRREADER_H
|
#define LLVM_IRREADER_IRREADER_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
@ -28,20 +30,21 @@ class LLVMContext;
|
|||||||
/// for it which does lazy deserialization of function bodies. Otherwise,
|
/// for it which does lazy deserialization of function bodies. Otherwise,
|
||||||
/// attempt to parse it as LLVM Assembly and return a fully populated
|
/// attempt to parse it as LLVM Assembly and return a fully populated
|
||||||
/// Module.
|
/// Module.
|
||||||
Module *getLazyIRFileModule(const std::string &Filename, SMDiagnostic &Err,
|
std::unique_ptr<Module> getLazyIRFileModule(StringRef Filename,
|
||||||
LLVMContext &Context);
|
SMDiagnostic &Err,
|
||||||
|
LLVMContext &Context);
|
||||||
|
|
||||||
/// If the given MemoryBuffer holds a bitcode image, return a Module
|
/// If the given MemoryBuffer holds a bitcode image, return a Module
|
||||||
/// for it. Otherwise, attempt to parse it as LLVM Assembly and return
|
/// for it. Otherwise, attempt to parse it as LLVM Assembly and return
|
||||||
/// a Module for it. This function *never* takes ownership of Buffer.
|
/// a Module for it. This function *never* takes ownership of Buffer.
|
||||||
Module *ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err, LLVMContext &Context);
|
std::unique_ptr<Module> parseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
|
||||||
|
LLVMContext &Context);
|
||||||
|
|
||||||
/// If the given file holds a bitcode image, return a Module for it.
|
/// If the given file holds a bitcode image, return a Module for it.
|
||||||
/// Otherwise, attempt to parse it as LLVM Assembly and return a Module
|
/// Otherwise, attempt to parse it as LLVM Assembly and return a Module
|
||||||
/// for it.
|
/// for it.
|
||||||
Module *ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
|
std::unique_ptr<Module> parseIRFile(StringRef Filename, SMDiagnostic &Err,
|
||||||
LLVMContext &Context);
|
LLVMContext &Context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -49,8 +49,9 @@ getLazyIRModule(std::unique_ptr<MemoryBuffer> Buffer, SMDiagnostic &Err,
|
|||||||
return parseAssembly(std::move(Buffer), Err, Context);
|
return parseAssembly(std::move(Buffer), Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *llvm::getLazyIRFileModule(const std::string &Filename,
|
std::unique_ptr<Module> llvm::getLazyIRFileModule(StringRef Filename,
|
||||||
SMDiagnostic &Err, LLVMContext &Context) {
|
SMDiagnostic &Err,
|
||||||
|
LLVMContext &Context) {
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
|
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
|
||||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||||
if (std::error_code EC = FileOrErr.getError()) {
|
if (std::error_code EC = FileOrErr.getError()) {
|
||||||
@ -59,33 +60,31 @@ Module *llvm::getLazyIRFileModule(const std::string &Filename,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getLazyIRModule(std::move(FileOrErr.get()), Err, Context).release();
|
return getLazyIRModule(std::move(FileOrErr.get()), Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *llvm::ParseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
|
std::unique_ptr<Module> llvm::parseIR(MemoryBuffer *Buffer, SMDiagnostic &Err,
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
|
NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName,
|
||||||
TimePassesIsEnabled);
|
TimePassesIsEnabled);
|
||||||
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
|
if (isBitcode((const unsigned char *)Buffer->getBufferStart(),
|
||||||
(const unsigned char *)Buffer->getBufferEnd())) {
|
(const unsigned char *)Buffer->getBufferEnd())) {
|
||||||
ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context);
|
ErrorOr<Module *> ModuleOrErr = parseBitcodeFile(Buffer, Context);
|
||||||
Module *M = nullptr;
|
if (std::error_code EC = ModuleOrErr.getError()) {
|
||||||
if (std::error_code EC = ModuleOrErr.getError())
|
|
||||||
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
|
Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error,
|
||||||
EC.message());
|
EC.message());
|
||||||
else
|
return nullptr;
|
||||||
M = ModuleOrErr.get();
|
}
|
||||||
// parseBitcodeFile does not take ownership of the Buffer.
|
return std::unique_ptr<Module>(ModuleOrErr.get());
|
||||||
return M;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseAssembly(std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer(
|
return parseAssembly(std::unique_ptr<MemoryBuffer>(MemoryBuffer::getMemBuffer(
|
||||||
Buffer->getBuffer(), Buffer->getBufferIdentifier())),
|
Buffer->getBuffer(), Buffer->getBufferIdentifier())),
|
||||||
Err, Context).release();
|
Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
|
std::unique_ptr<Module> llvm::parseIRFile(StringRef Filename, SMDiagnostic &Err,
|
||||||
LLVMContext &Context) {
|
LLVMContext &Context) {
|
||||||
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
|
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
|
||||||
MemoryBuffer::getFileOrSTDIN(Filename);
|
MemoryBuffer::getFileOrSTDIN(Filename);
|
||||||
if (std::error_code EC = FileOrErr.getError()) {
|
if (std::error_code EC = FileOrErr.getError()) {
|
||||||
@ -94,7 +93,7 @@ Module *llvm::ParseIRFile(const std::string &Filename, SMDiagnostic &Err,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ParseIR(FileOrErr.get().get(), Err, Context);
|
return parseIR(FileOrErr.get().get(), Err, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -107,7 +106,7 @@ LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
|
|||||||
SMDiagnostic Diag;
|
SMDiagnostic Diag;
|
||||||
|
|
||||||
std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
|
std::unique_ptr<MemoryBuffer> MB(unwrap(MemBuf));
|
||||||
*OutM = wrap(ParseIR(MB.get(), Diag, *unwrap(ContextRef)));
|
*OutM = wrap(parseIR(MB.get(), Diag, *unwrap(ContextRef)).release());
|
||||||
|
|
||||||
if(!*OutM) {
|
if(!*OutM) {
|
||||||
if (OutMessage) {
|
if (OutMessage) {
|
||||||
|
@ -85,7 +85,7 @@ BugDriver::~BugDriver() {
|
|||||||
std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename,
|
std::unique_ptr<Module> llvm::parseInputFile(StringRef Filename,
|
||||||
LLVMContext &Ctxt) {
|
LLVMContext &Ctxt) {
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
std::unique_ptr<Module> Result (ParseIRFile(Filename, Err, Ctxt));
|
std::unique_ptr<Module> Result = parseIRFile(Filename, Err, Ctxt);
|
||||||
if (!Result)
|
if (!Result)
|
||||||
Err.print("bugpoint", errs());
|
Err.print("bugpoint", errs());
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ static int compileModule(char **argv, LLVMContext &Context) {
|
|||||||
|
|
||||||
// If user just wants to list available options, skip module loading
|
// If user just wants to list available options, skip module loading
|
||||||
if (!SkipModule) {
|
if (!SkipModule) {
|
||||||
M.reset(ParseIRFile(InputFilename, Err, Context));
|
M = parseIRFile(InputFilename, Err, Context);
|
||||||
mod = M.get();
|
mod = M.get();
|
||||||
if (mod == nullptr) {
|
if (mod == nullptr) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
|
@ -399,7 +399,7 @@ int main(int argc, char **argv, char * const *envp) {
|
|||||||
|
|
||||||
// Load the bitcode...
|
// Load the bitcode...
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
std::unique_ptr<Module> Owner(ParseIRFile(InputFile, Err, Context));
|
std::unique_ptr<Module> Owner = parseIRFile(InputFile, Err, Context);
|
||||||
Module *Mod = Owner.get();
|
Module *Mod = Owner.get();
|
||||||
if (!Mod) {
|
if (!Mod) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
@ -513,7 +513,7 @@ int main(int argc, char **argv, char * const *envp) {
|
|||||||
|
|
||||||
// Load any additional modules specified on the command line.
|
// Load any additional modules specified on the command line.
|
||||||
for (unsigned i = 0, e = ExtraModules.size(); i != e; ++i) {
|
for (unsigned i = 0, e = ExtraModules.size(); i != e; ++i) {
|
||||||
std::unique_ptr<Module> XMod(ParseIRFile(ExtraModules[i], Err, Context));
|
std::unique_ptr<Module> XMod = parseIRFile(ExtraModules[i], Err, Context);
|
||||||
if (!XMod) {
|
if (!XMod) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -32,21 +32,22 @@ using namespace llvm;
|
|||||||
|
|
||||||
/// Reads a module from a file. On error, messages are written to stderr
|
/// Reads a module from a file. On error, messages are written to stderr
|
||||||
/// and null is returned.
|
/// and null is returned.
|
||||||
static Module *ReadModule(LLVMContext &Context, StringRef Name) {
|
static std::unique_ptr<Module> readModule(LLVMContext &Context,
|
||||||
|
StringRef Name) {
|
||||||
SMDiagnostic Diag;
|
SMDiagnostic Diag;
|
||||||
Module *M = ParseIRFile(Name, Diag, Context);
|
std::unique_ptr<Module> M = parseIRFile(Name, Diag, Context);
|
||||||
if (!M)
|
if (!M)
|
||||||
Diag.print("llvm-diff", errs());
|
Diag.print("llvm-diff", errs());
|
||||||
return M;
|
return M;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void diffGlobal(DifferenceEngine &Engine, Module *L, Module *R,
|
static void diffGlobal(DifferenceEngine &Engine, Module &L, Module &R,
|
||||||
StringRef Name) {
|
StringRef Name) {
|
||||||
// Drop leading sigils from the global name.
|
// Drop leading sigils from the global name.
|
||||||
if (Name.startswith("@")) Name = Name.substr(1);
|
if (Name.startswith("@")) Name = Name.substr(1);
|
||||||
|
|
||||||
Function *LFn = L->getFunction(Name);
|
Function *LFn = L.getFunction(Name);
|
||||||
Function *RFn = R->getFunction(Name);
|
Function *RFn = R.getFunction(Name);
|
||||||
if (LFn && RFn)
|
if (LFn && RFn)
|
||||||
Engine.diff(LFn, RFn);
|
Engine.diff(LFn, RFn);
|
||||||
else if (!LFn && !RFn)
|
else if (!LFn && !RFn)
|
||||||
@ -72,8 +73,8 @@ int main(int argc, char **argv) {
|
|||||||
LLVMContext Context;
|
LLVMContext Context;
|
||||||
|
|
||||||
// Load both modules. Die if that fails.
|
// Load both modules. Die if that fails.
|
||||||
Module *LModule = ReadModule(Context, LeftFilename);
|
std::unique_ptr<Module> LModule = readModule(Context, LeftFilename);
|
||||||
Module *RModule = ReadModule(Context, RightFilename);
|
std::unique_ptr<Module> RModule = readModule(Context, RightFilename);
|
||||||
if (!LModule || !RModule) return 1;
|
if (!LModule || !RModule) return 1;
|
||||||
|
|
||||||
DiffConsumer Consumer;
|
DiffConsumer Consumer;
|
||||||
@ -82,15 +83,12 @@ int main(int argc, char **argv) {
|
|||||||
// If any global names were given, just diff those.
|
// If any global names were given, just diff those.
|
||||||
if (!GlobalsToCompare.empty()) {
|
if (!GlobalsToCompare.empty()) {
|
||||||
for (unsigned I = 0, E = GlobalsToCompare.size(); I != E; ++I)
|
for (unsigned I = 0, E = GlobalsToCompare.size(); I != E; ++I)
|
||||||
diffGlobal(Engine, LModule, RModule, GlobalsToCompare[I]);
|
diffGlobal(Engine, *LModule, *RModule, GlobalsToCompare[I]);
|
||||||
|
|
||||||
// Otherwise, diff everything in the module.
|
// Otherwise, diff everything in the module.
|
||||||
} else {
|
} else {
|
||||||
Engine.diff(LModule, RModule);
|
Engine.diff(LModule.get(), RModule.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
delete LModule;
|
|
||||||
delete RModule;
|
|
||||||
|
|
||||||
return Consumer.hadDifferences();
|
return Consumer.hadDifferences();
|
||||||
}
|
}
|
||||||
|
@ -101,8 +101,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// Use lazy loading, since we only care about selected global values.
|
// Use lazy loading, since we only care about selected global values.
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M = getLazyIRFileModule(InputFilename, Err, Context);
|
||||||
M.reset(getLazyIRFileModule(InputFilename, Err, Context));
|
|
||||||
|
|
||||||
if (!M.get()) {
|
if (!M.get()) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
|
@ -55,17 +55,16 @@ static cl::opt<bool>
|
|||||||
SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
|
SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
|
||||||
cl::init(false));
|
cl::init(false));
|
||||||
|
|
||||||
// LoadFile - Read the specified bitcode file in and return it. This routine
|
// Read the specified bitcode file in and return it. This routine searches the
|
||||||
// searches the link path for the specified file to try to find it...
|
// link path for the specified file to try to find it...
|
||||||
//
|
//
|
||||||
static inline Module *LoadFile(const char *argv0, const std::string &FN,
|
static std::unique_ptr<Module>
|
||||||
LLVMContext& Context) {
|
loadFile(const char *argv0, const std::string &FN, LLVMContext &Context) {
|
||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
if (Verbose) errs() << "Loading '" << FN << "'\n";
|
if (Verbose) errs() << "Loading '" << FN << "'\n";
|
||||||
Module* Result = nullptr;
|
std::unique_ptr<Module> Result = parseIRFile(FN, Err, Context);
|
||||||
|
if (Result)
|
||||||
Result = ParseIRFile(FN, Err, Context);
|
return Result;
|
||||||
if (Result) return Result; // Load successful!
|
|
||||||
|
|
||||||
Err.print(argv0, errs());
|
Err.print(argv0, errs());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -83,8 +82,8 @@ int main(int argc, char **argv) {
|
|||||||
unsigned BaseArg = 0;
|
unsigned BaseArg = 0;
|
||||||
std::string ErrorMessage;
|
std::string ErrorMessage;
|
||||||
|
|
||||||
std::unique_ptr<Module> Composite(
|
std::unique_ptr<Module> Composite =
|
||||||
LoadFile(argv[0], InputFilenames[BaseArg], Context));
|
loadFile(argv[0], InputFilenames[BaseArg], Context);
|
||||||
if (!Composite.get()) {
|
if (!Composite.get()) {
|
||||||
errs() << argv[0] << ": error loading file '"
|
errs() << argv[0] << ": error loading file '"
|
||||||
<< InputFilenames[BaseArg] << "'\n";
|
<< InputFilenames[BaseArg] << "'\n";
|
||||||
@ -93,7 +92,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
Linker L(Composite.get(), SuppressWarnings);
|
Linker L(Composite.get(), SuppressWarnings);
|
||||||
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
|
for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
|
||||||
std::unique_ptr<Module> M(LoadFile(argv[0], InputFilenames[i], Context));
|
std::unique_ptr<Module> M = loadFile(argv[0], InputFilenames[i], Context);
|
||||||
if (!M.get()) {
|
if (!M.get()) {
|
||||||
errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
|
errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -362,8 +362,7 @@ int main(int argc, char **argv) {
|
|||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
|
|
||||||
// Load the input module...
|
// Load the input module...
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
|
||||||
M.reset(ParseIRFile(InputFilename, Err, Context));
|
|
||||||
|
|
||||||
if (!M.get()) {
|
if (!M.get()) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
|
@ -520,8 +520,7 @@ int main(int argc, char **argv) {
|
|||||||
SMDiagnostic Err;
|
SMDiagnostic Err;
|
||||||
|
|
||||||
// Load the input module...
|
// Load the input module...
|
||||||
std::unique_ptr<Module> M;
|
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
|
||||||
M.reset(ParseIRFile(InputFilename, Err, Context));
|
|
||||||
|
|
||||||
if (!M.get()) {
|
if (!M.get()) {
|
||||||
Err.print(argv[0], errs());
|
Err.print(argv[0], errs());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user