summaryrefslogtreecommitdiffstats
path: root/lld/lib/Core/YamlWriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/Core/YamlWriter.cpp')
-rw-r--r--lld/lib/Core/YamlWriter.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/lld/lib/Core/YamlWriter.cpp b/lld/lib/Core/YamlWriter.cpp
new file mode 100644
index 00000000000..ae27c7e3129
--- /dev/null
+++ b/lld/lib/Core/YamlWriter.cpp
@@ -0,0 +1,100 @@
+//===- Core/YamlWriter.cpp - Writes YAML ----------------------------------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lld/Core/YamlWriter.h"
+#include "lld/Core/Atom.h"
+#include "lld/Core/File.h"
+#include "lld/Core/Reference.h"
+
+#include "llvm/ADT/OwningPtr.h"
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/system_error.h"
+
+#include <vector>
+
+namespace lld {
+namespace yaml {
+
+class Handler : public File::AtomHandler {
+public:
+ Handler(llvm::raw_ostream &out) : _out(out) { }
+
+ virtual void doFile(const class File &) { }
+ virtual void doAtom(const class Atom &atom) {
+ _out << " - name: " << atom.name() << "\n";
+ _out << " definition: " << definitionString(atom.definition()) <<"\n";
+ _out << " user-visible:" << atom.userVisibleName() << "\n";
+ _out << " scope: " << scopeString(atom.scope()) << "\n";
+ _out << " type: " << typeString(atom.contentType()) << "\n";
+ if (atom.referencesBegin() != atom.referencesEnd()) {
+ _out << " fixups:\n";
+ for (Reference::iterator it = atom.referencesBegin(),
+ end = atom.referencesEnd(); it != end; ++it) {
+ _out << " - kind: " << it->kind << "\n";
+ _out << " offset: " << it->offsetInAtom << "\n";
+ }
+ }
+
+ }
+
+private:
+ const char *scopeString(Atom::Scope scope) {
+ switch (scope) {
+ case Atom::scopeTranslationUnit:
+ return "static";
+ case Atom::scopeLinkageUnit:
+ return "hidden";
+ case Atom::scopeGlobal:
+ return "global";
+ }
+ return "???";
+ }
+
+ const char *typeString(Atom::ContentType type) {
+ switch (type) {
+ case Atom::typeCode:
+ return "code";
+ case Atom::typeCString:
+ return "c-string";
+ case Atom::typeZeroFill:
+ return "zero-fill";
+ case Atom::typeData:
+ return "data";
+ default:
+ return "???";
+ }
+ }
+
+ const char *definitionString(Atom::Definition def) {
+ switch (def) {
+ case Atom::definitionRegular:
+ return "regular";
+ case Atom::definitionTentative:
+ return "tentative";
+ case Atom::definitionAbsolute:
+ return "absolute";
+ default:
+ return "???";
+ }
+ }
+
+ llvm::raw_ostream &_out;
+};
+
+void writeObjectText(File *file, llvm::raw_ostream &out) {
+ Handler h(out);
+ out << "---\n";
+ out << "atoms:\n";
+ file->forEachAtom(h);
+ out << "...\n";
+}
+
+} // namespace yaml
+} // namespace lld
OpenPOWER on IntegriCloud