From: Chris Lattner Date: Wed, 7 Nov 2001 04:21:57 +0000 (+0000) Subject: Implement CachedWriter class to allow module level printing of various components... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=da1fbcc5c389e86840f6131afc22b45ce7e9ad08;p=oota-llvm.git Implement CachedWriter class to allow module level printing of various components very quickly git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1168 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index dda9f7390e8..e22d97d7ce7 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Assembly/Writer.h" +#include "llvm/Assembly/CachedWriter.h" #include "llvm/Analysis/SlotCalculator.h" #include "llvm/Module.h" #include "llvm/Method.h" @@ -275,6 +275,7 @@ public: inline void write(const BasicBlock *BB) { printBasicBlock(BB); } inline void write(const Instruction *I) { printInstruction(I); } inline void write(const ConstPoolVal *CPV) { printConstant(CPV); } + inline void write(const Type *Ty) { printType(Ty); } private : void printModule(const Module *M); @@ -676,3 +677,37 @@ void WriteToAssembly(const Instruction *I, ostream &o) { W.write(I); } + +void CachedWriter::setModule(const Module *M) { + delete SC; delete AW; + if (M) { + SC = new SlotCalculator(M, true); + AW = new AssemblyWriter(Out, *SC, M); + } else { + SC = 0; AW = 0; + } +} + +CachedWriter::~CachedWriter() { + delete AW; + delete SC; +} + +CachedWriter &CachedWriter::operator<<(const Value *V) { + assert(AW && SC && "CachedWriter does not have a current module!"); + switch (V->getValueType()) { + case Value::ConstantVal: + Out << " "; AW->write(V->getType()); + Out << " " << cast(V)->getStrValue(); break; + case Value::MethodArgumentVal: + AW->write(V->getType()); Out << " " << V->getName(); break; + case Value::TypeVal: AW->write(cast(V)); break; + case Value::InstructionVal: AW->write(cast(V)); break; + case Value::BasicBlockVal: AW->write(cast(V)); break; + case Value::MethodVal: AW->write(cast(V)); break; + case Value::GlobalVariableVal: AW->write(cast(V)); break; + case Value::ModuleVal: AW->write(cast(V)); break; + default: Out << "getValueType() << ">"; break; + } + return *this; +}