aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/VMCore/AsmWriter.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index dda9f7390e..e22d97d7ce 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<ConstPoolVal>(V)->getStrValue(); break;
+ case Value::MethodArgumentVal:
+ AW->write(V->getType()); Out << " " << V->getName(); break;
+ case Value::TypeVal: AW->write(cast<const Type>(V)); break;
+ case Value::InstructionVal: AW->write(cast<Instruction>(V)); break;
+ case Value::BasicBlockVal: AW->write(cast<BasicBlock>(V)); break;
+ case Value::MethodVal: AW->write(cast<Method>(V)); break;
+ case Value::GlobalVariableVal: AW->write(cast<GlobalVariable>(V)); break;
+ case Value::ModuleVal: AW->write(cast<Module>(V)); break;
+ default: Out << "<unknown value type: " << V->getValueType() << ">"; break;
+ }
+ return *this;
+}