Pull bytecode writing out of Module writer pass. Prepare to move to seperate file

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2001-10-18 20:05:07 +00:00
parent c148d4e073
commit 3923140a4d

View File

@ -17,19 +17,14 @@ class PrintModulePass : public Pass {
ostream *Out; // ostream to print on ostream *Out; // ostream to print on
bool DeleteStream; // Delete the ostream in our dtor? bool DeleteStream; // Delete the ostream in our dtor?
bool PrintPerMethod; // Print one method at a time rather than the whole? bool PrintPerMethod; // Print one method at a time rather than the whole?
bool PrintAsBytecode; // Print as bytecode rather than assembly?
public: public:
inline PrintModulePass(const string &B, ostream *o = &cout, inline PrintModulePass(const string &B, ostream *o = &cout,
bool DS = false, bool DS = false,
bool printPerMethod = true, bool printPerMethod = true)
bool printAsBytecode = false) : Banner(B), Out(o), DeleteStream(DS), PrintPerMethod(printPerMethod) {
: Banner(B), Out(o), DeleteStream(DS),
PrintPerMethod(printPerMethod), PrintAsBytecode(printAsBytecode) {
if (PrintAsBytecode)
PrintPerMethod = false;
} }
~PrintModulePass() { inline ~PrintModulePass() {
if (DeleteStream) delete Out; if (DeleteStream) delete Out;
} }
@ -45,13 +40,28 @@ public:
// doPassFinalization - Virtual method overriden by subclasses to do any post // doPassFinalization - Virtual method overriden by subclasses to do any post
// processing needed after all passes have run. // processing needed after all passes have run.
// //
bool doPassFinalization(Module *module) { bool doPassFinalization(Module *M) {
if (PrintAsBytecode) if (! PrintPerMethod)
WriteBytecodeToFile(module, *Out); (*Out) << Banner << M;
else if (! PrintPerMethod)
(*Out) << Banner << module;
return false; return false;
} }
}; };
class WriteModuleBytecode : public Pass {
ostream *Out; // ostream to print on
bool DeleteStream;
public:
inline WriteModuleBytecode(ostream *o = &cout, bool DS = false)
: Out(o), DeleteStream(DS) {
}
inline ~WriteModuleBytecode() {
if (DeleteStream) delete Out;
}
bool doPassFinalization(Module *M) {
WriteBytecodeToFile(M, *Out);
}
};
#endif #endif