Skip to content

Commit a2d10ed

Browse files
Adding llvm:cl::opt support to kore-rich-header (#1074)
Closes Pi-Squared-Inc/pi2#1483 This simple PR addresses @Baltoli's suggestion to include `cl::opt` in the `kore-rich-header` to improve the user experience for a broader audience. I also added `-o/--output` support to improve the tool's usability and compatibility with other tools and scripts.
1 parent d55d9dd commit a2d10ed

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

tools/kore-rich-header/main.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,44 @@
22
#include <kllvm/binary/serializer.h>
33
#include <kllvm/parser/KOREParser.h>
44

5+
#include <llvm/Support/CommandLine.h>
6+
57
#include <cstdint>
8+
#include <fstream>
69
#include <iostream>
710

11+
using namespace llvm;
812
using namespace kllvm;
913
using namespace kllvm::parser;
1014

15+
cl::OptionCategory rich_header_cat("kore-rich-header options");
16+
17+
cl::opt<std::string> input(
18+
cl::Positional, cl::desc("<kore-definition>"), cl::Required,
19+
cl::cat(rich_header_cat));
20+
21+
cl::opt<std::string> output(
22+
"o", cl::desc("Output file path"), cl::value_desc("filepath"),
23+
cl::cat(rich_header_cat));
24+
25+
cl::alias output_alias(
26+
"output", cl::desc("Alias for -o"), cl::value_desc("filepath"),
27+
cl::cat(rich_header_cat), cl::aliasopt(output));
28+
1129
int main(int argc, char **argv) {
12-
char *filename = argv[1];
13-
kore_parser parser(filename);
14-
ptr<kore_definition> definition = parser.definition();
30+
cl::HideUnrelatedOptions({&rich_header_cat});
31+
cl::ParseCommandLineOptions(argc, argv);
32+
33+
kore_parser parser(input);
34+
auto definition = parser.definition();
1535
definition->preprocess();
16-
emit_kore_rich_header(std::cout, definition.get());
36+
37+
if (output.empty()) {
38+
emit_kore_rich_header(std::cout, definition.get());
39+
} else {
40+
std::ofstream out(output);
41+
emit_kore_rich_header(out, definition.get());
42+
}
43+
1744
return 0;
1845
}

0 commit comments

Comments
 (0)