- // If the user wants to generate a native executable, compile it from the
- // bitcode file.
- //
- // Otherwise, create a script that will run the bitcode through the JIT.
- if (Native) {
- // Name of the Assembly Language output file
- sys::Path AssemblyFile ( OutputFilename);
- AssemblyFile.appendSuffix("s");
-
- // Mark the output files for removal if we get an interrupt.
- sys::RemoveFileOnSignal(AssemblyFile);
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
- // Determine the locations of the llc and gcc programs.
- sys::Path llc = FindExecutable("llc", argv[0]);
- if (llc.isEmpty())
- PrintAndExit("Failed to find llc");
-
- sys::Path gcc = FindExecutable("gcc", argv[0]);
- if (gcc.isEmpty())
- PrintAndExit("Failed to find gcc");
-
- // Generate an assembly language file for the bitcode.
- std::string ErrMsg;
- if (0 != GenerateAssembly(AssemblyFile.toString(), RealBitcodeOutput,
- llc, ErrMsg))
- PrintAndExit(ErrMsg);
-
- if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
- NativeLinkItems, gcc, envp, ErrMsg))
- PrintAndExit(ErrMsg);
-
- // Remove the assembly language file.
- AssemblyFile.eraseFromDisk();
- } else if (NativeCBE) {
- sys::Path CFile (OutputFilename);
- CFile.appendSuffix("cbe.c");
-
- // Mark the output files for removal if we get an interrupt.
- sys::RemoveFileOnSignal(CFile);
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
- // Determine the locations of the llc and gcc programs.
- sys::Path llc = FindExecutable("llc", argv[0]);
- if (llc.isEmpty())
- PrintAndExit("Failed to find llc");
-
- sys::Path gcc = FindExecutable("gcc", argv[0]);
- if (gcc.isEmpty())
- PrintAndExit("Failed to find gcc");
-
- // Generate an assembly language file for the bitcode.
- std::string ErrMsg;
- if (0 != GenerateCFile(
- CFile.toString(), RealBitcodeOutput, llc, ErrMsg))
- PrintAndExit(ErrMsg);
+ // Arrange for the bitcode output file to be deleted on any errors.
+ BitcodeOutputRemover.setFile(BitcodeOutputFilename);
+ sys::RemoveFileOnSignal(sys::Path(BitcodeOutputFilename));
+
+ // Arrange for the output file to be deleted on any errors.
+ if (!LinkAsLibrary) {
+ OutputRemover.setFile(OutputFilename);
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ }
+
+ // Construct a Linker (now that Verbose is set)
+ Linker TheLinker(progname, OutputFilename, Context, Verbose);
+
+ // Keep track of the native link items (versus the bitcode items)
+ Linker::ItemList NativeLinkItems;