1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

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.

llvm-svn: 34035
This commit is contained in:
Bill Wendling 2007-02-08 01:41:07 +00:00
parent 289ab30051
commit 9345a73364
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);