aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-01-30 02:11:59 +0000
committerRui Ueyama <ruiu@google.com>2015-01-30 02:11:59 +0000
commit78e2a2df22a40a7ed097ab64e4bf70833d115ed3 (patch)
tree74e824e5897a2451e59a59e4eb3916557f45dd3f
parent38522b8867bacc6cd6714d538ff0caf3c86656da (diff)
downloadllvm-78e2a2df22a40a7ed097ab64e4bf70833d115ed3.zip
llvm-78e2a2df22a40a7ed097ab64e4bf70833d115ed3.tar.gz
llvm-78e2a2df22a40a7ed097ab64e4bf70833d115ed3.tar.bz2
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
-rw-r--r--lld/include/lld/Core/Simple.h26
-rw-r--r--lld/lib/Passes/RoundTripNativePass.cpp4
-rw-r--r--lld/lib/Passes/RoundTripYAMLPass.cpp3
3 files changed, 16 insertions, 17 deletions
diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h
index e13c0f4..b1c560d1 100644
--- a/lld/include/lld/Core/Simple.h
+++ b/lld/include/lld/Core/Simple.h
@@ -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,
diff --git a/lld/lib/Passes/RoundTripNativePass.cpp b/lld/lib/Passes/RoundTripNativePass.cpp
index f769a54..2e7e1a3 100644
--- a/lld/lib/Passes/RoundTripNativePass.cpp
+++ b/lld/lib/Passes/RoundTripNativePass.cpp
@@ -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());
}
diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp
index 6fcfe58..fbd1c1b 100644
--- a/lld/lib/Passes/RoundTripYAMLPass.cpp
+++ b/lld/lib/Passes/RoundTripYAMLPass.cpp
@@ -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());
}