blob: 79466b5cdb5cc65478f043b167c36c6a8640d50b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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());
OwningPtr<MemoryBuffer> buff;
if (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());
}
|