summaryrefslogtreecommitdiffstats
path: root/lld/lib/Passes/RoundTripYAMLPass.cpp
diff options
context:
space:
mode:
authorShankar Easwaran <shankare@codeaurora.org>2013-10-29 05:12:14 +0000
committerShankar Easwaran <shankare@codeaurora.org>2013-10-29 05:12:14 +0000
commit2bc24928d36531aeea52c6563a125adb22c203bf (patch)
treeb7fd4a401d972e6c946bc2ba3309ca99924b2070 /lld/lib/Passes/RoundTripYAMLPass.cpp
parent3aca58f135b593a66c4c5680a4ce3b97d6531bdf (diff)
downloadbcm5719-llvm-2bc24928d36531aeea52c6563a125adb22c203bf.tar.gz
bcm5719-llvm-2bc24928d36531aeea52c6563a125adb22c203bf.zip
[PassManager] add ReaderWriter{Native,YAML} to the Driver.
Enable this for the following flavors a) core b) gnu c) darwin Its disabled for the flavor PECOFF. Convenient markers are added with FIXME comments in the Driver that would be removed and code removed from each flavor. llvm-svn: 193585
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