aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-remarkutil
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-remarkutil')
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkFilter.cpp8
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp14
-rw-r--r--llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h9
3 files changed, 24 insertions, 7 deletions
diff --git a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
index 507ae36..9b521b4 100644
--- a/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkFilter.cpp
@@ -48,12 +48,8 @@ static Error tryFilter() {
return MaybeParser.takeError();
auto &Parser = **MaybeParser;
- Format SerializerFormat = OutputFormat;
- if (SerializerFormat == Format::Auto) {
- SerializerFormat = Parser.ParserFormat;
- if (OutputFileName.empty() || OutputFileName == "-")
- SerializerFormat = Format::YAML;
- }
+ Format SerializerFormat =
+ getSerializerFormat(OutputFileName, OutputFormat, Parser.ParserFormat);
auto MaybeOF = getOutputFileForRemarks(OutputFileName, SerializerFormat);
if (!MaybeOF)
diff --git a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
index be52948..b6204d0 100644
--- a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
+++ b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.cpp
@@ -54,6 +54,20 @@ getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat) {
: sys::fs::OF_None);
}
+Format getSerializerFormat(StringRef OutputFileName, Format SelectedFormat,
+ Format DefaultFormat) {
+ if (SelectedFormat != Format::Auto)
+ return SelectedFormat;
+ SelectedFormat = DefaultFormat;
+ if (OutputFileName.empty() || OutputFileName == "-" ||
+ OutputFileName.ends_with_insensitive(".yaml") ||
+ OutputFileName.ends_with_insensitive(".yml"))
+ SelectedFormat = Format::YAML;
+ if (OutputFileName.ends_with_insensitive(".bitstream"))
+ SelectedFormat = Format::Bitstream;
+ return SelectedFormat;
+}
+
Expected<FilterMatcher>
FilterMatcher::createRE(const llvm::cl::opt<std::string> &Arg) {
return createRE(Arg.ArgStr, Arg);
diff --git a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
index 0dd550765..73867fe 100644
--- a/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
+++ b/llvm/tools/llvm-remarkutil/RemarkUtilHelpers.h
@@ -47,7 +47,8 @@
"serializer", cl::init(Format::Auto), \
cl::desc("Output remark format to serialize"), \
cl::values(clEnumValN(Format::Auto, "auto", \
- "Follow the parser format (default)"), \
+ "Automatic detection based on output file " \
+ "extension or parser format (default)"), \
clEnumValN(Format::YAML, "yaml", "YAML"), \
clEnumValN(Format::Bitstream, "bitstream", "Bitstream")), \
cl::sub(SUBOPT));
@@ -151,6 +152,12 @@ getOutputFileWithFlags(StringRef OutputFileName, sys::fs::OpenFlags Flags);
Expected<std::unique_ptr<ToolOutputFile>>
getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat);
+/// Choose the serializer format. If \p SelectedFormat is Format::Auto, try to
+/// detect the format based on the extension of \p OutputFileName or fall back
+/// to \p DefaultFormat.
+Format getSerializerFormat(StringRef OutputFileName, Format SelectedFormat,
+ Format DefaultFormat);
+
/// Filter object which can be either a string or a regex to match with the
/// remark properties.
class FilterMatcher {