aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h')
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
index 73867fe..39e7b42 100644
--- a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
+++ b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
@@ -9,6 +9,7 @@
// Helpers for remark utilites
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Remarks/Remark.h"
#include "llvm/Remarks/RemarkFormat.h"
@@ -19,6 +20,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Regex.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/ToolOutputFile.h"
// Keep input + output help + names consistent across the various modes via a
@@ -205,5 +207,54 @@ struct Filters {
bool filterRemark(const Remark &Remark);
};
+/// Helper to construct Remarks using an API similar to DiagnosticInfo.
+/// Once this is more fully featured, consider implementing DiagnosticInfo using
+/// RemarkBuilder.
+class RemarkBuilder {
+ BumpPtrAllocator Alloc;
+ UniqueStringSaver Strs;
+
+public:
+ Remark R;
+ struct Argument {
+ std::string Key;
+ std::string Val;
+ std::optional<RemarkLocation> Loc;
+ Argument(StringRef Key, StringRef Val,
+ std::optional<RemarkLocation> Loc = std::nullopt)
+ : Key(Key), Val(Val), Loc(Loc) {}
+ Argument(StringRef Key, int Val,
+ std::optional<RemarkLocation> Loc = std::nullopt)
+ : Key(Key), Val(itostr(Val)), Loc(Loc) {}
+ };
+
+ RemarkBuilder(Type RemarkType, StringRef PassName, StringRef RemarkName,
+ StringRef FunctionName)
+ : Strs(Alloc) {
+ R.RemarkType = RemarkType;
+ R.PassName = Strs.save(PassName);
+ R.RemarkName = Strs.save(RemarkName);
+ R.FunctionName = Strs.save(FunctionName);
+ }
+
+ RemarkBuilder &operator<<(Argument &&Arg) {
+ auto &RArg = R.Args.emplace_back(Strs.save(Arg.Key), Strs.save(Arg.Val));
+ RArg.Loc = Arg.Loc;
+ return *this;
+ }
+
+ RemarkBuilder &operator<<(const char *Str) {
+ R.Args.emplace_back("String", Str);
+ return *this;
+ }
+
+ RemarkBuilder &operator<<(StringRef Str) {
+ R.Args.emplace_back("String", Strs.save(Str));
+ return *this;
+ }
+};
+
+using NV = RemarkBuilder::Argument;
+
} // namespace remarks
} // namespace llvm