Add a (forward_as) option property
authorMikhail Glushenkov <foldr@codedgers.com>
Mon, 22 Sep 2008 20:46:19 +0000 (20:46 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Mon, 22 Sep 2008 20:46:19 +0000 (20:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56459 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvmc2/Common.td
tools/llvmc2/doc/LLVMC-Reference.rst
utils/TableGen/LLVMCConfigurationEmitter.cpp

index 046e19e4448e2db484c88cdb21a53b7c3eb8e6e9..45518385e412f273385cec7012981cc4d54afeaa 100644 (file)
@@ -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.
index e71d99c30eb40f70cefabe6c7d0e7d637ae5d525..bd55f38cc466d45ff25a1a0c7c2c84dd5c1e3ff2 100644 (file)
@@ -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.
 
index f336d452031fc4addb22f9f995a02b9c00e46658..bc742998bd818ba167f6b7241d21468b4165edfd 100644 (file)
@@ -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<OptionPropertyType::OptionPropertyType, std::string>
@@ -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()) {