summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DiagnosticInfo.cpp
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-01-25 16:59:06 +0000
committerFlorian Hahn <flo@fhahn.com>2019-01-25 16:59:06 +0000
commitca95ee5e11ad7e5fdd2d41f463a6d790cf1249ed (patch)
treea63b33373d17717224e84c4fa7dd70e822ae62dd /llvm/lib/IR/DiagnosticInfo.cpp
parent4db70d9695e4c863329ee3347b6eeb1d13eb7aa1 (diff)
downloadbcm5719-llvm-ca95ee5e11ad7e5fdd2d41f463a6d790cf1249ed.tar.gz
bcm5719-llvm-ca95ee5e11ad7e5fdd2d41f463a6d790cf1249ed.zip
[DiagnosticInfo] Add support for preserving newlines in remark arguments.
This patch adds a new type StringBlockVal which can be used to emit a YAML block scalar, which preserves newlines in a multiline string. It also updates MappingTraits<DiagnosticInfoOptimizationBase::Argument> to use it for argument values with more than a single newline. This is helpful for remarks that want to display more in-depth information in a more structured way. Reviewers: thegameg, anemet Reviewed By: anemet Subscribers: hfinkel, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D57159 llvm-svn: 352216
Diffstat (limited to 'llvm/lib/IR/DiagnosticInfo.cpp')
-rw-r--r--llvm/lib/IR/DiagnosticInfo.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/llvm/lib/IR/DiagnosticInfo.cpp b/llvm/lib/IR/DiagnosticInfo.cpp
index b7409983b39..14bee35dc29 100644
--- a/llvm/lib/IR/DiagnosticInfo.cpp
+++ b/llvm/lib/IR/DiagnosticInfo.cpp
@@ -438,11 +438,33 @@ template <> struct MappingTraits<DiagnosticLocation> {
static const bool flow = true;
};
+/// Helper struct for multiline string block literals. Use this type to preserve
+/// newlines in strings.
+struct StringBlockVal {
+ StringRef Value;
+ StringBlockVal(const std::string &Value) : Value(Value) {}
+};
+
+template <> struct BlockScalarTraits<StringBlockVal> {
+ static void output(const StringBlockVal &S, void *Ctx, raw_ostream &OS) {
+ return ScalarTraits<StringRef>::output(S.Value, Ctx, OS);
+ }
+
+ static StringRef input(StringRef Scalar, void *Ctx, StringBlockVal &S) {
+ return ScalarTraits<StringRef>::input(Scalar, Ctx, S.Value);
+ }
+};
+
// Implement this as a mapping for now to get proper quotation for the value.
template <> struct MappingTraits<DiagnosticInfoOptimizationBase::Argument> {
static void mapping(IO &io, DiagnosticInfoOptimizationBase::Argument &A) {
assert(io.outputting() && "input not yet implemented");
- io.mapRequired(A.Key.data(), A.Val);
+ // Emit a string block scalar for multiline strings, to preserve newlines.
+ if (StringRef(A.Val).count('\n') > 1) {
+ StringBlockVal S(A.Val);
+ io.mapRequired(A.Key.data(), S);
+ } else
+ io.mapRequired(A.Key.data(), A.Val);
if (A.Loc.isValid())
io.mapOptional("DebugLoc", A.Loc);
}
OpenPOWER on IntegriCloud