llvm.org GIT mirror llvm / 546d0fb
The new version of how to add passes to emit files. We explicitly call a function to add the file writers between calls to add the passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34035 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 12 years ago
2 changed file(s) with 51 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1313 //===----------------------------------------------------------------------===//
1414
1515 #include "llvm/Bytecode/Reader.h"
16 #include "llvm/CodeGen/FileWriters.h"
1617 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
1718 #include "llvm/Target/SubtargetFeature.h"
1819 #include "llvm/Target/TargetData.h"
247248 #endif
248249
249250 // Ask the target to add backend passes as necessary.
250 if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
251 MachineCodeEmitter *MCE = 0;
252
253 switch (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
254 default:
255 assert(0 && "Invalid file model!");
256 return 1;
257 case FileModel::Error:
258 std::cerr << argv[0] << ": target does not support generation of this"
259 << " file type!\n";
260 if (Out != &std::cout) delete Out;
261 // And the Out file is empty and useless, so remove it now.
262 sys::Path(OutputFilename).eraseFromDisk();
263 return 1;
264 case FileModel::AsmFile:
265 break;
266 case FileModel::MachOFile:
267 MCE = AddMachOWriter(Passes, *Out, Target);
268 break;
269 case FileModel::ElfFile:
270 MCE = AddELFWriter(Passes, *Out, Target);
271 break;
272 }
273
274 if (Target.addPassesToEmitFileFinish(Passes, MCE, Fast)) {
251275 std::cerr << argv[0] << ": target does not support generation of this"
252276 << " file type!\n";
253277 if (Out != &std::cout) delete Out;
2626 #include "llvm/System/Signals.h"
2727 #include "llvm/Analysis/Passes.h"
2828 #include "llvm/Analysis/Verifier.h"
29 #include "llvm/CodeGen/FileWriters.h"
2930 #include "llvm/Target/SubtargetFeature.h"
3031 #include "llvm/Target/TargetData.h"
3132 #include "llvm/Target/TargetMachine.h"
307308 new FunctionPassManager(new ExistingModuleProvider(M));
308309
309310 CodeGenPasses->add(new TargetData(*Target->getTargetData()));
310 Target->addPassesToEmitFile(*CodeGenPasses, Out, TargetMachine::AssemblyFile,
311 true);
311
312 MachineCodeEmitter *MCE = 0;
313
314 switch (Target->addPassesToEmitFile(*CodeGenPasses, Out,
315 TargetMachine::AssemblyFile, true)) {
316 default:
317 assert(0 && "Invalid file model!");
318 return LTO_UNKNOWN;
319 case FileModel::Error:
320 // FIXME: Error...
321 return LTO_UNKNOWN;
322 case FileModel::AsmFile:
323 break;
324 case FileModel::MachOFile:
325 MCE = AddMachOWriter(*CodeGenPasses, Out, *Target);
326 break;
327 case FileModel::ElfFile:
328 MCE = AddELFWriter(*CodeGenPasses, Out, *Target);
329 break;
330 }
331
332 if (Target->addPassesToEmitFileFinish(*CodeGenPasses, MCE, true)) {
333 // FIXME: Error...
334 return LTO_UNKNOWN;
335 }
312336
313337 // Run our queue of passes all at once now, efficiently.
314338 Passes.run(*M);