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
1 changed files with 7 additions and 14 deletions

View File

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