Validate the generated C++ code in llvmc tests.
authorMikhail Glushenkov <foldr@codedgers.com>
Tue, 15 Dec 2009 03:04:52 +0000 (03:04 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Tue, 15 Dec 2009 03:04:52 +0000 (03:04 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91404 91177308-0d34-0410-b5e6-96231b3b80d8

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

index cfd675b9ad5beacfc84533cab8b3eb3c9624cfd2..8d2f63b3306363666a438c97cedd47ba38550fc7 100644 (file)
@@ -42,9 +42,9 @@ def hidden;
 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.
index b30f84c6e2a3be302037b8da867dab4fec3fba0a..934905b15e99d054e50b2eb6ce3f6477f5e80509 100644 (file)
@@ -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"
 
index 694468f2dda8031e999c14160db165f65f7dc7e2..77aab95c5f03db81fbdb13ca6b33b8f0aed4cedd 100644 (file)
@@ -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"
 
index 5c69af7d8054d0ed21dcb246c6ab74024e6cd917..4694b106e2b4263e247aef1caf21ccf16be546fc 100644 (file)
@@ -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"
 
index 51bd494610eae6991a64b1b542ab2cf67e900366..54fc050a98156b4faa0b11c279e950d8984a443b 100644 (file)
@@ -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"
 
index 478d1267282e1c5fed90b26fc66089f67dd9cee6..0cda1bf1a5bef50faf8be74c034dbf20bfe48c07 100644 (file)
@@ -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"
 
index aebb198fd154701b90769594ece2a5d48da40caf..29f61a4c0cfc5d4030a04971dc99bacf79c83d66 100644 (file)
@@ -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"
 
index 3bdb3eeb9d43f22575a83f0b583cc84a71254caf..909dc8bf9b472fceeedfda3c717c535e5302803d 100644 (file)
@@ -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"
 
index a2cc4d81549ba5abe305209ecf1dd4783cfe759f..7fb3df1c9a66b2af2ce610dd59be62676a9d0b64 100644 (file)
@@ -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"
 
index d9a4fc1c1b12418792f633ff36bc6d42b25f466e..3d68d050ee967795013eee63b054634d41dc0bf0 100644 (file)
@@ -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"
 
index bd1e0338f7555d17f7fc7ccd83283b246460001b..108eb86dbebd43c6b68b635ed3ca20a97ae9ceb6 100644 (file)
@@ -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"
 
index 64dbc9b1845c5f261efe1c17590d728f11e69add..9702248b572913510b32c37acb1371cb650c067a 100644 (file)
@@ -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"
 
index 2a4a7495ab0b4486c9926a67472c73a70d630802..7b8e721397a240a9e929f19cf03fc4978f29b85b 100644 (file)
@@ -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"
 
index 2eea3e98343c9ab2688f61e7f62ae5114c589aa2..96c1f17e18e04f13c27c941dc978a2025704a81f 100644 (file)
@@ -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"
index 38b7eb7dffea310afb4979a51949e95299c006d5..08be7cfe8a7af1120a4f2608d985c5f4c7eec857 100644 (file)
@@ -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"),
index 5b9f4357feabe6983024b7454d512002d10fede2..2f5e68bfe51f1ad66b4c4959624de423facbec3f 100644 (file)
@@ -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"
 
index 1a4064e44b270cc24b694ba4d39e89d86b76c919..9523e24702ea87a93e1fd33725638d40128c82dd 100644 (file)
@@ -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!"
 
index 789fc09a493c8c24b7adee9c5efe0db193b389f6..4d80a2a6e1638b27aafa21213ebec90042d3ecc8 100644 (file)
@@ -336,8 +336,8 @@ separate option groups syntactically.
      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 @@ separate option groups syntactically.
    - ``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
index acffc435f1a84cb804ef69dc8c3e19f805cb9a95..69001dd27596d93894eab7f736d34bb315a2e7e0 100644 (file)
@@ -211,7 +211,7 @@ OptionType::OptionType stringToOptionType(const std::string& T) {
 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 @@ struct OptionDescription {
   bool isOneOrMore() const;
   void setOneOrMore();
 
-  bool isZeroOrOne() const;
-  void setZeroOrOne();
+  bool isOptional() const;
+  void setOptional();
 
   bool isHidden() const;
   void setHidden();
@@ -331,11 +331,11 @@ void OptionDescription::setOneOrMore() {
   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 @@ public:
       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 @@ private:
 
   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 @@ private:
 
   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 @@ private:
     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 @@ class EmitActionHandlersCallback
     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 @@ void EmitOptionDefinitions (const OptionDescriptions& descs,
     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())