comparison gen/toobj.cpp @ 694:931333ea35c6

Allow output of only bc, ll, or s by making -of set the output type depending on the extension.
author Christian Kamm <kamm incasoftware de>
date Mon, 13 Oct 2008 10:58:00 +0200
parents 06c05906b054
children ed9a9e6dd1cc
comparison
equal deleted inserted replaced
693:3112d269dd95 694:931333ea35c6
209 std::ofstream aos(llpath.c_str()); 209 std::ofstream aos(llpath.c_str());
210 ir.module->print(aos, NULL); 210 ir.module->print(aos, NULL);
211 } 211 }
212 212
213 // write native assembly 213 // write native assembly
214 LLPath spath = LLPath(objfile->name->toChars()); 214 if (global.params.output_s || global.params.output_o) {
215 spath.eraseSuffix(); 215 LLPath spath = LLPath(objfile->name->toChars());
216 spath.appendSuffix(std::string(global.s_ext)); 216 spath.eraseSuffix();
217 if (!global.params.output_s) { 217 spath.appendSuffix(std::string(global.s_ext));
218 spath.createTemporaryFileOnDisk(); 218 if (!global.params.output_s) {
219 } 219 spath.createTemporaryFileOnDisk();
220 Logger::println("Writing native asm to: %s\n", spath.c_str()); 220 }
221 std::string err; 221 Logger::println("Writing native asm to: %s\n", spath.c_str());
222 { 222 std::string err;
223 llvm::raw_fd_ostream out(spath.c_str(), err); 223 {
224 write_asm_to_file(*ir.module, out); 224 llvm::raw_fd_ostream out(spath.c_str(), err);
225 } 225 write_asm_to_file(*ir.module, out);
226 226 }
227 // call gcc to convert assembly to object file 227
228 LLPath objpath = LLPath(objfile->name->toChars()); 228 // call gcc to convert assembly to object file
229 assemble(spath, objpath, envp); 229 if (global.params.output_o) {
230 230 LLPath objpath = LLPath(objfile->name->toChars());
231 if (!global.params.output_s) { 231 objpath.eraseSuffix();
232 spath.eraseFromDisk(); 232 objpath.appendSuffix(std::string(global.obj_ext));
233 assemble(spath, objpath, envp);
234 }
235
236 if (!global.params.output_s) {
237 spath.eraseFromDisk();
238 }
233 } 239 }
234 240
235 delete ir.module; 241 delete ir.module;
236 gTargetData = 0; 242 gTargetData = 0;
237 gIR = NULL; 243 gIR = NULL;