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
18
18
19
19
RUN: llvm-remarkutil yaml2bitstream -o %t.opt.bitstream %p/Inputs/filter.yaml
20
20
RUN: 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
21
27
22
28
RUN: llvm-remarkutil filter --function=func1 %t.opt.bitstream -o %t.r1.opt.bitstream
23
29
RUN: 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
24
34
25
35
RUN: llvm-remarkutil filter --function=func %p/Inputs/filter.yaml | FileCheck %s --allow-empty --strict-whitespace --check-prefix=EMPTY
26
36
Original file line number Diff line number Diff line change @@ -46,12 +46,8 @@ static Error tryFilter() {
46
46
return MaybeParser.takeError ();
47
47
auto &Parser = **MaybeParser;
48
48
49
- Format SerializerFormat = OutputFormat;
50
- if (SerializerFormat == Format::Auto) {
51
- SerializerFormat = Parser.ParserFormat ;
52
- if (OutputFileName.empty () || OutputFileName == " -" )
53
- SerializerFormat = Format::YAML;
54
- }
49
+ Format SerializerFormat =
50
+ getSerializerFormat (OutputFileName, OutputFormat, Parser.ParserFormat );
55
51
56
52
auto MaybeOF = getOutputFileForRemarks (OutputFileName, SerializerFormat);
57
53
if (!MaybeOF)
Original file line number Diff line number Diff line change @@ -54,6 +54,20 @@ getOutputFileForRemarks(StringRef OutputFileName, Format OutputFormat) {
54
54
: sys::fs::OF_None);
55
55
}
56
56
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
+
57
71
Expected<FilterMatcher>
58
72
FilterMatcher::createRE (const llvm::cl::opt<std::string> &Arg) {
59
73
return createRE (Arg.ArgStr , Arg);
Original file line number Diff line number Diff line change 47
47
" serializer" , cl::init(Format::Auto), \
48
48
cl::desc(" Output remark format to serialize" ), \
49
49
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)" ), \
51
52
clEnumValN(Format::YAML, " yaml" , " YAML" ), \
52
53
clEnumValN(Format::Bitstream, " bitstream" , " Bitstream" )), \
53
54
cl::sub(SUBOPT));
@@ -151,6 +152,12 @@ getOutputFileWithFlags(StringRef OutputFileName, sys::fs::OpenFlags Flags);
151
152
Expected<std::unique_ptr<ToolOutputFile>>
152
153
getOutputFileForRemarks (StringRef OutputFileName, Format OutputFormat);
153
154
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
+
154
161
// / Filter object which can be either a string or a regex to match with the
155
162
// / remark properties.
156
163
class FilterMatcher {
You can’t perform that action at this time.
0 commit comments