]> granicus.if.org Git - llvm/commitdiff
Use StringRef instead of raw pointer in TargetRegistry API (NFC)
authorMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 06:25:30 +0000 (06:25 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Sat, 1 Oct 2016 06:25:30 +0000 (06:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283017 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/TargetRegistry.h
lib/Support/TargetRegistry.cpp
lib/Target/TargetMachineC.cpp
tools/llc/llc.cpp

index 99d679a31c0c4188264300214fade90e87e00bb8..9966ec97d785aab6911a4b5e863dc4191f2451f9 100644 (file)
@@ -165,10 +165,10 @@ private:
   ArchMatchFnTy ArchMatchFn;
 
   /// Name - The target name.
-  const char *Name;
+  StringRef Name;
 
   /// ShortDesc - A short description of the target.
-  const char *ShortDesc;
+  StringRef ShortDesc;
 
   /// HasJIT - Whether this target supports the JIT.
   bool HasJIT;
@@ -262,10 +262,10 @@ public:
   const Target *getNext() const { return Next; }
 
   /// getName - Get the target name.
-  const char *getName() const { return Name; }
+  StringRef getName() const { return Name; }
 
   /// getShortDescription - Get a short description of the target.
-  const char *getShortDescription() const { return ShortDesc; }
+  StringRef getShortDescription() const { return ShortDesc; }
 
   /// @}
   /// @name Feature Predicates
@@ -624,7 +624,7 @@ struct TargetRegistry {
   /// @param ArchMatchFn - The arch match checking function for this target.
   /// @param HasJIT - Whether the target supports JIT code
   /// generation.
-  static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
+  static void RegisterTarget(Target &T, StringRef Name, StringRef ShortDesc,
                              Target::ArchMatchFnTy ArchMatchFn,
                              bool HasJIT = false);
 
@@ -857,7 +857,7 @@ struct TargetRegistry {
 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
           bool HasJIT = false>
 struct RegisterTarget {
-  RegisterTarget(Target &T, const char *Name, const char *Desc) {
+  RegisterTarget(Target &T, StringRef Name, StringRef Desc) {
     TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
   }
 
index bed9ed64f802b8467da156d82e6b698c56674174..1b8ad3a010361564f14ac559df4db458bd162003 100644 (file)
@@ -78,8 +78,8 @@ const Target *TargetRegistry::lookupTarget(const std::string &TT,
 
   auto J = std::find_if(std::next(I), targets().end(), ArchMatch);
   if (J != targets().end()) {
-    Error = std::string("Cannot choose between targets \"") + I->Name +
-            "\" and \"" + J->Name + "\"";
+    Error = ("Cannot choose between targets \"" + I->Name +
+            "\" a nd \"" + J->Name + "\"").str();
     return nullptr;
   }
 
@@ -87,16 +87,16 @@ const Target *TargetRegistry::lookupTarget(const std::string &TT,
 }
 
 void TargetRegistry::RegisterTarget(Target &T,
-                                    const char *Name,
-                                    const char *ShortDesc,
+                                    StringRef Name,
+                                    StringRef ShortDesc,
                                     Target::ArchMatchFnTy ArchMatchFn,
                                     bool HasJIT) {
-  assert(Name && ShortDesc && ArchMatchFn &&
+  assert(!Name.empty() && !ShortDesc.empty() && ArchMatchFn &&
          "Missing required target information!");
 
   // Check if this target has already been initialized, we allow this as a
   // convenience to some clients.
-  if (T.Name)
+  if (!T.Name.empty())
     return;
          
   // Add to the list of targets.
index 5fb5b02278002cfc08276420b0e6b26ee539c868..b20012fba32d428533cfe5e3654dd1f6698ed595 100644 (file)
@@ -81,11 +81,11 @@ LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
 }
 
 const char * LLVMGetTargetName(LLVMTargetRef T) {
-  return unwrap(T)->getName();
+  return unwrap(T)->getName().data();
 }
 
 const char * LLVMGetTargetDescription(LLVMTargetRef T) {
-  return unwrap(T)->getShortDescription();
+  return unwrap(T)->getShortDescription().data();
 }
 
 LLVMBool LLVMTargetHasJIT(LLVMTargetRef T) {
index 1a6ff63b118ed229eca3e51e688ca179cde8fb64..2c64cf33f59e33dcc41ff55656461d905fbc3bb2 100644 (file)
@@ -159,7 +159,7 @@ static cl::opt<RunPassOption, true, cl::parser<std::string>> RunPass(
 static int compileModule(char **, LLVMContext &);
 
 static std::unique_ptr<tool_output_file>
-GetOutputStream(const char *TargetName, Triple::OSType OS,
+GetOutputStream(StringRef TargetName, Triple::OSType OS,
                 const char *ProgName) {
   // If we don't yet have an output filename, make one.
   if (OutputFilename.empty()) {