Filter option names to escape symbols not allowed as C++ identifiers.
authorMikhail Glushenkov <foldr@codedgers.com>
Mon, 12 May 2008 16:33:06 +0000 (16:33 +0000)
committerMikhail Glushenkov <foldr@codedgers.com>
Mon, 12 May 2008 16:33:06 +0000 (16:33 +0000)
Makes it possible to use options with names like "Wa,".
Also fixes the -Wall option handling as a side-effect.

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

test/LLVMC/wall.c [new file with mode: 0644]
tools/llvmc2/Tools.td
utils/TableGen/LLVMCConfigurationEmitter.cpp

diff --git a/test/LLVMC/wall.c b/test/LLVMC/wall.c
new file mode 100644 (file)
index 0000000..9af9bfb
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Check that -Wall works as intended
+ * RUN: llvmc2 -Wall %s -o %t
+ * RUN: ./%t | grep hello
+ */
+
+#include <stdio.h>
+
+int main() {
+    printf("hello\n");
+    return 0;
+}
index 26925628d19a6149bcd9bebcaf66ce9375e97b47..5a614cf4ac0bc61fc5f18137af8752d724d542af 100644 (file)
@@ -71,7 +71,7 @@ def llvm_gcc_assembler : Tool<
  (cmd_line "llvm-gcc -c -x assembler $INFILE -o $OUTFILE"),
  (switch_option "c", (stop_compilation),
                 (help "Compile and assemble, but do not link")),
- (prefix_list_option "Wa", (unpack_values), (help "pass options to assembler"))
+ (prefix_list_option "Wa,", (unpack_values), (help "pass options to assembler"))
 ]>;
 
 // Default linker
@@ -83,7 +83,7 @@ def llvm_gcc_linker : Tool<
  (join),
  (prefix_list_option "L", (forward), (help "add a directory to link path")),
  (prefix_list_option "l", (forward), (help "search a library when linking")),
- (prefix_list_option "Wl", (unpack_values), (help "pass options to linker"))
+ (prefix_list_option "Wl,", (unpack_values), (help "pass options to linker"))
 ]>;
 
 // Alternative linker for C++
@@ -97,7 +97,7 @@ def llvm_gcc_cpp_linker : Tool<
                    (help "Choose linker (possible values: gcc, g++)")),
  (prefix_list_option "L", (forward)),
  (prefix_list_option "l", (forward)),
- (prefix_list_option "Wl", (unpack_values))
+ (prefix_list_option "Wl,", (unpack_values))
 ]>;
 
 // Language map
index 1947aa5bef55001a51bb7a83a84e1decf600b93c..8e4d870f76b13498d68d87e46eaf7821d84e14f8 100644 (file)
@@ -135,19 +135,36 @@ struct OptionDescription {
     }
   }
 
+  // Escape commas and other symbols not allowed in the C++ variable
+  // names. Makes it possible to use options with names like "Wa,"
+  // (useful for prefix options).
+  std::string EscapeVariableName(const std::string& Var) const {
+    std::string ret;
+    for (unsigned i = 0; i != Var.size(); ++i) {
+      if (Var[i] == ',') {
+        ret += "_comma_";
+      }
+      else {
+        ret.push_back(Var[i]);
+      }
+    }
+    return ret;
+  }
+
   std::string GenVariableName() const {
+    const std::string& EscapedName = EscapeVariableName(Name);
     switch (Type) {
     case OptionType::Switch:
-     return "AutoGeneratedSwitch" + Name;
+     return "AutoGeneratedSwitch" + EscapedName;
    case OptionType::Prefix:
-     return "AutoGeneratedPrefix" + Name;
+     return "AutoGeneratedPrefix" + EscapedName;
    case OptionType::PrefixList:
-     return "AutoGeneratedPrefixList" + Name;
+     return "AutoGeneratedPrefixList" + EscapedName;
    case OptionType::Parameter:
-     return "AutoGeneratedParameter" + Name;
+     return "AutoGeneratedParameter" + EscapedName;
    case OptionType::ParameterList:
    default:
-     return "AutoGeneratedParameterList" + Name;
+     return "AutoGeneratedParameterList" + EscapedName;
    }
   }