[llvm-commits] [llvm] r91404 - in /llvm/trunk: include/llvm/CompilerDriver/ test/LLVMC/ tools/llvmc/doc/ utils/TableGen/

Mikhail Glushenkov foldr at codedgers.com
Mon Dec 14 19:04:52 PST 2009


Author: foldr
Date: Mon Dec 14 21:04:52 2009
New Revision: 91404

URL: http://llvm.org/viewvc/llvm-project?rev=91404&view=rev
Log:
Validate the generated C++ code in llvmc tests.

Checks that the code generated by 'tblgen --emit-llvmc' can be actually
compiled. Also fixes two bugs found in this way:

- forward_transformed_value didn't work with non-list arguments
- cl::ZeroOrOne is now called cl::Optional

Modified:
    llvm/trunk/include/llvm/CompilerDriver/Common.td
    llvm/trunk/test/LLVMC/EmptyCompilationGraph.td
    llvm/trunk/test/LLVMC/EnvParentheses.td
    llvm/trunk/test/LLVMC/ExternOptions.td
    llvm/trunk/test/LLVMC/ForwardAs.td
    llvm/trunk/test/LLVMC/ForwardTransformedValue.td
    llvm/trunk/test/LLVMC/ForwardValue.td
    llvm/trunk/test/LLVMC/HookWithArguments.td
    llvm/trunk/test/LLVMC/HookWithInFile.td
    llvm/trunk/test/LLVMC/Init.td
    llvm/trunk/test/LLVMC/MultiValuedOption.td
    llvm/trunk/test/LLVMC/MultipleCompilationGraphs.td
    llvm/trunk/test/LLVMC/NoActions.td
    llvm/trunk/test/LLVMC/NoCompilationGraph.td
    llvm/trunk/test/LLVMC/OneOrMore.td
    llvm/trunk/test/LLVMC/OptionPreprocessor.td
    llvm/trunk/test/LLVMC/TestWarnings.td
    llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
    llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp

Modified: llvm/trunk/include/llvm/CompilerDriver/Common.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CompilerDriver/Common.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CompilerDriver/Common.td (original)
+++ llvm/trunk/include/llvm/CompilerDriver/Common.td Mon Dec 14 21:04:52 2009
@@ -42,9 +42,9 @@
 def init;
 def multi_val;
 def one_or_more;
+def optional;
 def really_hidden;
 def required;
-def zero_or_one;
 def comma_separated;
 
 // The 'case' construct.

Modified: llvm/trunk/test/LLVMC/EmptyCompilationGraph.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/EmptyCompilationGraph.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/EmptyCompilationGraph.td (original)
+++ llvm/trunk/test/LLVMC/EmptyCompilationGraph.td Mon Dec 14 21:04:52 2009
@@ -1,5 +1,6 @@
 // Check that the compilation graph can be empty.
-// RUN: tblgen -I %p/../../include --gen-llvmc %s
+// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/EnvParentheses.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/EnvParentheses.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/EnvParentheses.td (original)
+++ llvm/trunk/test/LLVMC/EnvParentheses.td Mon Dec 14 21:04:52 2009
@@ -2,6 +2,7 @@
 // http://llvm.org/bugs/show_bug.cgi?id=4157
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: not grep {)));} %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/ExternOptions.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/ExternOptions.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/ExternOptions.td (original)
+++ llvm/trunk/test/LLVMC/ExternOptions.td Mon Dec 14 21:04:52 2009
@@ -2,6 +2,7 @@
 // The dummy tool and graph are required to silence warnings.
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep {extern .* AutoGeneratedSwitch_Wall} %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/ForwardAs.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/ForwardAs.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/ForwardAs.td (original)
+++ llvm/trunk/test/LLVMC/ForwardAs.td Mon Dec 14 21:04:52 2009
@@ -2,6 +2,7 @@
 // http://llvm.org/bugs/show_bug.cgi?id=4159
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep unique_name %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/ForwardTransformedValue.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/ForwardTransformedValue.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/ForwardTransformedValue.td (original)
+++ llvm/trunk/test/LLVMC/ForwardTransformedValue.td Mon Dec 14 21:04:52 2009
@@ -1,8 +1,9 @@
 // Check that forward_transformed_value works.
 // The dummy tool and graph are required to silence warnings.
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
-// RUN: grep HookA %t
-// RUN: grep HookB %t
+// RUN: grep HookA %t | count 2
+// RUN: grep HookB %t | count 2
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/ForwardValue.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/ForwardValue.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/ForwardValue.td (original)
+++ llvm/trunk/test/LLVMC/ForwardValue.td Mon Dec 14 21:04:52 2009
@@ -3,6 +3,7 @@
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep {vec.push_back\(AutoGeneratedParameter_a\)} %t
 // RUN: grep {std::copy\(AutoGeneratedList_b.begin\(\)} %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/HookWithArguments.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/HookWithArguments.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/HookWithArguments.td (original)
+++ llvm/trunk/test/LLVMC/HookWithArguments.td Mon Dec 14 21:04:52 2009
@@ -4,6 +4,7 @@
 // RUN: grep "/path" %t | count 1
 // RUN: grep "VARIABLE" %t | count 1
 // RUN: grep "/2path" %t | count 1
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/HookWithInFile.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/HookWithInFile.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/HookWithInFile.td (original)
+++ llvm/trunk/test/LLVMC/HookWithInFile.td Mon Dec 14 21:04:52 2009
@@ -1,6 +1,7 @@
 // Check that a hook can be given $INFILE as an argument.
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep Hook\\(inFile.c_str\\(\\)\\) %t | count 1
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/Init.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/Init.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/Init.td (original)
+++ llvm/trunk/test/LLVMC/Init.td Mon Dec 14 21:04:52 2009
@@ -2,6 +2,7 @@
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep cl::init(\\"some-string\\") %t | count 1
 // RUN: grep cl::init(true) %t | count 1
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/MultiValuedOption.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/MultiValuedOption.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/MultiValuedOption.td (original)
+++ llvm/trunk/test/LLVMC/MultiValuedOption.td Mon Dec 14 21:04:52 2009
@@ -2,6 +2,7 @@
 // The dummy tool and graph are required to silence warnings.
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
 // RUN: grep cl::multi_val(2) %t | count 1
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/MultipleCompilationGraphs.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/MultipleCompilationGraphs.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/MultipleCompilationGraphs.td (original)
+++ llvm/trunk/test/LLVMC/MultipleCompilationGraphs.td Mon Dec 14 21:04:52 2009
@@ -1,5 +1,6 @@
 // Check that multiple compilation graphs are allowed.
-// RUN: tblgen -I %p/../../include --gen-llvmc %s
+// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/NoActions.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/NoActions.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/NoActions.td (original)
+++ llvm/trunk/test/LLVMC/NoActions.td Mon Dec 14 21:04:52 2009
@@ -1,5 +1,7 @@
 // Check that tools without associated actions are accepted.
-// RUN: tblgen -I %p/../../include --gen-llvmc %s | grep dummy_tool
+// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
+// RUN: grep dummy_tool %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/NoCompilationGraph.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/NoCompilationGraph.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/NoCompilationGraph.td (original)
+++ llvm/trunk/test/LLVMC/NoCompilationGraph.td Mon Dec 14 21:04:52 2009
@@ -1,4 +1,5 @@
 // Check that the compilation graph is not required.
-// RUN: tblgen -I %p/../../include --gen-llvmc %s
+// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"

Modified: llvm/trunk/test/LLVMC/OneOrMore.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/OneOrMore.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/OneOrMore.td (original)
+++ llvm/trunk/test/LLVMC/OneOrMore.td Mon Dec 14 21:04:52 2009
@@ -1,14 +1,15 @@
 // Check that (one_or_more) and (zero_or_one) properties work.
 // The dummy tool and graph are required to silence warnings.
 // RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
-// RUN: grep cl::ZeroOrOne %t | count 1
+// RUN: grep cl::Optional %t | count 1
 // RUN: grep cl::OneOrMore %t | count 1
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 
 def OptList : OptionList<[
     (prefix_list_option "foo", (one_or_more)),
-    (parameter_list_option "baz", (zero_or_one))]>;
+    (parameter_list_option "baz", (optional))]>;
 
 def dummy_tool : Tool<[
 (cmd_line "dummy_cmd $INFILE"),

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

==============================================================================
--- llvm/trunk/test/LLVMC/OptionPreprocessor.td (original)
+++ llvm/trunk/test/LLVMC/OptionPreprocessor.td Mon Dec 14 21:04:52 2009
@@ -3,6 +3,7 @@
 // RUN: grep W1 %t
 // RUN: grep W2 %t
 // RUN: grep W3 %t
+// RUN: %compile_cxx -fexceptions -x c++ %t
 
 include "llvm/CompilerDriver/Common.td"
 

Modified: llvm/trunk/test/LLVMC/TestWarnings.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LLVMC/TestWarnings.td?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/test/LLVMC/TestWarnings.td (original)
+++ llvm/trunk/test/LLVMC/TestWarnings.td Mon Dec 14 21:04:52 2009
@@ -1,4 +1,4 @@
-// Check that the compiler warns about unused options.
+// Check that warnings about unused options are really emitted.
 // This should fail because the output is printed on stderr.
 // RUN: ignore tblgen -I %p/../../include --gen-llvmc %s |& grep "option '-Wall' has no effect!"
 

Modified: llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst?rev=91404&r1=91403&r2=91404&view=diff

==============================================================================
--- llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst (original)
+++ llvm/trunk/tools/llvmc/doc/LLVMC-Reference.rst Mon Dec 14 21:04:52 2009
@@ -336,8 +336,8 @@
      it is synonymous with ``required``. Incompatible with ``required`` and
      ``zero_or_one``.
 
-   - ``zero_or_one`` - the option can be specified zero or one times. Useful
-     only for list options in conjunction with ``multi_val``. Incompatible with
+   - ``optional`` - the option can be specified zero or one times. Useful only
+     for list options in conjunction with ``multi_val``. Incompatible with
      ``required`` and ``one_or_more``.
 
    - ``hidden`` - the description of this option will not appear in
@@ -356,7 +356,7 @@
    - ``multi_val n`` - this option takes *n* arguments (can be useful in some
      special cases). Usage example: ``(parameter_list_option "foo", (multi_val
      3))``; the command-line syntax is '-foo a b c'. Only list options can have
-     this attribute; you can, however, use the ``one_or_more``, ``zero_or_one``
+     this attribute; you can, however, use the ``one_or_more``, ``optional``
      and ``required`` properties.
 
    - ``init`` - this option has a default value, either a string (if it is a

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

==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Mon Dec 14 21:04:52 2009
@@ -211,7 +211,7 @@
 namespace OptionDescriptionFlags {
   enum OptionDescriptionFlags { Required = 0x1, Hidden = 0x2,
                                 ReallyHidden = 0x4, Extern = 0x8,
-                                OneOrMore = 0x10, ZeroOrOne = 0x20,
+                                OneOrMore = 0x10, Optional = 0x20,
                                 CommaSeparated = 0x40 };
 }
 
@@ -260,8 +260,8 @@
   bool isOneOrMore() const;
   void setOneOrMore();
 
-  bool isZeroOrOne() const;
-  void setZeroOrOne();
+  bool isOptional() const;
+  void setOptional();
 
   bool isHidden() const;
   void setHidden();
@@ -331,11 +331,11 @@
   Flags |= OptionDescriptionFlags::OneOrMore;
 }
 
-bool OptionDescription::isZeroOrOne() const {
-  return Flags & OptionDescriptionFlags::ZeroOrOne;
+bool OptionDescription::isOptional() const {
+  return Flags & OptionDescriptionFlags::Optional;
 }
-void OptionDescription::setZeroOrOne() {
-  Flags |= OptionDescriptionFlags::ZeroOrOne;
+void OptionDescription::setOptional() {
+  Flags |= OptionDescriptionFlags::Optional;
 }
 
 bool OptionDescription::isHidden() const {
@@ -548,7 +548,7 @@
       AddHandler("one_or_more", &CollectOptionProperties::onOneOrMore);
       AddHandler("really_hidden", &CollectOptionProperties::onReallyHidden);
       AddHandler("required", &CollectOptionProperties::onRequired);
-      AddHandler("zero_or_one", &CollectOptionProperties::onZeroOrOne);
+      AddHandler("optional", &CollectOptionProperties::onOptional);
       AddHandler("comma_separated", &CollectOptionProperties::onCommaSeparated);
 
       staticMembersInitialized_ = true;
@@ -595,8 +595,8 @@
 
   void onRequired (const DagInit* d) {
     checkNumberOfArguments(d, 0);
-    if (optDesc_.isOneOrMore() || optDesc_.isZeroOrOne())
-      throw "Only one of (required), (zero_or_one) or "
+    if (optDesc_.isOneOrMore() || optDesc_.isOptional())
+      throw "Only one of (required), (optional) or "
         "(one_or_more) properties is allowed!";
     optDesc_.setRequired();
   }
@@ -617,8 +617,8 @@
 
   void onOneOrMore (const DagInit* d) {
     checkNumberOfArguments(d, 0);
-    if (optDesc_.isRequired() || optDesc_.isZeroOrOne())
-      throw "Only one of (required), (zero_or_one) or "
+    if (optDesc_.isRequired() || optDesc_.isOptional())
+      throw "Only one of (required), (optional) or "
         "(one_or_more) properties is allowed!";
     if (!OptionType::IsList(optDesc_.Type))
       llvm::errs() << "Warning: specifying the 'one_or_more' property "
@@ -626,15 +626,15 @@
     optDesc_.setOneOrMore();
   }
 
-  void onZeroOrOne (const DagInit* d) {
+  void onOptional (const DagInit* d) {
     checkNumberOfArguments(d, 0);
     if (optDesc_.isRequired() || optDesc_.isOneOrMore())
-      throw "Only one of (required), (zero_or_one) or "
+      throw "Only one of (required), (optional) or "
         "(one_or_more) properties is allowed!";
     if (!OptionType::IsList(optDesc_.Type))
-      llvm::errs() << "Warning: specifying the 'zero_or_one' property"
+      llvm::errs() << "Warning: specifying the 'optional' property"
         "on a non-list option will have no effect.\n";
-    optDesc_.setZeroOrOne();
+    optDesc_.setOptional();
   }
 
   void onMultiVal (const DagInit* d) {
@@ -1882,7 +1882,8 @@
     const OptionDescription& D = OptDescs.FindListOrParameter(Name);
 
     O.indent(IndentLevel) << "vec.push_back(" << "hooks::"
-                          << Hook << "(" << D.GenVariableName() << "));\n";
+                          << Hook << "(" << D.GenVariableName()
+                          << (D.isParameter() ? ".c_str()" : "") << "));\n";
   }
 
 
@@ -2211,8 +2212,8 @@
     else if (val.isOneOrMore() && val.isList()) {
         O << ", cl::OneOrMore";
     }
-    else if (val.isZeroOrOne() && val.isList()) {
-        O << ", cl::ZeroOrOne";
+    else if (val.isOptional() && val.isList()) {
+        O << ", cl::Optional";
     }
 
     if (val.isReallyHidden())





More information about the llvm-commits mailing list