Move some functions out of gccld.cpp to GenerateCode.cpp. This allows us
authorChris Lattner <sabre@nondot.org>
Wed, 2 Jun 2004 00:22:24 +0000 (00:22 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 Jun 2004 00:22:24 +0000 (00:22 +0000)
to reduce the inter-file interface in the gccld tool and gets some
uninteresting code out of gccld.cpp.

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

lib/Linker/LinkArchives.cpp
tools/gccld/GenerateCode.cpp
tools/gccld/Linker.cpp
tools/gccld/gccld.cpp
tools/gccld/gccld.h

index 4f322d956ef0fc5e146cf4436cd41515b1f96522..d7a74fb5aff575fd402b56dbc91e9a76535bd496 100644 (file)
@@ -332,8 +332,8 @@ bool llvm::LinkFiles(const char *progname, Module *HeadModule,
         std::cerr << "Trying to link archive '" << Pathname << "'\n";
 
       if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) {
-        PrintAndReturn(progname, ErrorMessage,
-                       ": Error linking in archive '" + Pathname + "'");
+        std::cerr << progname << ": Error linking in archive '" << Pathname 
+                  << "': " << ErrorMessage << "\n";
         return true;
       }
     } else if (IsBytecode(Pathname)) {
@@ -341,8 +341,8 @@ bool llvm::LinkFiles(const char *progname, Module *HeadModule,
         std::cerr << "Trying to link bytecode file '" << Pathname << "'\n";
 
       if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
-        PrintAndReturn(progname, ErrorMessage,
-                       ": Error linking in bytecode file '" + Pathname + "'");
+        std::cerr << progname << ": Error linking in bytecode file '"
+                  << Pathname << "': " << ErrorMessage << "\n";
         return true;
       }
     }
index a844ee751a0c0aea4cbf787df451c2f4a2e4e50f..4498d73300fb88a1e3e46db3062ef2e07d732eed 100644 (file)
@@ -39,6 +39,84 @@ namespace {
                        cl::desc("Do not run any optimization passes"));
 }
 
+/// CopyEnv - This function takes an array of environment variables and makes a
+/// copy of it.  This copy can then be manipulated any way the caller likes
+/// without affecting the process's real environment.
+///
+/// Inputs:
+///  envp - An array of C strings containing an environment.
+///
+/// Return value:
+///  NULL - An error occurred.
+///
+///  Otherwise, a pointer to a new array of C strings is returned.  Every string
+///  in the array is a duplicate of the one in the original array (i.e. we do
+///  not copy the char *'s from one array to another).
+///
+static char ** CopyEnv(char ** const envp) {
+  // Count the number of entries in the old list;
+  unsigned entries;   // The number of entries in the old environment list
+  for (entries = 0; envp[entries] != NULL; entries++)
+    /*empty*/;
+
+  // Add one more entry for the NULL pointer that ends the list.
+  ++entries;
+
+  // If there are no entries at all, just return NULL.
+  if (entries == 0)
+    return NULL;
+
+  // Allocate a new environment list.
+  char **newenv = new char* [entries];
+  if ((newenv = new char* [entries]) == NULL)
+    return NULL;
+
+  // Make a copy of the list.  Don't forget the NULL that ends the list.
+  entries = 0;
+  while (envp[entries] != NULL) {
+    newenv[entries] = new char[strlen (envp[entries]) + 1];
+    strcpy (newenv[entries], envp[entries]);
+    ++entries;
+  }
+  newenv[entries] = NULL;
+
+  return newenv;
+}
+
+
+/// RemoveEnv - Remove the specified environment variable from the environment
+/// array.
+///
+/// Inputs:
+///  name - The name of the variable to remove.  It cannot be NULL.
+///  envp - The array of environment variables.  It cannot be NULL.
+///
+/// Notes:
+///  This is mainly done because functions to remove items from the environment
+///  are not available across all platforms.  In particular, Solaris does not
+///  seem to have an unsetenv() function or a setenv() function (or they are
+///  undocumented if they do exist).
+///
+static void RemoveEnv(const char * name, char ** const envp) {
+  for (unsigned index=0; envp[index] != NULL; index++) {
+    // Find the first equals sign in the array and make it an EOS character.
+    char *p = strchr (envp[index], '=');
+    if (p == NULL)
+      continue;
+    else
+      *p = '\0';
+
+    // Compare the two strings.  If they are equal, zap this string.
+    // Otherwise, restore it.
+    if (!strcmp(name, envp[index]))
+      *envp[index] = '\0';
+    else
+      *p = '=';
+  }
+
+  return;
+}
+
 static inline void addPass(PassManager &PM, Pass *P) {
   // Add the pass to the pass manager...
   PM.add(P);
@@ -270,3 +348,4 @@ int llvm::GenerateNative(const std::string &OutputFilename,
   // Run the compiler to assembly and link together the program.
   return ExecWait(&(cmd[0]), clean_env);
 }
+
index 4f322d956ef0fc5e146cf4436cd41515b1f96522..d7a74fb5aff575fd402b56dbc91e9a76535bd496 100644 (file)
@@ -332,8 +332,8 @@ bool llvm::LinkFiles(const char *progname, Module *HeadModule,
         std::cerr << "Trying to link archive '" << Pathname << "'\n";
 
       if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) {
-        PrintAndReturn(progname, ErrorMessage,
-                       ": Error linking in archive '" + Pathname + "'");
+        std::cerr << progname << ": Error linking in archive '" << Pathname 
+                  << "': " << ErrorMessage << "\n";
         return true;
       }
     } else if (IsBytecode(Pathname)) {
@@ -341,8 +341,8 @@ bool llvm::LinkFiles(const char *progname, Module *HeadModule,
         std::cerr << "Trying to link bytecode file '" << Pathname << "'\n";
 
       if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
-        PrintAndReturn(progname, ErrorMessage,
-                       ": Error linking in bytecode file '" + Pathname + "'");
+        std::cerr << progname << ": Error linking in bytecode file '"
+                  << Pathname << "': " << ErrorMessage << "\n";
         return true;
       }
     }
index e4614dc03ed31b5655711740f0f20ee44b90701e..a9e91f9dc35d08b4d2b05941cfdfd83f65dae528 100644 (file)
@@ -93,109 +93,17 @@ namespace {
   CO6("h", cl::Hidden, cl::desc("Compatibility option: ignored"));
 }
 
-namespace llvm {
-
-/// PrintAndReturn - Prints a message to standard error and returns a value
-/// usable for an exit status.
+/// PrintAndReturn - Prints a message to standard error and returns true.
 ///
 /// Inputs:
 ///  progname - The name of the program (i.e. argv[0]).
 ///  Message  - The message to print to standard error.
-///  Extra    - Extra information to print between the program name and thei
-///             message.  It is optional.
-///
-/// Return value:
-///  Returns a value that can be used as the exit status (i.e. for exit()).
 ///
-int
-PrintAndReturn(const char *progname,
-               const std::string &Message,
-               const std::string &Extra)
-{
-  std::cerr << progname << Extra << ": " << Message << "\n";
+static int PrintAndReturn(const char *progname, const std::string &Message) {
+  std::cerr << progname << ": " << Message << "\n";
   return 1;
 }
 
-/// CopyEnv - This function takes an array of environment variables and makes a
-/// copy of it.  This copy can then be manipulated any way the caller likes
-/// without affecting the process's real environment.
-///
-/// Inputs:
-///  envp - An array of C strings containing an environment.
-///
-/// Return value:
-///  NULL - An error occurred.
-///
-///  Otherwise, a pointer to a new array of C strings is returned.  Every string
-///  in the array is a duplicate of the one in the original array (i.e. we do
-///  not copy the char *'s from one array to another).
-///
-char ** CopyEnv(char ** const envp) {
-  // Count the number of entries in the old list;
-  unsigned entries;   // The number of entries in the old environment list
-  for (entries = 0; envp[entries] != NULL; entries++)
-    /*empty*/;
-
-  // Add one more entry for the NULL pointer that ends the list.
-  ++entries;
-
-  // If there are no entries at all, just return NULL.
-  if (entries == 0)
-    return NULL;
-
-  // Allocate a new environment list.
-  char **newenv = new char* [entries];
-  if ((newenv = new char* [entries]) == NULL)
-    return NULL;
-
-  // Make a copy of the list.  Don't forget the NULL that ends the list.
-  entries = 0;
-  while (envp[entries] != NULL) {
-    newenv[entries] = new char[strlen (envp[entries]) + 1];
-    strcpy (newenv[entries], envp[entries]);
-    ++entries;
-  }
-  newenv[entries] = NULL;
-
-  return newenv;
-}
-
-
-/// RemoveEnv - Remove the specified environment variable from the environment
-/// array.
-///
-/// Inputs:
-///  name - The name of the variable to remove.  It cannot be NULL.
-///  envp - The array of environment variables.  It cannot be NULL.
-///
-/// Notes:
-///  This is mainly done because functions to remove items from the environment
-///  are not available across all platforms.  In particular, Solaris does not
-///  seem to have an unsetenv() function or a setenv() function (or they are
-///  undocumented if they do exist).
-///
-void RemoveEnv(const char * name, char ** const envp) {
-  for (unsigned index=0; envp[index] != NULL; index++) {
-    // Find the first equals sign in the array and make it an EOS character.
-    char *p = strchr (envp[index], '=');
-    if (p == NULL)
-      continue;
-    else
-      *p = '\0';
-
-    // Compare the two strings.  If they are equal, zap this string.
-    // Otherwise, restore it.
-    if (!strcmp(name, envp[index]))
-      *envp[index] = '\0';
-    else
-      *p = '=';
-  }
-
-  return;
-}
-
-} // end LLVM namespace
-
 /// EmitShellScript - Output the wrapper file that invokes the JIT on the LLVM
 /// bytecode file for the program.
 static void EmitShellScript(char **argv) {
index 8913d379fb9b3add504971500895ee07780e9614..7f62bad542a077ba90066c0c35acc16cfc910546 100644 (file)
 
 namespace llvm {
 
-int
-PrintAndReturn (const char *progname,
-                const std::string &Message,
-                const std::string &Extra = "");
-
 void
 GetAllDefinedSymbols (Module *M, std::set<std::string> &DefinedSymbols);
 
 void
 GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols);
 
-char **
-CopyEnv (char ** const envp);
-
-void
-RemoveEnv (const char * name, char ** const envp);
-
 int
 GenerateBytecode (Module * M,
                   bool Strip,