|
2 | 2 | #include <kllvm/binary/serializer.h>
|
3 | 3 | #include <kllvm/parser/KOREParser.h>
|
4 | 4 |
|
| 5 | +#include <llvm/Support/CommandLine.h> |
| 6 | + |
5 | 7 | #include <cstdint>
|
| 8 | +#include <fstream> |
6 | 9 | #include <iostream>
|
7 | 10 |
|
| 11 | +using namespace llvm; |
8 | 12 | using namespace kllvm;
|
9 | 13 | using namespace kllvm::parser;
|
10 | 14 |
|
| 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 | + |
11 | 29 | 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(); |
15 | 35 | 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 | + |
17 | 44 | return 0;
|
18 | 45 | }
|
0 commit comments