Simplify some getNode calls.
[oota-llvm.git] / tools / llvm-ld / llvm-ld.cpp
index f15281dffdc21d616ba82ce607bc34a89681390f..40265628ac007335acb51ced15aab6e10d65a3d4 100644 (file)
@@ -403,11 +403,7 @@ static void EmitShellScript(char **argv) {
   if (llvmstub.isEmpty())
     PrintAndExit("Could not find llvm-stub.exe executable!");
 
-  sys::Path OutPath(OutputFilename);
-  if (OutPath.getSuffix() != "exe")
-    OutPath.appendSuffix("exe");
-
-  if (0 != sys::CopyFile(OutPath, llvmstub, &ErrMsg))
+  if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg))
     PrintAndExit(ErrMsg);
 
   return;
@@ -534,14 +530,24 @@ int main(int argc, char **argv, char **envp) {
     // Optimize the module
     Optimize(Composite.get());
 
-    // Generate the bitcode for the optimized module.
-    std::string RealBitcodeOutput = OutputFilename;
-
 #if defined(_WIN32) || defined(__CYGWIN__)
-    if (!LinkAsLibrary && sys::Path(OutputFilename).getSuffix() != "exe")
-      RealBitcodeOutput += ".exe";
+    if (!LinkAsLibrary) {
+      // Default to "a.exe" instead of "a.out".
+      if (OutputFilename.getNumOccurrences() == 0)
+        OutputFilename = "a.exe";
+
+      // If there is no suffix add an "exe" one.
+      sys::Path ExeFile( OutputFilename );
+      if (ExeFile.getSuffix() == "") {
+        ExeFile.appendSuffix("exe");
+        OutputFilename = ExeFile.toString();
+      }
+    }
 #endif
 
+    // Generate the bitcode for the optimized module.
+    std::string RealBitcodeOutput = OutputFilename;
+
     if (!LinkAsLibrary) RealBitcodeOutput += ".bc";
     GenerateBitcode(Composite.get(), RealBitcodeOutput);