Marek Sokolowski | 2ce2fa4 | 2017-07-25 00:25:18 +0000 | [diff] [blame^] | 1 | //===- llvm-rc.cpp - Compile .rc scripts into .res -------------*- C++ -*--===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Compile .rc scripts into .res files. This is intended to be a |
| 11 | // platform-independent port of Microsoft's rc.exe tool. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Option/Arg.h" |
| 16 | #include "llvm/Option/ArgList.h" |
| 17 | #include "llvm/Support/Error.h" |
| 18 | #include "llvm/Support/ManagedStatic.h" |
| 19 | #include "llvm/Support/PrettyStackTrace.h" |
| 20 | #include "llvm/Support/Process.h" |
| 21 | #include "llvm/Support/Signals.h" |
| 22 | #include "llvm/Support/raw_ostream.h" |
| 23 | |
| 24 | #include <system_error> |
| 25 | |
| 26 | using namespace llvm; |
| 27 | |
| 28 | namespace { |
| 29 | |
| 30 | // Input options tables. |
| 31 | |
| 32 | enum ID { |
| 33 | OPT_INVALID = 0, // This is not a correct option ID. |
| 34 | #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ |
| 35 | HELPTEXT, METAVAR, VALUES) \ |
| 36 | OPT_##ID, |
| 37 | #include "Opts.inc" |
| 38 | #undef OPTION |
| 39 | }; |
| 40 | |
| 41 | #define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; |
| 42 | #include "Opts.inc" |
| 43 | #undef PREFIX |
| 44 | |
| 45 | static const opt::OptTable::Info InfoTable[] = { |
| 46 | #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ |
| 47 | HELPTEXT, METAVAR, VALUES) \ |
| 48 | { \ |
| 49 | PREFIX, NAME, HELPTEXT, \ |
| 50 | METAVAR, OPT_##ID, opt::Option::KIND##Class, \ |
| 51 | PARAM, FLAGS, OPT_##GROUP, \ |
| 52 | OPT_##ALIAS, ALIASARGS, VALUES}, |
| 53 | #include "Opts.inc" |
| 54 | #undef OPTION |
| 55 | }; |
| 56 | |
| 57 | class RcOptTable : public opt::OptTable { |
| 58 | public: |
| 59 | RcOptTable() : OptTable(InfoTable, /* IgnoreCase = */ true) {} |
| 60 | }; |
| 61 | |
| 62 | static ExitOnError ExitOnErr; |
| 63 | } // anonymous namespace |
| 64 | |
| 65 | int main(int argc_, const char *argv_[]) { |
| 66 | sys::PrintStackTraceOnErrorSignal(argv_[0]); |
| 67 | PrettyStackTraceProgram X(argc_, argv_); |
| 68 | |
| 69 | ExitOnErr.setBanner("llvm-rc: "); |
| 70 | |
| 71 | SmallVector<const char *, 256> argv; |
| 72 | SpecificBumpPtrAllocator<char> ArgAllocator; |
| 73 | ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector( |
| 74 | argv, makeArrayRef(argv_, argc_), ArgAllocator))); |
| 75 | |
| 76 | llvm_shutdown_obj Y; |
| 77 | |
| 78 | RcOptTable T; |
| 79 | unsigned MAI, MAC; |
| 80 | ArrayRef<const char *> ArgsArr = makeArrayRef(argv_ + 1, argc_); |
| 81 | opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC); |
| 82 | |
| 83 | // The tool prints nothing when invoked with no command-line arguments. |
| 84 | if (InputArgs.hasArg(OPT_HELP)) |
| 85 | T.PrintHelp(outs(), "rc", "Resource Converter", false); |
| 86 | |
| 87 | return 0; |
| 88 | } |