-int main(int argc, char **argv) {
- llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
- cl::ParseCommandLineOptions(argc, argv, " llvm .ll -> .bc assembler\n");
- sys::PrintStackTraceOnErrorSignal();
-
- int exitCode = 0;
- std::ostream *Out = 0;
- try {
- // Parse the file now...
- ParseError Err;
- std::auto_ptr<Module> M(ParseAssemblyFile(InputFilename,&Err));
- if (M.get() == 0) {
- llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n";
- return 1;
- }
-
- if (!DisableVerify) {
- std::string Err;
- if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
- llvm_cerr << argv[0]
- << ": assembly parsed, but does not verify as correct!\n";
- llvm_cerr << Err;
- return 1;
- }
- }
-
- if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *M.get();
-
- if (OutputFilename != "") { // Specified an output filename?
- if (OutputFilename != "-") { // Not stdout?
- if (!Force && std::ifstream(OutputFilename.c_str())) {
- // If force is not specified, make sure not to overwrite a file!
- llvm_cerr << argv[0] << ": error opening '" << OutputFilename
- << "': file exists!\n"
- << "Use -f command line argument to force output\n";
- return 1;
- }
- Out = new std::ofstream(OutputFilename.c_str(), std::ios::out |
- std::ios::trunc | std::ios::binary);
- } else { // Specified stdout
- // FIXME: cout is not binary!
- Out = &std::cout;
- }
+static void WriteOutputFile(const Module *M) {
+ // Infer the output filename if needed.
+ if (OutputFilename.empty()) {
+ if (InputFilename == "-") {
+ OutputFilename = "-";