[llvm-commits] [llvm] r91679 - in /llvm/trunk: test/LLVMC/OptionPreprocessor.td utils/TableGen/LLVMCConfigurationEmitter.cpp

Mikhail Glushenkov foldr at codedgers.com
Fri Dec 18 03:27:26 PST 2009


Author: foldr
Date: Fri Dec 18 05:27:26 2009
New Revision: 91679

URL: http://llvm.org/viewvc/llvm-project?rev=91679&view=rev
Log:
Make 'set_option' work with list options.

This works now: (set_option "list_opt", ["val_1", "val_2", "val_3"])

Modified:
    llvm/trunk/test/LLVMC/OptionPreprocessor.td
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/test/LLVMC/OptionPreprocessor.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/OptionPreprocessor.td?rev=91679&r1=91678&r2=91679&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/OptionPreprocessor.td (original)
+++ llvm/trunk/test/LLVMC/OptionPreprocessor.td Fri Dec 18 05:27:26 2009
@@ -27,8 +27,13 @@
       // CHECK: W2
       // CHECK: foo = true;
       // CHECK: foo_p = "asdf";
+      // CHECK: foo_l.clear();
+      // CHECK: foo_l.push_back("qwert");
+      // CHECK: foo_l.push_back("yuiop");
+      // CHECK: foo_l.push_back("asdf");
       (and (switch_on ["foo", "bar"]), (any_empty ["foo_p", "bar_p"])),
-           [(warning "W2"), (set_option "foo"), (set_option "foo_p", "asdf")],
+           [(warning "W2"), (set_option "foo"), (set_option "foo_p", "asdf"),
+                            (set_option "foo_l", ["qwert", "yuiop", "asdf"])],
       // CHECK: W3
       // CHECK: foo = true;
       // CHECK: bar = true;

Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=91679&r1=91678&r2=91679&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Fri Dec 18 05:27:26 2009
@@ -2354,19 +2354,31 @@
                       d, IndentLevel, O);
   }
 
-  void onSetParameter(const DagInit& d,
+  void onSetListOrParameter(const DagInit& d,
                       unsigned IndentLevel, raw_ostream& O) const {
     checkNumberOfArguments(d, 2);
     const std::string& OptName = InitPtrToString(d.getArg(0));
-    const std::string& Value = InitPtrToString(d.getArg(1));
+    const Init* Value = d.getArg(1);
     const OptionDescription& OptDesc = OptDescs_.FindOption(OptName);
 
-    if (OptDesc.isParameter())
+    if (OptDesc.isList()) {
+      const ListInit& List = InitPtrToList(Value);
+
+      O.indent(IndentLevel) << OptDesc.GenVariableName() << ".clear();\n";
+      for (ListInit::const_iterator B = List.begin(), E = List.end();
+           B != E; ++B) {
+        O.indent(IndentLevel) << OptDesc.GenVariableName() << ".push_back(\""
+                              << InitPtrToString(*B) << "\");\n";
+      }
+    }
+    else if (OptDesc.isParameter()) {
+      const std::string& Str = InitPtrToString(Value);
       O.indent(IndentLevel) << OptDesc.GenVariableName()
-                            << " = \"" << Value << "\";\n";
-    else
-      throw "Two-argument 'set_option' "
-        "can be only applied to parameter options!";
+                            << " = \"" << Str << "\";\n";
+    }
+    else {
+      throw "set_option: -" + OptName + ": is not a list or parameter option!";
+    }
   }
 
   void onSetSwitch(const Init* I,
@@ -2377,7 +2389,7 @@
     if (OptDesc.isSwitch())
       O.indent(IndentLevel) << OptDesc.GenVariableName() << " = true;\n";
     else
-      throw "One-argument 'set_option' can be only applied to switch options!";
+      throw "set_option: -" + OptName + " is not a switch option!";
   }
 
   void onSetOption(const DagInit& d,
@@ -2385,9 +2397,10 @@
   {
     checkNumberOfArguments(d, 1);
 
-    // Two arguments: (set_option "parameter", "value")
+    // Two arguments: (set_option "parameter", VALUE), where VALUE is either a
+    // string or a string list.
     if (d.getNumArgs() > 1)
-      this->onSetParameter(d, IndentLevel, O);
+      this->onSetListOrParameter(d, IndentLevel, O);
     // One argument: (set_option "switch")
     // or (set_option ["switch1", "switch2", ...])
     else





More information about the llvm-commits mailing list