Replace SimpleFileWrapper with a function.

SimpleFileWrapper was a class to wrap an existing (possibly non-mutable)
file as a mutable file. We used instances of the class in RoundTrip*
passes, because the passes convert mutable files to non-mutable files,
and we needed to convert them back to mutable.

That feature can be implemented without defining a new class. Generally
speaking, if we can implement a feature without defining a class and
using only public interface of exsiting classes, that's preferred way
to do that. And this is the case.

llvm-svn: 227549
This commit is contained in:
Rui Ueyama 2015-01-30 02:11:59 +00:00
parent 38522b8867
commit 78e2a2df22
3 changed files with 16 additions and 17 deletions

View File

@ -25,6 +25,18 @@
namespace lld {
// Copy all atoms from src to dst. Atom ownership is not transferred.
inline void copyAtoms(MutableFile *dst, File *src) {
for (const DefinedAtom *atom : src->defined())
dst->addAtom(*atom);
for (const UndefinedAtom *atom : src->undefined())
dst->addAtom(*atom);
for (const SharedLibraryAtom *atom : src->sharedLibrary())
dst->addAtom(*atom);
for (const AbsoluteAtom *atom : src->absolute())
dst->addAtom(*atom);
}
class SimpleFile : public MutableFile {
public:
SimpleFile(StringRef path) : MutableFile(path) {}
@ -77,20 +89,6 @@ protected:
atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
};
class SimpleFileWrapper : public SimpleFile {
public:
SimpleFileWrapper(const File &file) : SimpleFile(file.path()) {
for (const DefinedAtom *atom : file.defined())
_definedAtoms._atoms.push_back(atom);
for (const UndefinedAtom *atom : file.undefined())
_undefinedAtoms._atoms.push_back(atom);
for (const SharedLibraryAtom *atom : file.sharedLibrary())
_sharedLibraryAtoms._atoms.push_back(atom);
for (const AbsoluteAtom *atom : file.absolute())
_absoluteAtoms._atoms.push_back(atom);
}
};
class SimpleReference : public Reference {
public:
SimpleReference(Reference::KindNamespace ns, Reference::KindArch arch,

View File

@ -49,7 +49,7 @@ void RoundTripNativePass::perform(std::unique_ptr<MutableFile> &mergedFile) {
File *objFile = _nativeFile[0].get();
if (objFile->parse())
llvm_unreachable("native reader parse error");
mergedFile.reset(new SimpleFileWrapper(*objFile));
mergedFile.reset(new SimpleFile(objFile->path()));
copyAtoms(mergedFile.get(), objFile);
llvm::sys::fs::remove(tmpNativeFile.str());
}

View File

@ -49,6 +49,7 @@ void RoundTripYAMLPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
File *objFile = _yamlFile[0].get();
if (objFile->parse())
llvm_unreachable("native reader parse error");
mergedFile.reset(new SimpleFileWrapper(*objFile));
mergedFile.reset(new SimpleFile(objFile->path()));
copyAtoms(mergedFile.get(), objFile);
llvm::sys::fs::remove(tmpYAMLFile.str());
}