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
This commit is contained in:
Bill Wendling 2007-02-08 01:41:07 +00:00
parent eb1ac33850
commit 546d0fbd97
2 changed files with 51 additions and 3 deletions

View File

@ -14,6 +14,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Bytecode/Reader.h"
#include "llvm/CodeGen/FileWriters.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetData.h"
@ -248,7 +249,30 @@ int main(int argc, char **argv) {
#endif
// Ask the target to add backend passes as necessary.
if (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
MachineCodeEmitter *MCE = 0;
switch (Target.addPassesToEmitFile(Passes, *Out, FileType, Fast)) {
default:
assert(0 && "Invalid file model!");
return 1;
case FileModel::Error:
std::cerr << argv[0] << ": target does not support generation of this"
<< " file type!\n";
if (Out != &std::cout) delete Out;
// And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk();
return 1;
case FileModel::AsmFile:
break;
case FileModel::MachOFile:
MCE = AddMachOWriter(Passes, *Out, Target);
break;
case FileModel::ElfFile:
MCE = AddELFWriter(Passes, *Out, Target);
break;
}
if (Target.addPassesToEmitFileFinish(Passes, MCE, Fast)) {
std::cerr << argv[0] << ": target does not support generation of this"
<< " file type!\n";
if (Out != &std::cout) delete Out;

View File

@ -27,6 +27,7 @@
#include "llvm/System/Signals.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/CodeGen/FileWriters.h"
#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h"
@ -308,8 +309,31 @@ LTO::optimize(Module *M, std::ostream &Out,
new FunctionPassManager(new ExistingModuleProvider(M));
CodeGenPasses->add(new TargetData(*Target->getTargetData()));
Target->addPassesToEmitFile(*CodeGenPasses, Out, TargetMachine::AssemblyFile,
true);
MachineCodeEmitter *MCE = 0;
switch (Target->addPassesToEmitFile(*CodeGenPasses, Out,
TargetMachine::AssemblyFile, true)) {
default:
assert(0 && "Invalid file model!");
return LTO_UNKNOWN;
case FileModel::Error:
// FIXME: Error...
return LTO_UNKNOWN;
case FileModel::AsmFile:
break;
case FileModel::MachOFile:
MCE = AddMachOWriter(*CodeGenPasses, Out, *Target);
break;
case FileModel::ElfFile:
MCE = AddELFWriter(*CodeGenPasses, Out, *Target);
break;
}
if (Target->addPassesToEmitFileFinish(*CodeGenPasses, MCE, true)) {
// FIXME: Error...
return LTO_UNKNOWN;
}
// Run our queue of passes all at once now, efficiently.
Passes.run(*M);