From fdee9546235fcacdd73984e000ca4308ed8cfe1a Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Mon, 22 Sep 2008 20:46:19 +0000 Subject: [PATCH] Add a (forward_as) option property git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56459 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvmc2/Common.td | 6 +-- tools/llvmc2/doc/LLVMC-Reference.rst | 5 +- utils/TableGen/LLVMCConfigurationEmitter.cpp | 50 +++++++++++++++----- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/tools/llvmc2/Common.td b/tools/llvmc2/Common.td index 046e19e4448..45518385e41 100644 --- a/tools/llvmc2/Common.td +++ b/tools/llvmc2/Common.td @@ -1,4 +1,4 @@ -//===- Common.td - Common definitions for LLVMCC ----------*- tablegen -*-===// +//===- Common.td - Common definitions for LLVMC2 ----------*- tablegen -*-===// // // The LLVM Compiler Infrastructure // @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file contains common definitions used in llvmcc tool description files. +// This file contains common definitions used in llvmc2 tool description files. // //===----------------------------------------------------------------------===// @@ -41,6 +41,7 @@ def prefix_list_option; def append_cmd; def forward; +def forward_as; def stop_compilation; def unpack_values; def help; @@ -58,7 +59,6 @@ def parameter_equals; def element_in_list; def input_languages_contain; def not_empty; -// TOTHINK: remove? def default; // Boolean operators. diff --git a/tools/llvmc2/doc/LLVMC-Reference.rst b/tools/llvmc2/doc/LLVMC-Reference.rst index e71d99c30eb..bd55f38cc46 100644 --- a/tools/llvmc2/doc/LLVMC-Reference.rst +++ b/tools/llvmc2/doc/LLVMC-Reference.rst @@ -250,8 +250,11 @@ currently implemented option types and properties are described below: - ``forward`` - forward this option unchanged. + - ``forward_as`` - Change the name of this option, but forward the + argument unchanged. Example: ``(forward_as "--disable-optimize")``. + - ``output_suffix`` - modify the output suffix of this - tool. Example : ``(switch "E", (output_suffix "i")``. + tool. Example: ``(switch "E", (output_suffix "i")``. - ``stop_compilation`` - stop compilation after this phase. diff --git a/utils/TableGen/LLVMCConfigurationEmitter.cpp b/utils/TableGen/LLVMCConfigurationEmitter.cpp index f336d452031..bc742998bd8 100644 --- a/utils/TableGen/LLVMCConfigurationEmitter.cpp +++ b/utils/TableGen/LLVMCConfigurationEmitter.cpp @@ -155,11 +155,18 @@ struct OptionDescription { std::string EscapeVariableName(const std::string& Var) const { std::string ret; for (unsigned i = 0; i != Var.size(); ++i) { - if (Var[i] == ',') { + char cur_char = Var[i]; + if (cur_char == ',') { + ret += "_comma_"; + } + else if (cur_char == '+') { + ret += "_plus_"; + } + else if (cur_char == ',') { ret += "_comma_"; } else { - ret.push_back(Var[i]); + ret.push_back(cur_char); } } return ret; @@ -279,7 +286,7 @@ namespace ToolOptionDescriptionFlags { Forward = 0x2, UnpackValues = 0x4}; } namespace OptionPropertyType { - enum OptionPropertyType { AppendCmd, OutputSuffix }; + enum OptionPropertyType { AppendCmd, ForwardAs, OutputSuffix }; } typedef std::pair @@ -399,6 +406,8 @@ public: &CollectOptionProperties::onAppendCmd; optionPropertyHandlers_["forward"] = &CollectOptionProperties::onForward; + optionPropertyHandlers_["forward_as"] = + &CollectOptionProperties::onForwardAs; optionPropertyHandlers_["help"] = &CollectOptionProperties::onHelp; optionPropertyHandlers_["output_suffix"] = @@ -466,6 +475,15 @@ private: toolProps_->OptDescs[optDesc_.Name].setForward(); } + void onForwardAs (const DagInit* d) { + checkNumberOfArguments(d, 1); + checkToolProps(d); + const std::string& cmd = InitPtrToString(d->getArg(0)); + + toolProps_->OptDescs[optDesc_.Name]. + AddProperty(OptionPropertyType::ForwardAs, cmd); + } + void onHelp (const DagInit* d) { checkNumberOfArguments(d, 1); const std::string& help_message = InitPtrToString(d->getArg(0)); @@ -956,26 +974,31 @@ void EmitCaseConstructHandler(const DagInit* d, const char* IndentLevel, /// EmitForwardOptionPropertyHandlingCode - Helper function used to /// implement EmitOptionPropertyHandlingCode(). Emits code for -/// handling the (forward) option property. +/// handling the (forward) and (forward_as) option properties. void EmitForwardOptionPropertyHandlingCode (const ToolOptionDescription& D, + const std::string& NewName, std::ostream& O) { + const std::string& Name = NewName.empty() + ? ("-" + D.Name) + : NewName; + switch (D.Type) { case OptionType::Switch: - O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n"; + O << Indent3 << "vec.push_back(\"" << Name << "\");\n"; break; case OptionType::Parameter: - O << Indent3 << "vec.push_back(\"-" << D.Name << "\");\n"; + O << Indent3 << "vec.push_back(\"" << Name << "\");\n"; O << Indent3 << "vec.push_back(" << D.GenVariableName() << ");\n"; break; case OptionType::Prefix: - O << Indent3 << "vec.push_back(\"-" << D.Name << "\" + " + O << Indent3 << "vec.push_back(\"" << Name << "\" + " << D.GenVariableName() << ");\n"; break; case OptionType::PrefixList: O << Indent3 << "for (" << D.GenTypeDeclaration() << "::iterator B = " << D.GenVariableName() << ".begin(),\n" << Indent3 << "E = " << D.GenVariableName() << ".end(); B != E; ++B)\n" - << Indent4 << "vec.push_back(\"-" << D.Name << "\" + " + << Indent4 << "vec.push_back(\"" << Name << "\" + " << "*B);\n"; break; case OptionType::ParameterList: @@ -983,7 +1006,7 @@ void EmitForwardOptionPropertyHandlingCode (const ToolOptionDescription& D, << "::iterator B = " << D.GenVariableName() << ".begin(),\n" << Indent3 << "E = " << D.GenVariableName() << ".end() ; B != E; ++B) {\n" - << Indent4 << "vec.push_back(\"-" << D.Name << "\");\n" + << Indent4 << "vec.push_back(\"" << Name << "\");\n" << Indent4 << "vec.push_back(*B);\n" << Indent3 << "}\n"; break; @@ -1001,7 +1024,8 @@ bool ToolOptionHasInterestingProperties(const ToolOptionDescription& D) { for (OptionPropertyList::const_iterator B = D.Props.begin(), E = D.Props.end(); B != E; ++B) { const OptionProperty& OptProp = *B; - if (OptProp.first == OptionPropertyType::AppendCmd) + if (OptProp.first == OptionPropertyType::AppendCmd + || OptProp.first == OptionPropertyType::ForwardAs) ret = true; } if (D.isForward() || D.isUnpackValues()) @@ -1036,6 +1060,10 @@ void EmitOptionPropertyHandlingCode (const ToolOptionDescription& D, case OptionPropertyType::AppendCmd: O << Indent3 << "vec.push_back(\"" << val.second << "\");\n"; break; + // (forward_as) property + case OptionPropertyType::ForwardAs: + EmitForwardOptionPropertyHandlingCode(D, val.second, O); + break; // Other properties with argument default: break; @@ -1046,7 +1074,7 @@ void EmitOptionPropertyHandlingCode (const ToolOptionDescription& D, // (forward) property if (D.isForward()) - EmitForwardOptionPropertyHandlingCode(D, O); + EmitForwardOptionPropertyHandlingCode(D, "", O); // (unpack_values) property if (D.isUnpackValues()) { -- 2.34.1