]> granicus.if.org Git - clang/commitdiff
Yay for more StringRefs.
authorAnders Carlsson <andersca@mac.com>
Sat, 30 Jan 2010 19:12:25 +0000 (19:12 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 30 Jan 2010 19:12:25 +0000 (19:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94917 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/TargetInfo.cpp
lib/CodeGen/CGStmt.cpp

index 3d2eec147fc3ae060c682cccb22d8049f0898a92..19701030d4dddfd757164550a50b330621831de9 100644 (file)
@@ -226,11 +226,11 @@ public:
   /// 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 {
index 493beeea6dc5dbed0cfad9e7b64cb29773b3af9e..136089fe90c20b7b1186d4c07a953d1dd0a46992 100644 (file)
@@ -150,39 +150,41 @@ void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
 //===----------------------------------------------------------------------===//
 
 
-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 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
     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 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const {
   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 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const {
 
   // 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 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const {
     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;
     }
   }
index bbd546261800d942c2ba452620140dd76d02b20f..12cf9637550453fc462ac9ee440bd618690624f0 100644 (file)
@@ -1066,10 +1066,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   // 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 += ',';