aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-11-07 04:21:57 +0000
committerChris Lattner <sabre@nondot.org>2001-11-07 04:21:57 +0000
commitda1fbcc5c389e86840f6131afc22b45ce7e9ad08 (patch)
tree395437557d521c83fbfac62928567e4352f679f5
parent495d6f1933e6c680af4ea8f69ac12a7fdaee3aa0 (diff)
downloadexternal_llvm-da1fbcc5c389e86840f6131afc22b45ce7e9ad08.zip
external_llvm-da1fbcc5c389e86840f6131afc22b45ce7e9ad08.tar.gz
external_llvm-da1fbcc5c389e86840f6131afc22b45ce7e9ad08.tar.bz2
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
-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 dda9f73..e22d97d 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;
+}