summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp')
-rw-r--r--llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp33
1 files changed, 15 insertions, 18 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
index b1083f4ed0a..a043ea40c27 100644
--- a/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
+++ b/llvm/tools/llvm-exegesis/lib/BenchmarkResult.cpp
@@ -61,8 +61,10 @@ LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(exegesis::InstructionBenchmark)
namespace exegesis {
+namespace {
+
template <typename ObjectOrList>
-static ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) {
+ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) {
std::unique_ptr<llvm::MemoryBuffer> MemBuffer = llvm::cantFail(
llvm::errorOrToExpected(llvm::MemoryBuffer::getFile(Filename)));
llvm::yaml::Input Yin(*MemBuffer);
@@ -71,6 +73,8 @@ static ObjectOrList readYamlOrDieCommon(llvm::StringRef Filename) {
return Benchmark;
}
+} // namespace
+
InstructionBenchmark
InstructionBenchmark::readYamlOrDie(llvm::StringRef Filename) {
return readYamlOrDieCommon<InstructionBenchmark>(Filename);
@@ -81,26 +85,19 @@ InstructionBenchmark::readYamlsOrDie(llvm::StringRef Filename) {
return readYamlOrDieCommon<std::vector<InstructionBenchmark>>(Filename);
}
-void InstructionBenchmark::writeYamlTo(llvm::raw_ostream &S) {
- llvm::yaml::Output Yout(S);
- Yout << *this;
-}
-
-void InstructionBenchmark::readYamlFrom(llvm::StringRef InputContent) {
- llvm::yaml::Input Yin(InputContent);
- Yin >> *this;
-}
-
-// FIXME: Change the API to let the caller handle errors.
void InstructionBenchmark::writeYamlOrDie(const llvm::StringRef Filename) {
if (Filename == "-") {
- writeYamlTo(llvm::outs());
+ llvm::yaml::Output Yout(llvm::outs());
+ Yout << *this;
} else {
- int ResultFD = 0;
- llvm::cantFail(llvm::errorCodeToError(
- openFileForWrite(Filename, ResultFD, llvm::sys::fs::F_Text)));
- llvm::raw_fd_ostream Ostr(ResultFD, true /*shouldClose*/);
- writeYamlTo(Ostr);
+ llvm::SmallString<1024> Buffer;
+ llvm::raw_svector_ostream Ostr(Buffer);
+ llvm::yaml::Output Yout(Ostr);
+ Yout << *this;
+ std::unique_ptr<llvm::FileOutputBuffer> File =
+ llvm::cantFail(llvm::FileOutputBuffer::create(Filename, Buffer.size()));
+ memcpy(File->getBufferStart(), Buffer.data(), Buffer.size());
+ llvm::cantFail(File->commit());
}
}
OpenPOWER on IntegriCloud