[lld] r227549 - Replace SimpleFileWrapper with a function.
Rui Ueyama
ruiu at google.com
Thu Jan 29 18:11:59 PST 2015
Author: ruiu
Date: Thu Jan 29 20:11:59 2015
New Revision: 227549
URL: http://llvm.org/viewvc/llvm-project?rev=227549&view=rev
Log:
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.
Modified:
lld/trunk/include/lld/Core/Simple.h
lld/trunk/lib/Passes/RoundTripNativePass.cpp
lld/trunk/lib/Passes/RoundTripYAMLPass.cpp
Modified: lld/trunk/include/lld/Core/Simple.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Simple.h?rev=227549&r1=227548&r2=227549&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Simple.h (original)
+++ lld/trunk/include/lld/Core/Simple.h Thu Jan 29 20:11:59 2015
@@ -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,
Modified: lld/trunk/lib/Passes/RoundTripNativePass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/RoundTripNativePass.cpp?rev=227549&r1=227548&r2=227549&view=diff
==============================================================================
--- lld/trunk/lib/Passes/RoundTripNativePass.cpp (original)
+++ lld/trunk/lib/Passes/RoundTripNativePass.cpp Thu Jan 29 20:11:59 2015
@@ -49,7 +49,7 @@ void RoundTripNativePass::perform(std::u
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());
}
Modified: lld/trunk/lib/Passes/RoundTripYAMLPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Passes/RoundTripYAMLPass.cpp?rev=227549&r1=227548&r2=227549&view=diff
==============================================================================
--- lld/trunk/lib/Passes/RoundTripYAMLPass.cpp (original)
+++ lld/trunk/lib/Passes/RoundTripYAMLPass.cpp Thu Jan 29 20:11:59 2015
@@ -49,6 +49,7 @@ void RoundTripYAMLPass::perform(std::uni
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());
}
More information about the llvm-commits
mailing list