summaryrefslogtreecommitdiffstats
path: root/lld/lib/Passes/RoundTripYAMLPass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/Passes/RoundTripYAMLPass.cpp')
-rw-r--r--lld/lib/Passes/RoundTripYAMLPass.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/lld/lib/Passes/RoundTripYAMLPass.cpp b/lld/lib/Passes/RoundTripYAMLPass.cpp
new file mode 100644
index 00000000000..38012cd1308
--- /dev/null
+++ b/lld/lib/Passes/RoundTripYAMLPass.cpp
@@ -0,0 +1,43 @@
+//===--Passes/RoundTripYAMLPass.cpp - Write YAML file/Read it back---------===//
+//
+// The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "RoundTripYAMLPass"
+
+#include "lld/Core/Instrumentation.h"
+#include "lld/Passes/RoundTripYAMLPass.h"
+#include "lld/ReaderWriter/Simple.h"
+#include "lld/ReaderWriter/Writer.h"
+
+#include "llvm/Support/Path.h"
+
+using namespace lld;
+
+/// Perform the actual pass
+void RoundTripYAMLPass::perform(std::unique_ptr<MutableFile> &mergedFile) {
+ ScopedTask task(getDefaultDomain(), "RoundTripYAMLPass");
+ std::unique_ptr<Writer> yamlWriter = createWriterYAML(_context);
+ SmallString<128> tmpYAMLFile;
+ // Separate the directory from the filename
+ StringRef outFile = llvm::sys::path::filename(_context.outputPath());
+ if (llvm::sys::fs::createTemporaryFile(outFile, "yaml", tmpYAMLFile))
+ return;
+
+ // The file that is written would be kept around if there is a problem
+ // writing to the file or when reading atoms back from the file.
+ yamlWriter->writeFile(*mergedFile, tmpYAMLFile.str());
+ llvm::OwningPtr<llvm::MemoryBuffer> buff;
+ if (llvm::MemoryBuffer::getFileOrSTDIN(tmpYAMLFile.str(), buff))
+ return;
+
+ std::unique_ptr<MemoryBuffer> mb(buff.take());
+ _context.getYAMLReader().parseFile(mb, _yamlFile);
+
+ mergedFile.reset(new FileToMutable(_context, *_yamlFile[0].get()));
+
+ llvm::sys::fs::remove(tmpYAMLFile.str());
+}
OpenPOWER on IntegriCloud