COFF: Simplify InputFile class.

Now that all InputFile subclasses have MemoryBufferRefs and
provides the same set of functions. Implement that in the base class.

llvm-svn: 239281
This commit is contained in:
Rui Ueyama 2015-06-08 03:27:57 +00:00
parent 9cf1abb8d4
commit f811472b4c

View File

@ -37,7 +37,7 @@ public:
virtual ~InputFile() {}
// Returns the filename.
virtual StringRef getName() = 0;
StringRef getName() { return MB.getBufferIdentifier(); }
// Returns symbols defined by this file.
virtual std::vector<SymbolBody *> &getSymbols() = 0;
@ -55,7 +55,8 @@ public:
void setParentName(StringRef N) { ParentName = N; }
protected:
explicit InputFile(Kind K) : FileKind(K) {}
explicit InputFile(Kind K, MemoryBufferRef M) : MB(M), FileKind(K) {}
MemoryBufferRef MB;
private:
const Kind FileKind;
@ -65,10 +66,9 @@ private:
// .lib or .a file.
class ArchiveFile : public InputFile {
public:
explicit ArchiveFile(MemoryBufferRef M) : InputFile(ArchiveKind), MB(M) {}
explicit ArchiveFile(MemoryBufferRef M) : InputFile(ArchiveKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
std::error_code parse() override;
StringRef getName() override { return Filename; }
// Returns a memory buffer for a given symbol. An empty memory buffer
// is returned if we have already returned the same memory buffer.
@ -81,7 +81,6 @@ public:
private:
std::unique_ptr<Archive> File;
std::string Filename;
MemoryBufferRef MB;
std::vector<SymbolBody *> SymbolBodies;
std::set<const char *> Seen;
llvm::MallocAllocator Alloc;
@ -90,10 +89,9 @@ private:
// .obj or .o file. This may be a member of an archive file.
class ObjectFile : public InputFile {
public:
explicit ObjectFile(MemoryBufferRef M) : InputFile(ObjectKind), MB(M) {}
explicit ObjectFile(MemoryBufferRef M) : InputFile(ObjectKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == ObjectKind; }
std::error_code parse() override;
StringRef getName() override { return MB.getBufferIdentifier(); }
std::vector<Chunk *> &getChunks() { return Chunks; }
std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
@ -115,7 +113,6 @@ private:
const void *Aux, bool IsFirst);
std::unique_ptr<COFFObjectFile> COFFObj;
MemoryBufferRef MB;
StringRef Directives;
llvm::BumpPtrAllocator Alloc;
@ -145,15 +142,13 @@ private:
// for details about the format.
class ImportFile : public InputFile {
public:
explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind), MB(M) {}
explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
StringRef getName() override { return MB.getBufferIdentifier(); }
std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
private:
std::error_code parse() override;
MemoryBufferRef MB;
std::vector<SymbolBody *> SymbolBodies;
llvm::BumpPtrAllocator Alloc;
StringAllocator StringAlloc;
@ -162,9 +157,8 @@ private:
// Used for LTO.
class BitcodeFile : public InputFile {
public:
explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind), MB(M) {}
explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
StringRef getName() override { return MB.getBufferIdentifier(); }
std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
LTOModule *getModule() const { return M.get(); }
@ -176,7 +170,6 @@ public:
private:
std::error_code parse() override;
MemoryBufferRef MB;
std::vector<SymbolBody *> SymbolBodies;
llvm::BumpPtrAllocator Alloc;
std::unique_ptr<LTOModule> M;