Add a generic expansion transform: A op (B op' C) -> (A op B) op' (A op C)
[oota-llvm.git] / tools / llvm-stub / llvm-stub.c
index 809a53227788081e97de1e94c66e69522d73c13f..31c2d09c6b7eb8f20b08d40ef7b6a3ff5094d37e 100644 (file)
@@ -1,10 +1,10 @@
-/*===- llvm-stub.c - Stub executable to run llvm bitcode files -----------===//
-// 
+/*===- llvm-stub.c - Stub executable to run llvm bitcode files ------------===//
+//
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
 //===----------------------------------------------------------------------===//
 //
 // This tool is used by the gccld program to enable transparent execution of
@@ -45,22 +45,30 @@ int main(int argc, char** argv) {
   /* argv[0] is the JIT */
   Args[0] = Interp;
 
-#ifdef __CYGWIN32__
-  /* Cygwin strips the .exe suffix off of argv[0] to "help" us.  Put it back 
-   * on.
-   */
-  argv[0] = strcat(strcpy((char*)malloc(strlen(argv[0])+5), argv[0]), ".exe");
+#ifdef LLVM_ON_WIN32
+  {
+    int len = strlen(argv[0]);
+    if (len < 4 || strcmp(argv[0] + len - 4, ".exe") != 0) {
+      /* .exe suffix is stripped off of argv[0] if the executable was run on the
+       * command line without one. Put it back on.
+       */
+      argv[0] = strcat(strcpy((char*)malloc(len + 5), argv[0]), ".exe");
+    }
+  }
 #endif
 
   /* argv[1] is argv[0] + ".bc". */
   Args[1] = strcat(strcpy((char*)malloc(strlen(argv[0])+4), argv[0]), ".bc");
 
   /* The rest of the args are as before. */
-  memcpy(Args+2, argv+1, sizeof(char*)*argc);
+  memcpy((char **)Args+2, argv+1, sizeof(char*)*argc);
 
   /* Run the JIT. */
-  execvp(Interp, (char *const*)Args);
-
+#ifndef _WIN32
+  execvp(Interp, (char **)Args); /* POSIX execvp takes a char *const[]. */
+#else
+  execvp(Interp, Args); /* windows execvp takes a const char *const *. */
+#endif
   /* if _execv returns, the JIT could not be started. */
   fprintf(stderr, "Could not execute the LLVM JIT.  Either add 'lli' to your"
           " path, or set the\ninterpreter you want to use in the LLVMINTERP "