diff options
| author | Mingming Liu <mingmingl@google.com> | 2025-09-10 15:25:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 15:25:31 -0700 |
| commit | 1417dafa1db9cb1b2b09438aa9f53ea5ab6e36e2 (patch) | |
| tree | 57f4b1f313c8cf74eed8819870f39c36ea263c68 /llvm/lib/Support/VirtualOutputConfig.cpp | |
| parent | 898b813bc8a6d0276bf0f4769f5f2f64b34e632d (diff) | |
| parent | b8cefcb601ddaa18482555c4ff363c01a270c2fe (diff) | |
Merge branch 'main' into users/mingmingl-llvm/samplefdo-profile-formatusers/mingmingl-llvm/samplefdo-profile-format
Diffstat (limited to 'llvm/lib/Support/VirtualOutputConfig.cpp')
| -rw-r--r-- | llvm/lib/Support/VirtualOutputConfig.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/lib/Support/VirtualOutputConfig.cpp b/llvm/lib/Support/VirtualOutputConfig.cpp new file mode 100644 index 000000000000..4672a0dad65d --- /dev/null +++ b/llvm/lib/Support/VirtualOutputConfig.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file implements \c OutputConfig class methods. +/// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/VirtualOutputConfig.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; +using namespace llvm::vfs; + +OutputConfig &OutputConfig::setOpenFlags(const sys::fs::OpenFlags &Flags) { + // Ignore CRLF on its own as invalid. + using namespace llvm::sys::fs; + return Flags & OF_Text + ? setText().setCRLF(Flags & OF_CRLF).setAppend(Flags & OF_Append) + : setBinary().setAppend(Flags & OF_Append); +} + +void OutputConfig::print(raw_ostream &OS) const { + OS << "{"; + bool IsFirst = true; + auto printFlag = [&](StringRef FlagName, bool Value) { + if (IsFirst) + IsFirst = false; + else + OS << ","; + if (!Value) + OS << "No"; + OS << FlagName; + }; + +#define HANDLE_OUTPUT_CONFIG_FLAG(NAME, DEFAULT) \ + if (get##NAME() != DEFAULT) \ + printFlag(#NAME, get##NAME()); +#include "llvm/Support/VirtualOutputConfig.def" + OS << "}"; +} + +LLVM_DUMP_METHOD void OutputConfig::dump() const { print(dbgs()); } + +raw_ostream &llvm::operator<<(raw_ostream &OS, OutputConfig Config) { + Config.print(OS); + return OS; +} |
