llvm.org GIT mirror llvm / 51a1132
simplify output file selection, fixing two FIXMEs about binary output git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79808 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 22 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
109109 Passes.add(createDeadTypeEliminationPass()); // Remove dead types...
110110 Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
111111
112 raw_ostream *Out = 0;
113
114 if (OutputFilename != "-") { // Not stdout?
115 std::string ErrorInfo;
116 Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
117 raw_fd_ostream::F_Binary |
118 (Force ? raw_fd_ostream::F_Force : 0));
119 if (!ErrorInfo.empty()) {
120 errs() << ErrorInfo << '\n';
121 if (!Force)
122 errs() << "Use -f command line argument to force output\n";
123 delete Out;
124 return 1;
125 }
126 } else { // Specified stdout
127 // FIXME: outs() is not binary!
128 Out = &outs();
112 std::string ErrorInfo;
113 std::auto_ptr
114 Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
115 raw_fd_ostream::F_Binary |
116 (Force ? raw_fd_ostream::F_Force : 0)));
117 if (!ErrorInfo.empty()) {
118 errs() << ErrorInfo << '\n';
119 if (!Force)
120 errs() << "Use -f command line argument to force output\n";
121 return 1;
129122 }
130123
131124 Passes.add(createBitcodeWriterPass(*Out));
132125 Passes.run(*M.get());
133126
134 if (Out != &outs())
135 delete Out;
136127 return 0;
137128 }
117117
118118 if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite.get();
119119
120 // FIXME: outs() is not binary!
121 raw_ostream *Out = &outs(); // Default to printing to stdout...
122 if (OutputFilename != "-") {
123 std::string ErrorInfo;
124 Out = new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
125 raw_fd_ostream::F_Binary |
126 (Force ? raw_fd_ostream::F_Force : 0));
127 if (!ErrorInfo.empty()) {
128 errs() << ErrorInfo << '\n';
129 if (!Force)
130 errs() << "Use -f command line argument to force output\n";
131 delete Out;
132 return 1;
133 }
120 std::string ErrorInfo;
121 std::auto_ptr
122 Out(new raw_fd_ostream(OutputFilename.c_str(), ErrorInfo,
123 raw_fd_ostream::F_Binary |
124 (Force ? raw_fd_ostream::F_Force : 0)));
125 if (!ErrorInfo.empty()) {
126 errs() << ErrorInfo << '\n';
127 if (!Force)
128 errs() << "Use -f command line argument to force output\n";
129 return 1;
130 }
134131
135132 // Make sure that the Out file gets unlinked from the disk if we get a
136133 // SIGINT
134 if (OutputFilename != "-")
137135 sys::RemoveFileOnSignal(sys::Path(OutputFilename));
138 }
139136
140137 if (verifyModule(*Composite.get())) {
141138 errs() << argv[0] << ": linked module is broken!\n";
145142 if (Verbose) errs() << "Writing bitcode...\n";
146143 WriteBitcodeToFile(Composite.get(), *Out);
147144
148 if (Out != &outs()) delete Out;
149145 return 0;
150146 }