[cfe-commits] r94917 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/TargetInfo.cpp lib/CodeGen/CGStmt.cpp

Anders Carlsson andersca at mac.com
Sat Jan 30 11:12:25 PST 2010


Author: andersca
Date: Sat Jan 30 13:12:25 2010
New Revision: 94917

URL: http://llvm.org/viewvc/llvm-project?rev=94917&view=rev
Log:
Yay for more StringRefs.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=94917&r1=94916&r2=94917&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sat Jan 30 13:12:25 2010
@@ -226,11 +226,11 @@
   /// isValidGCCRegisterName - Returns whether the passed in string
   /// is a valid register name according to GCC. This is used by Sema for
   /// inline asm statements.
-  bool isValidGCCRegisterName(const char *Name) const;
+  bool isValidGCCRegisterName(llvm::StringRef Name) const;
 
   // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name.
   // For example, on x86 it will return "ax" when "eax" is passed in.
-  const char *getNormalizedGCCRegisterName(const char *Name) const;
+  llvm::StringRef getNormalizedGCCRegisterName(llvm::StringRef Name) const;
 
   struct ConstraintInfo {
     enum {

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=94917&r1=94916&r2=94917&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Sat Jan 30 13:12:25 2010
@@ -150,39 +150,41 @@
 //===----------------------------------------------------------------------===//
 
 
-static void removeGCCRegisterPrefix(const char *&Name) {
+static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) {
   if (Name[0] == '%' || Name[0] == '#')
-    Name++;
+    Name = Name.substr(1);
+  
+  return Name;
 }
 
 /// isValidGCCRegisterName - Returns whether the passed in string
 /// is a valid register name according to GCC. This is used by Sema for
 /// inline asm statements.
-bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
+bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const {
+  if (Name.empty())
+    return false;
+  
   const char * const *Names;
   unsigned NumNames;
 
   // Get rid of any register prefix.
-  removeGCCRegisterPrefix(Name);
+  Name = removeGCCRegisterPrefix(Name);
 
-
-  if (strcmp(Name, "memory") == 0 ||
-      strcmp(Name, "cc") == 0)
+  if (Name == "memory" || Name == "cc")
     return true;
 
   getGCCRegNames(Names, NumNames);
 
   // If we have a number it maps to an entry in the register name array.
   if (isdigit(Name[0])) {
-    char *End;
-    int n = (int)strtol(Name, &End, 0);
-    if (*End == 0)
+    int n;
+    if (!Name.getAsInteger(0, n))
       return n >= 0 && (unsigned)n < NumNames;
   }
 
   // Check register names.
   for (unsigned i = 0; i < NumNames; i++) {
-    if (strcmp(Name, Names[i]) == 0)
+    if (Name == Names[i])
       return true;
   }
 
@@ -195,7 +197,7 @@
     for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
       if (!Aliases[i].Aliases[j])
         break;
-      if (strcmp(Aliases[i].Aliases[j], Name) == 0)
+      if (Aliases[i].Aliases[j] == Name)
         return true;
     }
   }
@@ -203,10 +205,12 @@
   return false;
 }
 
-const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const {
+llvm::StringRef 
+TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const {
   assert(isValidGCCRegisterName(Name) && "Invalid register passed in");
 
-  removeGCCRegisterPrefix(Name);
+  // Get rid of any register prefix.
+  Name = removeGCCRegisterPrefix(Name);
 
   const char * const *Names;
   unsigned NumNames;
@@ -215,9 +219,8 @@
 
   // First, check if we have a number.
   if (isdigit(Name[0])) {
-    char *End;
-    int n = (int)strtol(Name, &End, 0);
-    if (*End == 0) {
+    int n;
+    if (!Name.getAsInteger(0, n)) {
       assert(n >= 0 && (unsigned)n < NumNames &&
              "Out of bounds register number!");
       return Names[n];
@@ -233,7 +236,7 @@
     for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) {
       if (!Aliases[i].Aliases[j])
         break;
-      if (strcmp(Aliases[i].Aliases[j], Name) == 0)
+      if (Aliases[i].Aliases[j] == Name)
         return Aliases[i].Register;
     }
   }

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=94917&r1=94916&r2=94917&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sat Jan 30 13:12:25 2010
@@ -1066,10 +1066,9 @@
 
   // Clobbers
   for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) {
-    std::string Clobber(S.getClobber(i)->getStrData(),
-                        S.getClobber(i)->getByteLength());
+    llvm::StringRef Clobber = S.getClobber(i)->getString();
 
-    Clobber = Target.getNormalizedGCCRegisterName(Clobber.c_str());
+    Clobber = Target.getNormalizedGCCRegisterName(Clobber);
 
     if (i != 0 || NumConstraints != 0)
       Constraints += ',';





More information about the cfe-commits mailing list