summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-07-20 19:15:21 +0000
committerChris Lattner <sabre@nondot.org>2001-07-20 19:15:21 +0000
commit622f740a7dcf0b3520244e58b2233898fd4a46e4 (patch)
tree3df53a900347a9b73250c3edd6a2abd0f447c87a /lib
parent698b56e6901074cde0547b93f68a4d30f0be6eef (diff)
downloadexternal_llvm-622f740a7dcf0b3520244e58b2233898fd4a46e4.zip
external_llvm-622f740a7dcf0b3520244e58b2233898fd4a46e4.tar.gz
external_llvm-622f740a7dcf0b3520244e58b2233898fd4a46e4.tar.bz2
Factor out WriteAsOperand.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/AsmWriter.cpp63
1 files changed, 47 insertions, 16 deletions
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index e802544..1719bc5 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -23,6 +23,52 @@ void DebugValue(const Value *V) {
cerr << V << endl;
}
+// WriteAsOperand - Write the name of the specified value out to the specified
+// ostream. This can be useful when you just want to print int %reg126, not the
+// whole instruction that generated it.
+//
+ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType,
+ bool PrintName, SlotCalculator *Table) {
+ if (PrintType)
+ Out << " " << V->getType();
+
+ if (V->hasName() && PrintName) {
+ Out << " %" << V->getName();
+ } else {
+ if (const ConstPoolVal *CPV = V->castConstant()) {
+ Out << " " << CPV->getStrValue();
+ } else {
+ int Slot;
+ if (Table) {
+ Slot = Table->getValSlot(V);
+ } else {
+ if (const Type *Ty = V->castType()) {
+ return Out << " " << Ty;
+ } else if (const MethodArgument *MA = V->castMethodArgument()) {
+ Table = new SlotCalculator(MA->getParent(), true);
+ } else if (const Instruction *I = V->castInstruction()) {
+ Table = new SlotCalculator(I->getParent()->getParent(), true);
+ } else if (const BasicBlock *BB = V->castBasicBlock()) {
+ Table = new SlotCalculator(BB->getParent(), true);
+ } else if (const Method *Meth = V->castMethod()) {
+ Table = new SlotCalculator(Meth, true);
+ } else if (const Module *Mod = V->castModule()) {
+ Table = new SlotCalculator(Mod, true);
+ } else {
+ return Out << "BAD VALUE TYPE!";
+ }
+ Slot = Table->getValSlot(V);
+ delete Table;
+ }
+ if (Slot >= 0) Out << " %" << Slot;
+ else if (PrintName)
+ Out << "<badref>"; // Not embeded into a location?
+ }
+ }
+ return Out;
+}
+
+
class AssemblyWriter : public ModuleAnalyzer {
ostream &Out;
@@ -265,22 +311,7 @@ bool AssemblyWriter::processInstruction(const Instruction *I) {
void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType,
bool PrintName) {
- if (PrintType)
- Out << " " << Operand->getType();
-
- if (Operand->hasName() && PrintName) {
- Out << " %" << Operand->getName();
- } else {
- int Slot = Table.getValSlot(Operand);
-
- if (const ConstPoolVal *CPV = Operand->castConstant()) {
- Out << " " << CPV->getStrValue();
- } else {
- if (Slot >= 0) Out << " %" << Slot;
- else if (PrintName)
- Out << "<badref>"; // Not embeded into a location?
- }
- }
+ WriteAsOperand(Out, Operand, PrintType, PrintName, &Table);
}