Index: llvm/tools/llvm-cvtres/CMakeLists.txt =================================================================== --- /dev/null +++ llvm/tools/llvm-cvtres/CMakeLists.txt @@ -0,0 +1,13 @@ +set(LLVM_LINK_COMPONENTS + Option + Support + ) + +set(LLVM_TARGET_DEFINITIONS Opts.td) + +tablegen(LLVM Opts.inc -gen-opt-parser-defs) +add_public_tablegen_target(CvtResTableGen) + +add_llvm_tool(llvm-cvtres + llvm-cvtres.cpp + ) Index: llvm/tools/llvm-cvtres/LLVMBuild.txt =================================================================== --- /dev/null +++ llvm/tools/llvm-cvtres/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-cvtres/LLVMBuild.txt ------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-cvtres +parent = Tools +required_libraries = Option Support Index: llvm/tools/llvm-cvtres/Opts.td =================================================================== --- /dev/null +++ llvm/tools/llvm-cvtres/Opts.td @@ -0,0 +1,8 @@ +include "llvm/Option/OptParser.td" + +def DEFINE : Joined<["/"], "define:">; +def FOLDDUPS : Flag<["/"], "folddups">; +def MACHINE : Joined<["/"], "machine:">; +def NOLOGO : Flag<["/"], "nologo">; +def OUT : Joined<["/"], "out:">; +def READONLY : Flag<["/"], "readonly">; \ No newline at end of file Index: llvm/tools/llvm-cvtres/llvm-cvtres.h =================================================================== --- /dev/null +++ llvm/tools/llvm-cvtres/llvm-cvtres.h @@ -0,0 +1,13 @@ +//===- llvm-cvtres.h ------------------------------------------ *- C++ --*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TOOLS_LLVMCVTRES_LLVMCVTRES_H +#define LLVM_TOOLS_LLVMCVTRES_LLVMCVTRES_H + +#endif Index: llvm/tools/llvm-cvtres/llvm-cvtres.cpp =================================================================== --- /dev/null +++ llvm/tools/llvm-cvtres/llvm-cvtres.cpp @@ -0,0 +1,78 @@ +//===- llvm-cvtres.cpp - Serialize .res files into .obj ---------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Serialize .res files into .obj files. This is intended to be a +// platform-independent port of Microsoft's cvtres.exe. +// +//===----------------------------------------------------------------------===// + +#include "llvm-cvtres.h" + +#include "llvm/Option/Arg.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +namespace { + +enum ID { + OPT_INVALID = 0, // This is not an option ID. +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR) OPT_##ID, +#include "Opts.inc" +#undef OPTION +}; + +#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#include "Opts.inc" +#undef PREFIX + +static const llvm::opt::OptTable::Info InfoTable[] = { +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ + HELPTEXT, METAVAR) \ + { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, llvm::opt::Option::KIND##Class, PARAM, \ + FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS }, +#include "Opts.inc" +#undef OPTION +}; + +class CvtResOptTable : public llvm::opt::OptTable { +public: + CvtResOptTable() : OptTable(InfoTable, true) {} +}; + +} + +int main(int argc_, const char *argv_[]) { + CvtResOptTable T; + unsigned MAI, MAC; + llvm::ArrayRef ArgsArr = makeArrayRef(argv_, argc_); + llvm::opt::InputArgList inputArgs = T.ParseArgs(ArgsArr, MAI, MAC); + + if (inputArgs.hasArg(OPT_DEFINE)) + llvm::outs() << "has define flag with symbol " + << inputArgs.getLastArgValue(OPT_DEFINE) << "\n"; + if (inputArgs.hasArg(OPT_FOLDDUPS)) + llvm::outs() << "has folddups flag\n"; + if (inputArgs.hasArg(OPT_MACHINE)) + llvm::outs() << "has machine flag with value " + << inputArgs.getLastArgValue(OPT_MACHINE) << "\n"; + if (inputArgs.hasArg(OPT_NOLOGO)) + llvm::outs() << "has nologo flag\n"; + if (inputArgs.hasArg(OPT_OUT)) + llvm::outs() << "has out flag with value " + << inputArgs.getLastArgValue(OPT_OUT) << "\n"; + if (inputArgs.hasArg(OPT_READONLY)) + llvm::outs() << "has readonly flag\n"; + + llvm::outs().flush(); + return 0; +}