// We will use GCC to assemble the program so set the assembly syntax to AT&T,
// regardless of what the target in the bitcode file is.
args.push_back("-x86-asm-syntax=att");
- args.push_back("-f");
args.push_back("-o");
args.push_back(OutputFilename.c_str());
args.push_back(InputFilename.c_str());
std::vector<const char*> args;
args.push_back(llc.c_str());
args.push_back("-march=c");
- args.push_back("-f");
args.push_back("-o");
args.push_back(OutputFile.c_str());
args.push_back(InputFile.c_str());
// Run the compiler to assembly and link together the program.
int R = sys::Program::ExecuteAndWait(
- gcc, &Args[0], (const char**)clean_env, 0, 0, 0, &ErrMsg);
+ gcc, &Args[0], const_cast<const char **>(clean_env), 0, 0, 0, &ErrMsg);
delete [] clean_env;
return R;
}
// Parse the command line options
cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
+#if defined(_WIN32) || defined(__CYGWIN__)
+ 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.str();
+ }
+ }
+#endif
+
+ // Generate the bitcode for the optimized module.
+ // If -b wasn't specified, use the name specified
+ // with -o to construct BitcodeOutputFilename.
+ if (BitcodeOutputFilename.empty()) {
+ BitcodeOutputFilename = OutputFilename;
+ if (!LinkAsLibrary) BitcodeOutputFilename += ".bc";
+ }
+
+ // Arrange for the bitcode output file to be deleted on any errors.
+ BitcodeOutputRemover.setFile(sys::Path(BitcodeOutputFilename));
+ sys::RemoveFileOnSignal(sys::Path(BitcodeOutputFilename));
+
+ // Arrange for the output file to be deleted on any errors.
+ if (!LinkAsLibrary) {
+ OutputRemover.setFile(sys::Path(OutputFilename));
+ sys::RemoveFileOnSignal(sys::Path(OutputFilename));
+ }
+
// Construct a Linker (now that Verbose is set)
Linker TheLinker(progname, OutputFilename, Context, Verbose);
// Optimize the module
Optimize(Composite.get());
-#if defined(_WIN32) || defined(__CYGWIN__)
- 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.str();
- }
- }
-#endif
-
- // Generate the bitcode for the optimized module.
- // If -b wasn't specified, use the name specified
- // with -o to construct BitcodeOutputFilename.
- if (BitcodeOutputFilename.empty()) {
- BitcodeOutputFilename = OutputFilename;
- if (!LinkAsLibrary) BitcodeOutputFilename += ".bc";
- }
-
- // Arrange for the bitcode output file to be deleted on any errors.
- BitcodeOutputRemover = FileRemover(sys::Path(BitcodeOutputFilename));
- sys::RemoveFileOnSignal(sys::Path(BitcodeOutputFilename));
-
// Generate the bitcode output.
GenerateBitcode(Composite.get(), BitcodeOutputFilename);
- // Arrange for the output file to be deleted on any errors.
- OutputRemover = FileRemover(sys::Path(OutputFilename));
- sys::RemoveFileOnSignal(sys::Path(OutputFilename));
-
// If we are not linking a library, generate either a native executable
// or a JIT shell script, depending upon what the user wants.
if (!LinkAsLibrary) {
sys::Path AssemblyFile ( OutputFilename);
AssemblyFile.appendSuffix("s");
- // Mark the output files for removal if we get an interrupt.
+ // Mark the output files for removal.
+ FileRemover AssemblyFileRemover(AssemblyFile);
sys::RemoveFileOnSignal(AssemblyFile);
// Determine the locations of the llc and gcc programs.
if (0 != GenerateNative(OutputFilename, AssemblyFile.str(),
NativeLinkItems, gcc, envp, ErrMsg))
PrintAndExit(ErrMsg, Composite.get());
-
- // 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.
+ // Mark the output files for removal.
+ FileRemover CFileRemover(CFile);
sys::RemoveFileOnSignal(CFile);
// Determine the locations of the llc and gcc programs.
if (GenerateNative(OutputFilename, CFile.str(),
NativeLinkItems, gcc, envp, ErrMsg))
PrintAndExit(ErrMsg, Composite.get());
-
- // Remove the assembly language file.
- CFile.eraseFromDisk();
-
} else {
EmitShellScript(argv, Composite.get());
}
}
// Operations which may fail are now complete.
- OutputRemover.releaseFile();
BitcodeOutputRemover.releaseFile();
+ if (!LinkAsLibrary)
+ OutputRemover.releaseFile();
// Graceful exit
return 0;