| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file implements \c OutputConfig class methods. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/Support/VirtualOutputConfig.h" |
| 15 | #include "llvm/Support/Debug.h" |
| 16 | #include "llvm/Support/FileSystem.h" |
| 17 | #include "llvm/Support/raw_ostream.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | using namespace llvm::vfs; |
| 21 | |
| 22 | OutputConfig &OutputConfig::setOpenFlags(const sys::fs::OpenFlags &Flags) { |
| 23 | // Ignore CRLF on its own as invalid. |
| 24 | using namespace llvm::sys::fs; |
| 25 | return Flags & OF_Text |
| 26 | ? setText().setCRLF(Flags & OF_CRLF).setAppend(Flags & OF_Append) |
| 27 | : setBinary().setAppend(Flags & OF_Append); |
| 28 | } |
| 29 | |
| 30 | void OutputConfig::print(raw_ostream &OS) const { |
| 31 | OS << "{"; |
| 32 | bool IsFirst = true; |
| 33 | auto printFlag = [&](StringRef FlagName, bool Value) { |
| 34 | if (IsFirst) |
| 35 | IsFirst = false; |
| 36 | else |
| 37 | OS << ","; |
| 38 | if (!Value) |
| 39 | OS << "No"; |
| 40 | OS << FlagName; |
| 41 | }; |
| 42 | |
| 43 | #define HANDLE_OUTPUT_CONFIG_FLAG(NAME, DEFAULT) \ |
| 44 | if (get##NAME() != DEFAULT) \ |
| 45 | printFlag(#NAME, get##NAME()); |
| 46 | #include "llvm/Support/VirtualOutputConfig.def" |
| 47 | OS << "}"; |
| 48 | } |
| 49 | |
| 50 | LLVM_DUMP_METHOD void OutputConfig::dump() const { print(OS&: dbgs()); } |
| 51 | |
| 52 | raw_ostream &llvm::operator<<(raw_ostream &OS, OutputConfig Config) { |
| 53 | Config.print(OS); |
| 54 | return OS; |
| 55 | } |
| 56 |