Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1 | //===-- Writer.cpp - Library for Printing VM assembly files ------*- C++ -*--=// |
| 2 | // |
| 3 | // This library implements the functionality defined in llvm/Assembly/Writer.h |
| 4 | // |
| 5 | // This library uses the Analysis library to figure out offsets for |
| 6 | // variables in the method tables... |
| 7 | // |
| 8 | // TODO: print out the type name instead of the full type if a particular type |
| 9 | // is in the symbol table... |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/Assembly/Writer.h" |
| 14 | #include "llvm/Analysis/SlotCalculator.h" |
| 15 | #include "llvm/Module.h" |
| 16 | #include "llvm/Method.h" |
| 17 | #include "llvm/BasicBlock.h" |
| 18 | #include "llvm/ConstPoolVals.h" |
| 19 | #include "llvm/iOther.h" |
| 20 | #include "llvm/iMemory.h" |
| 21 | |
Chris Lattner | 2e9fee4 | 2001-07-12 23:35:26 +0000 | [diff] [blame] | 22 | void DebugValue(const Value *V) { |
| 23 | cerr << V << endl; |
| 24 | } |
| 25 | |
Chris Lattner | 5e5abe3 | 2001-07-20 19:15:21 +0000 | [diff] [blame] | 26 | // WriteAsOperand - Write the name of the specified value out to the specified |
| 27 | // ostream. This can be useful when you just want to print int %reg126, not the |
| 28 | // whole instruction that generated it. |
| 29 | // |
| 30 | ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType, |
| 31 | bool PrintName, SlotCalculator *Table) { |
| 32 | if (PrintType) |
| 33 | Out << " " << V->getType(); |
| 34 | |
| 35 | if (V->hasName() && PrintName) { |
| 36 | Out << " %" << V->getName(); |
| 37 | } else { |
| 38 | if (const ConstPoolVal *CPV = V->castConstant()) { |
| 39 | Out << " " << CPV->getStrValue(); |
| 40 | } else { |
| 41 | int Slot; |
| 42 | if (Table) { |
| 43 | Slot = Table->getValSlot(V); |
| 44 | } else { |
| 45 | if (const Type *Ty = V->castType()) { |
| 46 | return Out << " " << Ty; |
| 47 | } else if (const MethodArgument *MA = V->castMethodArgument()) { |
| 48 | Table = new SlotCalculator(MA->getParent(), true); |
| 49 | } else if (const Instruction *I = V->castInstruction()) { |
| 50 | Table = new SlotCalculator(I->getParent()->getParent(), true); |
| 51 | } else if (const BasicBlock *BB = V->castBasicBlock()) { |
| 52 | Table = new SlotCalculator(BB->getParent(), true); |
| 53 | } else if (const Method *Meth = V->castMethod()) { |
| 54 | Table = new SlotCalculator(Meth, true); |
| 55 | } else if (const Module *Mod = V->castModule()) { |
| 56 | Table = new SlotCalculator(Mod, true); |
| 57 | } else { |
| 58 | return Out << "BAD VALUE TYPE!"; |
| 59 | } |
| 60 | Slot = Table->getValSlot(V); |
| 61 | delete Table; |
| 62 | } |
| 63 | if (Slot >= 0) Out << " %" << Slot; |
| 64 | else if (PrintName) |
| 65 | Out << "<badref>"; // Not embeded into a location? |
| 66 | } |
| 67 | } |
| 68 | return Out; |
| 69 | } |
| 70 | |
| 71 | |
Chris Lattner | 2e9fee4 | 2001-07-12 23:35:26 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 73 | class AssemblyWriter : public ModuleAnalyzer { |
| 74 | ostream &Out; |
| 75 | SlotCalculator &Table; |
| 76 | public: |
| 77 | inline AssemblyWriter(ostream &o, SlotCalculator &Tab) : Out(o), Table(Tab) { |
| 78 | } |
| 79 | |
| 80 | inline void write(const Module *M) { processModule(M); } |
| 81 | inline void write(const Method *M) { processMethod(M); } |
| 82 | inline void write(const BasicBlock *BB) { processBasicBlock(BB); } |
| 83 | inline void write(const Instruction *I) { processInstruction(I); } |
| 84 | inline void write(const ConstPoolVal *CPV) { processConstant(CPV); } |
| 85 | |
| 86 | protected: |
| 87 | virtual bool visitMethod(const Method *M); |
| 88 | virtual bool processConstPool(const ConstantPool &CP, bool isMethod); |
| 89 | virtual bool processConstant(const ConstPoolVal *CPV); |
| 90 | virtual bool processMethod(const Method *M); |
| 91 | virtual bool processMethodArgument(const MethodArgument *MA); |
| 92 | virtual bool processBasicBlock(const BasicBlock *BB); |
| 93 | virtual bool processInstruction(const Instruction *I); |
| 94 | |
| 95 | private : |
| 96 | void writeOperand(const Value *Op, bool PrintType, bool PrintName = true); |
| 97 | }; |
| 98 | |
| 99 | |
| 100 | |
| 101 | // visitMethod - This member is called after the above two steps, visting each |
| 102 | // method, because they are effectively values that go into the constant pool. |
| 103 | // |
| 104 | bool AssemblyWriter::visitMethod(const Method *M) { |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | bool AssemblyWriter::processConstPool(const ConstantPool &CP, bool isMethod) { |
| 109 | // Done printing arguments... |
Chris Lattner | 90e0d46 | 2001-07-25 22:47:55 +0000 | [diff] [blame] | 110 | if (isMethod) { |
| 111 | if (CP.getParentV()->castMethodAsserting()->getType()-> |
| 112 | isMethodType()->isVarArg()) |
| 113 | Out << ", ..."; // Output varargs portion of signature! |
| 114 | Out << ")\n"; |
| 115 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 116 | |
| 117 | ModuleAnalyzer::processConstPool(CP, isMethod); |
| 118 | |
Chris Lattner | a7620d9 | 2001-07-15 06:35:59 +0000 | [diff] [blame] | 119 | if (isMethod) { |
| 120 | if (!CP.getParentV()->castMethodAsserting()->isExternal()) |
| 121 | Out << "begin"; |
| 122 | } else { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 123 | Out << "implementation\n"; |
Chris Lattner | a7620d9 | 2001-07-15 06:35:59 +0000 | [diff] [blame] | 124 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 125 | return false; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | // processConstant - Print out a constant pool entry... |
| 130 | // |
| 131 | bool AssemblyWriter::processConstant(const ConstPoolVal *CPV) { |
| 132 | Out << "\t"; |
| 133 | |
| 134 | // Print out name if it exists... |
| 135 | if (CPV->hasName()) |
| 136 | Out << "%" << CPV->getName() << " = "; |
| 137 | |
| 138 | // Print out the opcode... |
| 139 | Out << CPV->getType(); |
| 140 | |
| 141 | // Write the value out now... |
| 142 | writeOperand(CPV, false, false); |
| 143 | |
| 144 | if (!CPV->hasName() && CPV->getType() != Type::VoidTy) { |
| 145 | int Slot = Table.getValSlot(CPV); // Print out the def slot taken... |
| 146 | Out << "\t\t; <" << CPV->getType() << ">:"; |
| 147 | if (Slot >= 0) Out << Slot; |
| 148 | else Out << "<badref>"; |
| 149 | } |
| 150 | |
| 151 | Out << endl; |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | // processMethod - Process all aspects of a method. |
| 156 | // |
| 157 | bool AssemblyWriter::processMethod(const Method *M) { |
| 158 | // Print out the return type and name... |
Chris Lattner | a7620d9 | 2001-07-15 06:35:59 +0000 | [diff] [blame] | 159 | Out << "\n" << (M->isExternal() ? "declare " : "") |
| 160 | << M->getReturnType() << " \"" << M->getName() << "\"("; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 161 | Table.incorporateMethod(M); |
| 162 | ModuleAnalyzer::processMethod(M); |
| 163 | Table.purgeMethod(); |
Chris Lattner | a7620d9 | 2001-07-15 06:35:59 +0000 | [diff] [blame] | 164 | if (!M->isExternal()) |
| 165 | Out << "end\n"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | |
| 169 | // processMethodArgument - This member is called for every argument that |
| 170 | // is passed into the method. Simply print it out |
| 171 | // |
| 172 | bool AssemblyWriter::processMethodArgument(const MethodArgument *Arg) { |
| 173 | // Insert commas as we go... the first arg doesn't get a comma |
| 174 | if (Arg != Arg->getParent()->getArgumentList().front()) Out << ", "; |
| 175 | |
| 176 | // Output type... |
| 177 | Out << Arg->getType(); |
| 178 | |
| 179 | // Output name, if available... |
| 180 | if (Arg->hasName()) |
| 181 | Out << " %" << Arg->getName(); |
| 182 | else if (Table.getValSlot(Arg) < 0) |
| 183 | Out << "<badref>"; |
| 184 | |
| 185 | return false; |
| 186 | } |
| 187 | |
| 188 | // processBasicBlock - This member is called for each basic block in a methd. |
| 189 | // |
| 190 | bool AssemblyWriter::processBasicBlock(const BasicBlock *BB) { |
| 191 | if (BB->hasName()) { // Print out the label if it exists... |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 192 | Out << "\n" << BB->getName() << ":"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 193 | } else { |
| 194 | int Slot = Table.getValSlot(BB); |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 195 | Out << "\n; <label>:"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 196 | if (Slot >= 0) |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 197 | Out << Slot; // Extra newline seperates out label's |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 198 | else |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 199 | Out << "<badref>"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 200 | } |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 201 | Out << "\t\t\t\t\t;[#uses=" << BB->use_size() << "]\n"; // Output # uses |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 202 | |
| 203 | ModuleAnalyzer::processBasicBlock(BB); |
| 204 | return false; |
| 205 | } |
| 206 | |
| 207 | // processInstruction - This member is called for each Instruction in a methd. |
| 208 | // |
| 209 | bool AssemblyWriter::processInstruction(const Instruction *I) { |
| 210 | Out << "\t"; |
| 211 | |
| 212 | // Print out name if it exists... |
| 213 | if (I && I->hasName()) |
| 214 | Out << "%" << I->getName() << " = "; |
| 215 | |
| 216 | // Print out the opcode... |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 217 | Out << I->getOpcodeName(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 218 | |
| 219 | // Print out the type of the operands... |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 220 | const Value *Operand = I->getNumOperands() ? I->getOperand(0) : 0; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 221 | |
| 222 | // Special case conditional branches to swizzle the condition out to the front |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 223 | if (I->getOpcode() == Instruction::Br && I->getNumOperands() > 1) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 224 | writeOperand(I->getOperand(2), true); |
| 225 | Out << ","; |
| 226 | writeOperand(Operand, true); |
| 227 | Out << ","; |
| 228 | writeOperand(I->getOperand(1), true); |
| 229 | |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 230 | } else if (I->getOpcode() == Instruction::Switch) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 231 | // Special case switch statement to get formatting nice and correct... |
| 232 | writeOperand(Operand , true); Out << ","; |
| 233 | writeOperand(I->getOperand(1), true); Out << " ["; |
| 234 | |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 235 | for (unsigned op = 2, Eop = I->getNumOperands(); op < Eop; op += 2) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 236 | Out << "\n\t\t"; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 237 | writeOperand(I->getOperand(op ), true); Out << ","; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 238 | writeOperand(I->getOperand(op+1), true); |
| 239 | } |
| 240 | Out << "\n\t]"; |
Chris Lattner | 4cee8d8 | 2001-06-27 23:41:11 +0000 | [diff] [blame] | 241 | } else if (I->isPHINode()) { |
Chris Lattner | 931ef3b | 2001-06-11 15:04:20 +0000 | [diff] [blame] | 242 | Out << " " << Operand->getType(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 243 | |
Chris Lattner | 931ef3b | 2001-06-11 15:04:20 +0000 | [diff] [blame] | 244 | Out << " ["; writeOperand(Operand, false); Out << ","; |
Chris Lattner | 4b94e23 | 2001-06-21 05:29:56 +0000 | [diff] [blame] | 245 | writeOperand(I->getOperand(1), false); Out << " ]"; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 246 | for (unsigned op = 2, Eop = I->getNumOperands(); op < Eop; op += 2) { |
| 247 | Out << ", ["; |
| 248 | writeOperand(I->getOperand(op ), false); Out << ","; |
Chris Lattner | 4b94e23 | 2001-06-21 05:29:56 +0000 | [diff] [blame] | 249 | writeOperand(I->getOperand(op+1), false); Out << " ]"; |
Chris Lattner | 931ef3b | 2001-06-11 15:04:20 +0000 | [diff] [blame] | 250 | } |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 251 | } else if (I->getOpcode() == Instruction::Ret && !Operand) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 252 | Out << " void"; |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 253 | } else if (I->getOpcode() == Instruction::Call) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 254 | writeOperand(Operand, true); |
| 255 | Out << "("; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 256 | if (I->getNumOperands() > 1) writeOperand(I->getOperand(1), true); |
| 257 | for (unsigned op = 2, Eop = I->getNumOperands(); op < Eop; ++op) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 258 | Out << ","; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 259 | writeOperand(I->getOperand(op), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | Out << " )"; |
Chris Lattner | b1ca9cb | 2001-07-07 19:24:15 +0000 | [diff] [blame] | 263 | } else if (I->getOpcode() == Instruction::Malloc || |
| 264 | I->getOpcode() == Instruction::Alloca) { |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 265 | Out << " " << ((const PointerType*)I->getType())->getValueType(); |
| 266 | if (I->getNumOperands()) { |
| 267 | Out << ","; |
| 268 | writeOperand(I->getOperand(0), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 269 | } |
Chris Lattner | a682182 | 2001-07-08 04:57:15 +0000 | [diff] [blame] | 270 | } else if (I->getOpcode() == Instruction::Cast) { |
| 271 | writeOperand(Operand, true); |
| 272 | Out << " to " << I->getType(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 273 | } else if (Operand) { // Print the normal way... |
| 274 | |
| 275 | // PrintAllTypes - Instructions who have operands of all the same type |
| 276 | // omit the type from all but the first operand. If the instruction has |
| 277 | // different type operands (for example br), then they are all printed. |
| 278 | bool PrintAllTypes = false; |
| 279 | const Type *TheType = Operand->getType(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 280 | |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 281 | for (unsigned i = 1, E = I->getNumOperands(); i != E; ++i) { |
| 282 | Operand = I->getOperand(i); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 283 | if (Operand->getType() != TheType) { |
| 284 | PrintAllTypes = true; // We have differing types! Print them all! |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (!PrintAllTypes) |
| 290 | Out << " " << I->getOperand(0)->getType(); |
| 291 | |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 292 | for (unsigned i = 0, E = I->getNumOperands(); i != E; ++i) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 293 | if (i) Out << ","; |
Chris Lattner | a073acb | 2001-07-07 08:36:50 +0000 | [diff] [blame] | 294 | writeOperand(I->getOperand(i), PrintAllTypes); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
| 298 | // Print a little comment after the instruction indicating which slot it |
| 299 | // occupies. |
| 300 | // |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 301 | if (I->getType() != Type::VoidTy) { |
| 302 | Out << "\t\t; <" << I->getType() << ">"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 303 | |
Chris Lattner | a2f0187 | 2001-06-07 16:58:55 +0000 | [diff] [blame] | 304 | if (!I->hasName()) { |
| 305 | int Slot = Table.getValSlot(I); // Print out the def slot taken... |
| 306 | if (Slot >= 0) Out << ":" << Slot; |
| 307 | else Out << ":<badref>"; |
| 308 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 309 | Out << "\t[#uses=" << I->use_size() << "]"; // Output # uses |
| 310 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 311 | Out << endl; |
| 312 | |
| 313 | return false; |
| 314 | } |
| 315 | |
| 316 | |
| 317 | void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType, |
| 318 | bool PrintName) { |
Chris Lattner | 5e5abe3 | 2001-07-20 19:15:21 +0000 | [diff] [blame] | 319 | WriteAsOperand(Out, Operand, PrintType, PrintName, &Table); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
| 323 | //===----------------------------------------------------------------------===// |
| 324 | // External Interface declarations |
| 325 | //===----------------------------------------------------------------------===// |
| 326 | |
| 327 | |
| 328 | |
| 329 | void WriteToAssembly(const Module *M, ostream &o) { |
| 330 | if (M == 0) { o << "<null> module\n"; return; } |
| 331 | SlotCalculator SlotTable(M, true); |
| 332 | AssemblyWriter W(o, SlotTable); |
| 333 | |
| 334 | W.write(M); |
| 335 | } |
| 336 | |
| 337 | void WriteToAssembly(const Method *M, ostream &o) { |
| 338 | if (M == 0) { o << "<null> method\n"; return; } |
| 339 | SlotCalculator SlotTable(M->getParent(), true); |
| 340 | AssemblyWriter W(o, SlotTable); |
| 341 | |
| 342 | W.write(M); |
| 343 | } |
| 344 | |
| 345 | |
| 346 | void WriteToAssembly(const BasicBlock *BB, ostream &o) { |
| 347 | if (BB == 0) { o << "<null> basic block\n"; return; } |
| 348 | |
| 349 | SlotCalculator SlotTable(BB->getParent(), true); |
| 350 | AssemblyWriter W(o, SlotTable); |
| 351 | |
| 352 | W.write(BB); |
| 353 | } |
| 354 | |
| 355 | void WriteToAssembly(const ConstPoolVal *CPV, ostream &o) { |
| 356 | if (CPV == 0) { o << "<null> constant pool value\n"; return; } |
| 357 | |
| 358 | SlotCalculator *SlotTable; |
| 359 | |
| 360 | // A Constant pool value may have a parent that is either a method or a |
| 361 | // module. Untangle this now... |
| 362 | // |
Chris Lattner | 32e96bc | 2001-07-14 06:10:33 +0000 | [diff] [blame] | 363 | if (const Method *Meth = CPV->getParentV()->castMethod()) { |
| 364 | SlotTable = new SlotCalculator(Meth, true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 365 | } else { |
Chris Lattner | 4cee8d8 | 2001-06-27 23:41:11 +0000 | [diff] [blame] | 366 | SlotTable = |
Chris Lattner | 32e96bc | 2001-07-14 06:10:33 +0000 | [diff] [blame] | 367 | new SlotCalculator(CPV->getParentV()->castModuleAsserting(), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | AssemblyWriter W(o, *SlotTable); |
| 371 | W.write(CPV); |
| 372 | |
| 373 | delete SlotTable; |
| 374 | } |
| 375 | |
| 376 | void WriteToAssembly(const Instruction *I, ostream &o) { |
| 377 | if (I == 0) { o << "<null> instruction\n"; return; } |
| 378 | |
| 379 | SlotCalculator SlotTable(I->getParent() ? I->getParent()->getParent() : 0, |
| 380 | true); |
| 381 | AssemblyWriter W(o, SlotTable); |
| 382 | |
| 383 | W.write(I); |
| 384 | } |