File tree Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Expand file tree Collapse file tree 4 files changed +34
-7
lines changed Original file line number Diff line number Diff line change @@ -18,9 +18,19 @@ RUN: llvm-remarkutil filter --remark-type=analysis %p/Inputs/filter.yaml | FileC
1818
1919RUN: llvm-remarkutil yaml2bitstream -o %t.opt.bitstream %p/Inputs/filter.yaml
2020RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream | FileCheck %s --strict-whitespace --check-prefix=REMARK1
21+ RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1.yamL
22+ RUN: cat %t.r1.yamL | FileCheck %s --strict-whitespace --check-prefix=REMARK1
23+ RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1.yMl
24+ RUN: cat %t.r1.yMl | FileCheck %s --strict-whitespace --check-prefix=REMARK1
25+ RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream --serializer=yaml -o %t.r1.fake.opt.bitstream
26+ RUN: cat %t.r1.fake.opt.bitstream | FileCheck %s --strict-whitespace --check-prefix=REMARK1
2127
2228RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1.opt.bitstream
2329RUN: llvm-remarkutil bitstream2yaml %t.r1.opt.bitstream | FileCheck %s --strict-whitespace --check-prefix=REMARK1
30+ RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1
31+ RUN: llvm-remarkutil bitstream2yaml %t.r1 | FileCheck %s --strict-whitespace --check-prefix=REMARK1
32+ RUN: llvm-remarkutil filter --function=func1 %p/Inputs/filter.yaml --serializer=bitstream -o %t.r1.fake.yaml
33+ RUN: llvm-remarkutil bitstream2yaml %t.r1.fake.yaml | FileCheck %s --strict-whitespace --check-prefix=REMARK1
2434
2535RUN: llvm-remarkutil filter --function=func %p/Inputs/filter.yaml | FileCheck %s --allow-empty --strict-whitespace --check-prefix=EMPTY
2636
Original file line number Diff line number Diff line change @@ -48,12 +48,8 @@ static Error tryFilter() {
4848 return MaybeParser.takeError ();
4949 auto &Parser = **MaybeParser;
5050
51- Format SerializerFormat = OutputFormat;
52- if (SerializerFormat == Format::Auto) {
53- SerializerFormat = Parser.ParserFormat ;
54- if (OutputFileName.empty () || OutputFileName == " -" )
55- SerializerFormat = Format::YAML;
56- }
51+ Format SerializerFormat =
52+ getSerializerFormat (OutputFileName, OutputFormat, Parser.ParserFormat );
5753
5854 auto MaybeOF = getOutputFileForRemarks (OutputFileName, SerializerFormat);
5955 if (!MaybeOF)
Original file line number Diff line number Diff line change @@ -54,6 +54,20 @@ getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat) {
5454 : sys::fs::OF_None);
5555}
5656
57+ Format getSerializerFormat (StringRef OutputFileName, Format SelectedFormat,
58+ Format DefaultFormat) {
59+ if (SelectedFormat != Format::Auto)
60+ return SelectedFormat;
61+ SelectedFormat = DefaultFormat;
62+ if (OutputFileName.empty () || OutputFileName == " -" ||
63+ OutputFileName.ends_with_insensitive (" .yaml" ) ||
64+ OutputFileName.ends_with_insensitive (" .yml" ))
65+ SelectedFormat = Format::YAML;
66+ if (OutputFileName.ends_with_insensitive (" .bitstream" ))
67+ SelectedFormat = Format::Bitstream;
68+ return SelectedFormat;
69+ }
70+
5771Expected<FilterMatcher>
5872FilterMatcher::createRE (const llvm::cl::opt<std::string> &Arg) {
5973 return createRE (Arg.ArgStr , Arg);
Original file line number Diff line number Diff line change 4747 " serializer" , cl::init(Format::Auto), \
4848 cl::desc(" Output remark format to serialize" ), \
4949 cl::values(clEnumValN(Format::Auto, " auto" , \
50- " Follow the parser format (default)" ), \
50+ " Automatic detection based on output file " \
51+ " extension or parser format (default)" ), \
5152 clEnumValN(Format::YAML, " yaml" , " YAML" ), \
5253 clEnumValN(Format::Bitstream, " bitstream" , " Bitstream" )), \
5354 cl::sub(SUBOPT));
@@ -151,6 +152,12 @@ getOutputFileWithFlags(StringRef OutputFileName, sys::fs::OpenFlags Flags);
151152Expected<std::unique_ptr<ToolOutputFile>>
152153getOutputFileForRemarks (StringRef OutputFileName, Format OutputFormat);
153154
155+ // / Choose the serializer format. If \p SelectedFormat is Format::Auto, try to
156+ // / detect the format based on the extension of \p OutputFileName or fall back
157+ // / to \p DefaultFormat.
158+ Format getSerializerFormat (StringRef OutputFileName, Format SelectedFormat,
159+ Format DefaultFormat);
160+
154161// / Filter object which can be either a string or a regex to match with the
155162// / remark properties.
156163class FilterMatcher {
You can’t perform that action at this time.
0 commit comments