summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
diff options
context:
space:
mode:
authorJoey Gouly <joey.gouly@gmail.com>2014-01-03 23:12:02 +0000
committerJoey Gouly <joey.gouly@gmail.com>2014-01-03 23:12:02 +0000
commitceb16dedefc7833b3f3b7305e751ad9ba748d99b (patch)
tree7158a67f016d6a8bece0f3cf0b35fd8d62f6ce46 /lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
parent0724bf67672c754aa61ce2659939450ff22c30fa (diff)
downloadbcm5719-llvm-ceb16dedefc7833b3f3b7305e751ad9ba748d99b.tar.gz
bcm5719-llvm-ceb16dedefc7833b3f3b7305e751ad9ba748d99b.zip
[MachO] Begin to add some MachO specific File/Atoms, and add the start of
normalizedToAtoms. llvm-svn: 198459
Diffstat (limited to 'lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp')
-rw-r--r--lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
new file mode 100644
index 00000000000..2032e0cea05
--- /dev/null
+++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
@@ -0,0 +1,66 @@
+//===- lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp --------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+///
+/// \file Converts from in-memory normalized mach-o to in-memory Atoms.
+///
+/// +------------+
+/// | normalized |
+/// +------------+
+/// |
+/// |
+/// v
+/// +-------+
+/// | Atoms |
+/// +-------+
+
+#include "MachONormalizedFile.h"
+#include "File.h"
+#include "Atoms.h"
+
+#include "lld/Core/LLVM.h"
+
+#include "llvm/Support/MachO.h"
+
+using namespace llvm::MachO;
+
+namespace lld {
+namespace mach_o {
+namespace normalized {
+
+static ErrorOr<std::unique_ptr<lld::File>>
+normalizedObjectToAtoms(const NormalizedFile &normalizedFile, StringRef path) {
+ std::unique_ptr<MachOFile> file(new MachOFile(path));
+
+ for (auto &sym : normalizedFile.globalSymbols) {
+ file->addDefinedAtom(sym.name,
+ normalizedFile.sections[sym.sect - 1].content);
+ }
+
+ assert(normalizedFile.localSymbols.empty() &&
+ "local symbols not supported yet!");
+ assert(normalizedFile.undefinedSymbols.empty() &&
+ "undefined symbols not supported yet!");
+
+ return std::unique_ptr<File>(std::move(file));
+}
+
+ErrorOr<std::unique_ptr<lld::File>>
+normalizedToAtoms(const NormalizedFile &normalizedFile, StringRef path) {
+ switch (normalizedFile.fileType) {
+ case MH_OBJECT:
+ return normalizedObjectToAtoms(normalizedFile, path);
+ default:
+ llvm_unreachable("unhandled MachO file type!");
+ }
+}
+
+} // namespace normalized
+} // namespace mach_o
+} // namespace lld
OpenPOWER on IntegriCloud