[lld] r239281 - COFF: Simplify InputFile class.
Rui Ueyama
ruiu at google.com
Sun Jun 7 20:27:57 PDT 2015
Author: ruiu
Date: Sun Jun 7 22:27:57 2015
New Revision: 239281
URL: http://llvm.org/viewvc/llvm-project?rev=239281&view=rev
Log:
COFF: Simplify InputFile class.
Now that all InputFile subclasses have MemoryBufferRefs and
provides the same set of functions. Implement that in the base class.
Modified:
lld/trunk/COFF/InputFiles.h
Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=239281&r1=239280&r2=239281&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Sun Jun 7 22:27:57 2015
@@ -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;
More information about the llvm-commits
mailing list