Chris Lattner | f7e7948 | 2002-04-07 22:31:46 +0000 | [diff] [blame] | 1 | //===-- AsmWriter.cpp - Printing LLVM as an assembly file -----------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
| 10 | // This library implements the functionality defined in llvm/Assembly/Writer.h |
| 11 | // |
Chris Lattner | 189088e | 2002-04-12 18:21:53 +0000 | [diff] [blame] | 12 | // Note that these routines must be extremely tolerant of various errors in the |
Chris Lattner | f70da10 | 2003-05-08 02:44:12 +0000 | [diff] [blame] | 13 | // LLVM code, because it can be used for debugging transformations. |
Chris Lattner | 189088e | 2002-04-12 18:21:53 +0000 | [diff] [blame] | 14 | // |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chris Lattner | c0b4c7b | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 17 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | 7f8845a | 2002-07-23 18:07:49 +0000 | [diff] [blame] | 18 | #include "llvm/Assembly/PrintModulePass.h" |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 19 | #include "llvm/Assembly/AsmAnnotationWriter.h" |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 20 | #include "llvm/CallingConv.h" |
Chris Lattner | c70b3f6 | 2004-01-20 19:50:34 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Chris Lattner | 913d18f | 2002-04-29 18:46:50 +0000 | [diff] [blame] | 22 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 8bbcda2 | 2006-01-25 18:57:27 +0000 | [diff] [blame] | 23 | #include "llvm/InlineAsm.h" |
Vikram S. Adve | b952b54 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 24 | #include "llvm/Instruction.h" |
Misha Brukman | 2d3fa9e | 2004-07-29 16:53:53 +0000 | [diff] [blame] | 25 | #include "llvm/Instructions.h" |
Chris Lattner | c70b3f6 | 2004-01-20 19:50:34 +0000 | [diff] [blame] | 26 | #include "llvm/Module.h" |
Reid Spencer | 3aaaa0b | 2007-02-05 20:47:22 +0000 | [diff] [blame] | 27 | #include "llvm/ValueSymbolTable.h" |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 28 | #include "llvm/TypeSymbolTable.h" |
Chris Lattner | a204d41 | 2008-08-17 17:25:25 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/DenseMap.h" |
Reid Spencer | 7c16caa | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
| 31 | #include "llvm/ADT/STLExtras.h" |
Bill Wendling | dfc9189 | 2006-11-28 02:09:03 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CFG.h" |
Jim Laskey | b74c666 | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 33 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 34 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 35 | #include <algorithm> |
Reid Spencer | bdf03b4 | 2007-05-22 19:27:35 +0000 | [diff] [blame] | 36 | #include <cctype> |
Chris Lattner | 189d19f | 2003-11-21 20:23:48 +0000 | [diff] [blame] | 37 | using namespace llvm; |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 38 | |
Reid Spencer | 294715b | 2005-05-15 16:13:11 +0000 | [diff] [blame] | 39 | // Make virtual table appear in this compilation unit. |
| 40 | AssemblyAnnotationWriter::~AssemblyAnnotationWriter() {} |
| 41 | |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 42 | //===----------------------------------------------------------------------===// |
| 43 | // Helper Functions |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | |
| 46 | static const Module *getModuleFromVal(const Value *V) { |
| 47 | if (const Argument *MA = dyn_cast<Argument>(V)) |
| 48 | return MA->getParent() ? MA->getParent()->getParent() : 0; |
| 49 | |
| 50 | if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) |
| 51 | return BB->getParent() ? BB->getParent()->getParent() : 0; |
| 52 | |
| 53 | if (const Instruction *I = dyn_cast<Instruction>(V)) { |
| 54 | const Function *M = I->getParent() ? I->getParent()->getParent() : 0; |
| 55 | return M ? M->getParent() : 0; |
| 56 | } |
| 57 | |
| 58 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) |
| 59 | return GV->getParent(); |
| 60 | return 0; |
| 61 | } |
| 62 | |
Daniel Dunbar | db0b70a | 2008-10-28 19:33:02 +0000 | [diff] [blame] | 63 | // PrintEscapedString - Print each character of the specified string, escaping |
| 64 | // it if it is not printable or if it is an escape char. |
| 65 | static void PrintEscapedString(const char *Str, unsigned Length, |
| 66 | raw_ostream &Out) { |
| 67 | for (unsigned i = 0; i != Length; ++i) { |
| 68 | unsigned char C = Str[i]; |
| 69 | if (isprint(C) && C != '\\' && C != '"' && isprint(C)) |
| 70 | Out << C; |
| 71 | else |
| 72 | Out << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // PrintEscapedString - Print each character of the specified string, escaping |
| 77 | // it if it is not printable or if it is an escape char. |
| 78 | static void PrintEscapedString(const std::string &Str, raw_ostream &Out) { |
| 79 | PrintEscapedString(Str.c_str(), Str.size(), Out); |
| 80 | } |
| 81 | |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 82 | enum PrefixType { |
| 83 | GlobalPrefix, |
| 84 | LabelPrefix, |
Daniel Dunbar | 389529a | 2008-10-14 23:28:09 +0000 | [diff] [blame] | 85 | LocalPrefix, |
| 86 | NoPrefix |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either |
| 90 | /// prefixed with % (if the string only contains simple characters) or is |
| 91 | /// surrounded with ""'s (if it has special chars in it). Print it out. |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 92 | static void PrintLLVMName(raw_ostream &OS, const char *NameStr, |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 93 | unsigned NameLen, PrefixType Prefix) { |
| 94 | assert(NameStr && "Cannot get empty name!"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 95 | switch (Prefix) { |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 96 | default: assert(0 && "Bad prefix!"); |
Daniel Dunbar | 389529a | 2008-10-14 23:28:09 +0000 | [diff] [blame] | 97 | case NoPrefix: break; |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 98 | case GlobalPrefix: OS << '@'; break; |
| 99 | case LabelPrefix: break; |
| 100 | case LocalPrefix: OS << '%'; break; |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | // Scan the name to see if it needs quotes first. |
Daniel Dunbar | db0b70a | 2008-10-28 19:33:02 +0000 | [diff] [blame] | 104 | bool NeedsQuotes = isdigit(NameStr[0]); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 105 | if (!NeedsQuotes) { |
| 106 | for (unsigned i = 0; i != NameLen; ++i) { |
| 107 | char C = NameStr[i]; |
| 108 | if (!isalnum(C) && C != '-' && C != '.' && C != '_') { |
| 109 | NeedsQuotes = true; |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // If we didn't need any quotes, just write out the name in one blast. |
| 116 | if (!NeedsQuotes) { |
| 117 | OS.write(NameStr, NameLen); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | // Okay, we need quotes. Output the quotes and escape any scary characters as |
| 122 | // needed. |
| 123 | OS << '"'; |
Daniel Dunbar | db0b70a | 2008-10-28 19:33:02 +0000 | [diff] [blame] | 124 | PrintEscapedString(NameStr, NameLen, OS); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 125 | OS << '"'; |
| 126 | } |
| 127 | |
Daniel Dunbar | 389529a | 2008-10-14 23:28:09 +0000 | [diff] [blame] | 128 | /// getLLVMName - Turn the specified string into an 'LLVM name', which is |
| 129 | /// surrounded with ""'s and escaped if it has special chars in it. |
| 130 | static std::string getLLVMName(const std::string &Name) { |
| 131 | assert(!Name.empty() && "Cannot get empty name!"); |
| 132 | std::string result; |
| 133 | raw_string_ostream OS(result); |
| 134 | PrintLLVMName(OS, Name.c_str(), Name.length(), NoPrefix); |
| 135 | return OS.str(); |
| 136 | } |
| 137 | |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 138 | /// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either |
| 139 | /// prefixed with % (if the string only contains simple characters) or is |
| 140 | /// surrounded with ""'s (if it has special chars in it). Print it out. |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 141 | static void PrintLLVMName(raw_ostream &OS, const Value *V) { |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 142 | PrintLLVMName(OS, V->getNameStart(), V->getNameLen(), |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 143 | isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix); |
| 144 | } |
| 145 | |
| 146 | |
| 147 | |
| 148 | //===----------------------------------------------------------------------===// |
| 149 | // SlotTracker Class: Enumerate slot numbers for unnamed values |
| 150 | //===----------------------------------------------------------------------===// |
| 151 | |
Chris Lattner | 3ee5876 | 2008-08-19 04:28:07 +0000 | [diff] [blame] | 152 | namespace { |
| 153 | |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 154 | /// This class provides computation of slot numbers for LLVM Assembly writing. |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 155 | /// |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 156 | class SlotTracker { |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 157 | public: |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 158 | /// ValueMap - A mapping of Values to slot numbers |
Chris Lattner | a204d41 | 2008-08-17 17:25:25 +0000 | [diff] [blame] | 159 | typedef DenseMap<const Value*, unsigned> ValueMap; |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 160 | |
| 161 | private: |
| 162 | /// TheModule - The module for which we are holding slot numbers |
| 163 | const Module* TheModule; |
| 164 | |
| 165 | /// TheFunction - The function for which we are holding slot numbers |
| 166 | const Function* TheFunction; |
| 167 | bool FunctionProcessed; |
| 168 | |
| 169 | /// mMap - The TypePlanes map for the module level data |
| 170 | ValueMap mMap; |
| 171 | unsigned mNext; |
| 172 | |
| 173 | /// fMap - The TypePlanes map for the function level data |
| 174 | ValueMap fMap; |
| 175 | unsigned fNext; |
| 176 | |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 177 | public: |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 178 | /// Construct from a module |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 179 | explicit SlotTracker(const Module *M); |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 180 | /// Construct from a function, starting out in incorp state. |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 181 | explicit SlotTracker(const Function *F); |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 182 | |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 183 | /// Return the slot number of the specified value in it's type |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 184 | /// plane. If something is not in the SlotTracker, return -1. |
Chris Lattner | 5e04332 | 2007-01-11 03:54:27 +0000 | [diff] [blame] | 185 | int getLocalSlot(const Value *V); |
| 186 | int getGlobalSlot(const GlobalValue *V); |
Reid Spencer | 8beac69 | 2004-06-09 15:26:53 +0000 | [diff] [blame] | 187 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 188 | /// If you'd like to deal with a function instead of just a module, use |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 189 | /// this method to get its data into the SlotTracker. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 190 | void incorporateFunction(const Function *F) { |
| 191 | TheFunction = F; |
Reid Spencer | b0ac8c4 | 2004-08-16 07:46:33 +0000 | [diff] [blame] | 192 | FunctionProcessed = false; |
| 193 | } |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 194 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 195 | /// After calling incorporateFunction, use this method to remove the |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 196 | /// most recently incorporated function from the SlotTracker. This |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 197 | /// will reset the state of the machine back to just the module contents. |
| 198 | void purgeFunction(); |
| 199 | |
Chris Lattner | 393b7cd | 2008-08-17 04:17:45 +0000 | [diff] [blame] | 200 | // Implementation Details |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 201 | private: |
Reid Spencer | 56010e4 | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 202 | /// This function does the actual initialization. |
| 203 | inline void initialize(); |
| 204 | |
Chris Lattner | ea862a3 | 2007-01-09 07:55:49 +0000 | [diff] [blame] | 205 | /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. |
| 206 | void CreateModuleSlot(const GlobalValue *V); |
| 207 | |
| 208 | /// CreateFunctionSlot - Insert the specified Value* into the slot table. |
| 209 | void CreateFunctionSlot(const Value *V); |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 210 | |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 211 | /// Add all of the module level global variables (and their initializers) |
| 212 | /// and function declarations, but not the contents of those functions. |
| 213 | void processModule(); |
| 214 | |
Reid Spencer | 56010e4 | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 215 | /// Add all of the functions arguments, basic blocks, and instructions |
| 216 | void processFunction(); |
| 217 | |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 218 | SlotTracker(const SlotTracker &); // DO NOT IMPLEMENT |
| 219 | void operator=(const SlotTracker &); // DO NOT IMPLEMENT |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 220 | }; |
| 221 | |
Chris Lattner | 3ee5876 | 2008-08-19 04:28:07 +0000 | [diff] [blame] | 222 | } // end anonymous namespace |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 223 | |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 224 | |
| 225 | static SlotTracker *createSlotTracker(const Value *V) { |
| 226 | if (const Argument *FA = dyn_cast<Argument>(V)) |
| 227 | return new SlotTracker(FA->getParent()); |
| 228 | |
| 229 | if (const Instruction *I = dyn_cast<Instruction>(V)) |
| 230 | return new SlotTracker(I->getParent()->getParent()); |
| 231 | |
| 232 | if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) |
| 233 | return new SlotTracker(BB->getParent()); |
| 234 | |
| 235 | if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) |
| 236 | return new SlotTracker(GV->getParent()); |
| 237 | |
| 238 | if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) |
| 239 | return new SlotTracker(GA->getParent()); |
| 240 | |
| 241 | if (const Function *Func = dyn_cast<Function>(V)) |
| 242 | return new SlotTracker(Func); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | #if 0 |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 248 | #define ST_DEBUG(X) cerr << X |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 249 | #else |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 250 | #define ST_DEBUG(X) |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 251 | #endif |
| 252 | |
| 253 | // Module level constructor. Causes the contents of the Module (sans functions) |
| 254 | // to be added to the slot table. |
| 255 | SlotTracker::SlotTracker(const Module *M) |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 256 | : TheModule(M), TheFunction(0), FunctionProcessed(false), mNext(0), fNext(0) { |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // Function level constructor. Causes the contents of the Module and the one |
| 260 | // function provided to be added to the slot table. |
| 261 | SlotTracker::SlotTracker(const Function *F) |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 262 | : TheModule(F ? F->getParent() : 0), TheFunction(F), FunctionProcessed(false), |
| 263 | mNext(0), fNext(0) { |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | inline void SlotTracker::initialize() { |
| 267 | if (TheModule) { |
| 268 | processModule(); |
| 269 | TheModule = 0; ///< Prevent re-processing next time we're called. |
| 270 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 271 | |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 272 | if (TheFunction && !FunctionProcessed) |
| 273 | processFunction(); |
| 274 | } |
| 275 | |
| 276 | // Iterate through all the global variables, functions, and global |
| 277 | // variable initializers and create slots for them. |
| 278 | void SlotTracker::processModule() { |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 279 | ST_DEBUG("begin processModule!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 280 | |
| 281 | // Add all of the unnamed global variables to the value table. |
| 282 | for (Module::const_global_iterator I = TheModule->global_begin(), |
| 283 | E = TheModule->global_end(); I != E; ++I) |
| 284 | if (!I->hasName()) |
| 285 | CreateModuleSlot(I); |
| 286 | |
| 287 | // Add all the unnamed functions to the table. |
| 288 | for (Module::const_iterator I = TheModule->begin(), E = TheModule->end(); |
| 289 | I != E; ++I) |
| 290 | if (!I->hasName()) |
| 291 | CreateModuleSlot(I); |
| 292 | |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 293 | ST_DEBUG("end processModule!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
| 297 | // Process the arguments, basic blocks, and instructions of a function. |
| 298 | void SlotTracker::processFunction() { |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 299 | ST_DEBUG("begin processFunction!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 300 | fNext = 0; |
| 301 | |
| 302 | // Add all the function arguments with no names. |
| 303 | for(Function::const_arg_iterator AI = TheFunction->arg_begin(), |
| 304 | AE = TheFunction->arg_end(); AI != AE; ++AI) |
| 305 | if (!AI->hasName()) |
| 306 | CreateFunctionSlot(AI); |
| 307 | |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 308 | ST_DEBUG("Inserting Instructions:\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 309 | |
| 310 | // Add all of the basic blocks and instructions with no names. |
| 311 | for (Function::const_iterator BB = TheFunction->begin(), |
| 312 | E = TheFunction->end(); BB != E; ++BB) { |
| 313 | if (!BB->hasName()) |
| 314 | CreateFunctionSlot(BB); |
| 315 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
| 316 | if (I->getType() != Type::VoidTy && !I->hasName()) |
| 317 | CreateFunctionSlot(I); |
| 318 | } |
| 319 | |
| 320 | FunctionProcessed = true; |
| 321 | |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 322 | ST_DEBUG("end processFunction!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | /// Clean up after incorporating a function. This is the only way to get out of |
| 326 | /// the function incorporation state that affects get*Slot/Create*Slot. Function |
| 327 | /// incorporation state is indicated by TheFunction != 0. |
| 328 | void SlotTracker::purgeFunction() { |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 329 | ST_DEBUG("begin purgeFunction!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 330 | fMap.clear(); // Simply discard the function level map |
| 331 | TheFunction = 0; |
| 332 | FunctionProcessed = false; |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 333 | ST_DEBUG("end purgeFunction!\n"); |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | /// getGlobalSlot - Get the slot number of a global value. |
| 337 | int SlotTracker::getGlobalSlot(const GlobalValue *V) { |
| 338 | // Check for uninitialized state and do lazy initialization. |
| 339 | initialize(); |
| 340 | |
| 341 | // Find the type plane in the module map |
| 342 | ValueMap::iterator MI = mMap.find(V); |
Dan Gohman | 1dd2757 | 2008-10-01 19:58:59 +0000 | [diff] [blame] | 343 | return MI == mMap.end() ? -1 : (int)MI->second; |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | |
| 347 | /// getLocalSlot - Get the slot number for a value that is local to a function. |
| 348 | int SlotTracker::getLocalSlot(const Value *V) { |
| 349 | assert(!isa<Constant>(V) && "Can't get a constant or global slot with this!"); |
| 350 | |
| 351 | // Check for uninitialized state and do lazy initialization. |
| 352 | initialize(); |
| 353 | |
| 354 | ValueMap::iterator FI = fMap.find(V); |
Dan Gohman | 1dd2757 | 2008-10-01 19:58:59 +0000 | [diff] [blame] | 355 | return FI == fMap.end() ? -1 : (int)FI->second; |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
| 359 | /// CreateModuleSlot - Insert the specified GlobalValue* into the slot table. |
| 360 | void SlotTracker::CreateModuleSlot(const GlobalValue *V) { |
| 361 | assert(V && "Can't insert a null Value into SlotTracker!"); |
| 362 | assert(V->getType() != Type::VoidTy && "Doesn't need a slot!"); |
| 363 | assert(!V->hasName() && "Doesn't need a slot!"); |
| 364 | |
| 365 | unsigned DestSlot = mNext++; |
| 366 | mMap[V] = DestSlot; |
| 367 | |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 368 | ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 369 | DestSlot << " ["); |
| 370 | // G = Global, F = Function, A = Alias, o = other |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 371 | ST_DEBUG((isa<GlobalVariable>(V) ? 'G' : |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 372 | (isa<Function>(V) ? 'F' : |
| 373 | (isa<GlobalAlias>(V) ? 'A' : 'o'))) << "]\n"); |
| 374 | } |
| 375 | |
| 376 | |
| 377 | /// CreateSlot - Create a new slot for the specified value if it has no name. |
| 378 | void SlotTracker::CreateFunctionSlot(const Value *V) { |
| 379 | assert(V->getType() != Type::VoidTy && !V->hasName() && |
| 380 | "Doesn't need a slot!"); |
| 381 | |
| 382 | unsigned DestSlot = fNext++; |
| 383 | fMap[V] = DestSlot; |
| 384 | |
| 385 | // G = Global, F = Function, o = other |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 386 | ST_DEBUG(" Inserting value [" << V->getType() << "] = " << V << " slot=" << |
Chris Lattner | 3eee99c | 2008-08-19 04:36:02 +0000 | [diff] [blame] | 387 | DestSlot << " [o]\n"); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | |
| 392 | //===----------------------------------------------------------------------===// |
| 393 | // AsmWriter Implementation |
| 394 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7f8845a | 2002-07-23 18:07:49 +0000 | [diff] [blame] | 395 | |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 396 | static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, |
Chris Lattner | a9f0a11 | 2006-12-06 05:50:41 +0000 | [diff] [blame] | 397 | std::map<const Type *, std::string> &TypeTable, |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 398 | SlotTracker *Machine); |
Reid Spencer | 58d30f2 | 2004-07-04 11:50:43 +0000 | [diff] [blame] | 399 | |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 400 | |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 401 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 402 | /// fillTypeNameTable - If the module has a symbol table, take all global types |
| 403 | /// and stuff their names into the TypeNames map. |
| 404 | /// |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 405 | static void fillTypeNameTable(const Module *M, |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 406 | std::map<const Type *, std::string> &TypeNames) { |
Chris Lattner | 98cf1f5 | 2002-11-20 18:36:02 +0000 | [diff] [blame] | 407 | if (!M) return; |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 408 | const TypeSymbolTable &ST = M->getTypeSymbolTable(); |
| 409 | TypeSymbolTable::const_iterator TI = ST.begin(); |
| 410 | for (; TI != ST.end(); ++TI) { |
Reid Spencer | e7e9671 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 411 | // As a heuristic, don't insert pointer to primitive types, because |
| 412 | // they are used too often to have a single useful name. |
| 413 | // |
| 414 | const Type *Ty = cast<Type>(TI->second); |
| 415 | if (!isa<PointerType>(Ty) || |
Reid Spencer | 56010e4 | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 416 | !cast<PointerType>(Ty)->getElementType()->isPrimitiveType() || |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 417 | !cast<PointerType>(Ty)->getElementType()->isInteger() || |
Reid Spencer | 56010e4 | 2004-05-26 21:56:09 +0000 | [diff] [blame] | 418 | isa<OpaqueType>(cast<PointerType>(Ty)->getElementType())) |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 419 | TypeNames.insert(std::make_pair(Ty, '%' + getLLVMName(TI->first))); |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | |
| 423 | |
| 424 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 425 | static void calcTypeName(const Type *Ty, |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 426 | std::vector<const Type *> &TypeStack, |
| 427 | std::map<const Type *, std::string> &TypeNames, |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 428 | std::string &Result) { |
Chris Lattner | 03c4953 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 429 | if (Ty->isInteger() || (Ty->isPrimitiveType() && !isa<OpaqueType>(Ty))) { |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 430 | Result += Ty->getDescription(); // Base case |
| 431 | return; |
| 432 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 433 | |
| 434 | // Check to see if the type is named. |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 435 | std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty); |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 436 | if (I != TypeNames.end()) { |
| 437 | Result += I->second; |
| 438 | return; |
| 439 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 440 | |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 441 | if (isa<OpaqueType>(Ty)) { |
| 442 | Result += "opaque"; |
| 443 | return; |
| 444 | } |
Chris Lattner | f14ead9 | 2003-10-30 00:22:33 +0000 | [diff] [blame] | 445 | |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 446 | // Check to see if the Type is already on the stack... |
| 447 | unsigned Slot = 0, CurSize = TypeStack.size(); |
| 448 | while (Slot < CurSize && TypeStack[Slot] != Ty) ++Slot; // Scan for type |
| 449 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 450 | // This is another base case for the recursion. In this case, we know |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 451 | // that we have looped back to a type that we have previously visited. |
| 452 | // Generate the appropriate upreference to handle this. |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 453 | if (Slot < CurSize) { |
| 454 | Result += "\\" + utostr(CurSize-Slot); // Here's the upreference |
| 455 | return; |
| 456 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 457 | |
| 458 | TypeStack.push_back(Ty); // Recursive case: Add us to the stack.. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 459 | |
Chris Lattner | 6b72759 | 2004-06-17 18:19:28 +0000 | [diff] [blame] | 460 | switch (Ty->getTypeID()) { |
Reid Spencer | 7a9c62b | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 461 | case Type::IntegerTyID: { |
| 462 | unsigned BitWidth = cast<IntegerType>(Ty)->getBitWidth(); |
Reid Spencer | c872159 | 2007-01-12 07:25:20 +0000 | [diff] [blame] | 463 | Result += "i" + utostr(BitWidth); |
Reid Spencer | 7a9c62b | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 464 | break; |
| 465 | } |
Chris Lattner | 91db582 | 2002-03-29 03:44:36 +0000 | [diff] [blame] | 466 | case Type::FunctionTyID: { |
Chris Lattner | f26a8ee | 2003-07-23 15:30:06 +0000 | [diff] [blame] | 467 | const FunctionType *FTy = cast<FunctionType>(Ty); |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 468 | calcTypeName(FTy->getReturnType(), TypeStack, TypeNames, Result); |
| 469 | Result += " ("; |
Chris Lattner | fa829be | 2004-02-09 04:14:01 +0000 | [diff] [blame] | 470 | for (FunctionType::param_iterator I = FTy->param_begin(), |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 471 | E = FTy->param_end(); I != E; ++I) { |
Chris Lattner | fa829be | 2004-02-09 04:14:01 +0000 | [diff] [blame] | 472 | if (I != FTy->param_begin()) |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 473 | Result += ", "; |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 474 | calcTypeName(*I, TypeStack, TypeNames, Result); |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 475 | } |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 476 | if (FTy->isVarArg()) { |
Chris Lattner | fa829be | 2004-02-09 04:14:01 +0000 | [diff] [blame] | 477 | if (FTy->getNumParams()) Result += ", "; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 478 | Result += "..."; |
| 479 | } |
| 480 | Result += ")"; |
| 481 | break; |
| 482 | } |
| 483 | case Type::StructTyID: { |
Chris Lattner | f26a8ee | 2003-07-23 15:30:06 +0000 | [diff] [blame] | 484 | const StructType *STy = cast<StructType>(Ty); |
Andrew Lenharth | dcb3c97 | 2006-12-08 18:06:16 +0000 | [diff] [blame] | 485 | if (STy->isPacked()) |
| 486 | Result += '<'; |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 487 | Result += "{ "; |
Chris Lattner | ac6db75 | 2004-02-09 04:37:31 +0000 | [diff] [blame] | 488 | for (StructType::element_iterator I = STy->element_begin(), |
| 489 | E = STy->element_end(); I != E; ++I) { |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 490 | calcTypeName(*I, TypeStack, TypeNames, Result); |
Dan Gohman | bb9a211 | 2008-09-25 17:37:20 +0000 | [diff] [blame] | 491 | if (next(I) != STy->element_end()) |
| 492 | Result += ','; |
| 493 | Result += ' '; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 494 | } |
Dan Gohman | bb9a211 | 2008-09-25 17:37:20 +0000 | [diff] [blame] | 495 | Result += '}'; |
Andrew Lenharth | dcb3c97 | 2006-12-08 18:06:16 +0000 | [diff] [blame] | 496 | if (STy->isPacked()) |
| 497 | Result += '>'; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 498 | break; |
| 499 | } |
Christopher Lamb | 54dd24c | 2007-12-11 08:59:05 +0000 | [diff] [blame] | 500 | case Type::PointerTyID: { |
| 501 | const PointerType *PTy = cast<PointerType>(Ty); |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 502 | calcTypeName(PTy->getElementType(), TypeStack, TypeNames, Result); |
Christopher Lamb | 54dd24c | 2007-12-11 08:59:05 +0000 | [diff] [blame] | 503 | if (unsigned AddressSpace = PTy->getAddressSpace()) |
| 504 | Result += " addrspace(" + utostr(AddressSpace) + ")"; |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 505 | Result += "*"; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 506 | break; |
Christopher Lamb | 54dd24c | 2007-12-11 08:59:05 +0000 | [diff] [blame] | 507 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 508 | case Type::ArrayTyID: { |
Chris Lattner | f26a8ee | 2003-07-23 15:30:06 +0000 | [diff] [blame] | 509 | const ArrayType *ATy = cast<ArrayType>(Ty); |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 510 | Result += "[" + utostr(ATy->getNumElements()) + " x "; |
| 511 | calcTypeName(ATy->getElementType(), TypeStack, TypeNames, Result); |
| 512 | Result += "]"; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 513 | break; |
| 514 | } |
Reid Spencer | d84d35b | 2007-02-15 02:26:10 +0000 | [diff] [blame] | 515 | case Type::VectorTyID: { |
| 516 | const VectorType *PTy = cast<VectorType>(Ty); |
Brian Gaeke | 0220904 | 2004-08-20 06:00:58 +0000 | [diff] [blame] | 517 | Result += "<" + utostr(PTy->getNumElements()) + " x "; |
| 518 | calcTypeName(PTy->getElementType(), TypeStack, TypeNames, Result); |
| 519 | Result += ">"; |
| 520 | break; |
| 521 | } |
Chris Lattner | 15285ab | 2003-05-14 17:50:47 +0000 | [diff] [blame] | 522 | case Type::OpaqueTyID: |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 523 | Result += "opaque"; |
Chris Lattner | 15285ab | 2003-05-14 17:50:47 +0000 | [diff] [blame] | 524 | break; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 525 | default: |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 526 | Result += "<unrecognized-type>"; |
Chris Lattner | fc9f1c9 | 2006-12-06 06:40:49 +0000 | [diff] [blame] | 527 | break; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | TypeStack.pop_back(); // Remove self from stack... |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | |
Misha Brukman | b22d09c | 2004-03-01 19:48:13 +0000 | [diff] [blame] | 534 | /// printTypeInt - The internal guts of printing out a type that has a |
| 535 | /// potentially named portion. |
| 536 | /// |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 537 | static void printTypeInt(raw_ostream &Out, const Type *Ty, |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 538 | std::map<const Type *, std::string> &TypeNames) { |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 539 | // Primitive types always print out their description, regardless of whether |
| 540 | // they have been named or not. |
| 541 | // |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 542 | if (Ty->isInteger() || (Ty->isPrimitiveType() && !isa<OpaqueType>(Ty))) { |
| 543 | Out << Ty->getDescription(); |
| 544 | return; |
| 545 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 546 | |
| 547 | // Check to see if the type is named. |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 548 | std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty); |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 549 | if (I != TypeNames.end()) { |
| 550 | Out << I->second; |
| 551 | return; |
| 552 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 553 | |
| 554 | // Otherwise we have a type that has not been named but is a derived type. |
| 555 | // Carefully recurse the type hierarchy to print out any contained symbolic |
| 556 | // names. |
| 557 | // |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 558 | std::vector<const Type *> TypeStack; |
John Criswell | cd116ba | 2004-06-01 14:54:08 +0000 | [diff] [blame] | 559 | std::string TypeName; |
| 560 | calcTypeName(Ty, TypeStack, TypeNames, TypeName); |
Chris Lattner | 7f74a56 | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 561 | TypeNames.insert(std::make_pair(Ty, TypeName));//Cache type name for later use |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 562 | Out << TypeName; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 563 | } |
| 564 | |
Chris Lattner | 34b9518 | 2001-10-31 04:33:19 +0000 | [diff] [blame] | 565 | |
Misha Brukman | b22d09c | 2004-03-01 19:48:13 +0000 | [diff] [blame] | 566 | /// WriteTypeSymbolic - This attempts to write the specified type as a symbolic |
| 567 | /// type, iff there is an entry in the modules symbol table for the specified |
| 568 | /// type or one of it's component types. This is slower than a simple x << Type |
| 569 | /// |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 570 | void llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty, |
| 571 | const Module *M) { |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 572 | raw_os_ostream RO(Out); |
| 573 | WriteTypeSymbolic(RO, Ty, M); |
| 574 | } |
| 575 | |
| 576 | void llvm::WriteTypeSymbolic(raw_ostream &Out, const Type *Ty, const Module *M){ |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 577 | Out << ' '; |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 578 | |
Chris Lattner | fc9f1c9 | 2006-12-06 06:40:49 +0000 | [diff] [blame] | 579 | // If they want us to print out a type, but there is no context, we can't |
| 580 | // print it symbolically. |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 581 | if (!M) { |
| 582 | Out << Ty->getDescription(); |
| 583 | } else { |
| 584 | std::map<const Type *, std::string> TypeNames; |
| 585 | fillTypeNameTable(M, TypeNames); |
| 586 | printTypeInt(Out, Ty, TypeNames); |
| 587 | } |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Chris Lattner | fc9f1c9 | 2006-12-06 06:40:49 +0000 | [diff] [blame] | 590 | static const char *getPredicateText(unsigned predicate) { |
Reid Spencer | 812a1be | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 591 | const char * pred = "unknown"; |
| 592 | switch (predicate) { |
| 593 | case FCmpInst::FCMP_FALSE: pred = "false"; break; |
| 594 | case FCmpInst::FCMP_OEQ: pred = "oeq"; break; |
| 595 | case FCmpInst::FCMP_OGT: pred = "ogt"; break; |
| 596 | case FCmpInst::FCMP_OGE: pred = "oge"; break; |
| 597 | case FCmpInst::FCMP_OLT: pred = "olt"; break; |
| 598 | case FCmpInst::FCMP_OLE: pred = "ole"; break; |
| 599 | case FCmpInst::FCMP_ONE: pred = "one"; break; |
| 600 | case FCmpInst::FCMP_ORD: pred = "ord"; break; |
| 601 | case FCmpInst::FCMP_UNO: pred = "uno"; break; |
| 602 | case FCmpInst::FCMP_UEQ: pred = "ueq"; break; |
| 603 | case FCmpInst::FCMP_UGT: pred = "ugt"; break; |
| 604 | case FCmpInst::FCMP_UGE: pred = "uge"; break; |
| 605 | case FCmpInst::FCMP_ULT: pred = "ult"; break; |
| 606 | case FCmpInst::FCMP_ULE: pred = "ule"; break; |
| 607 | case FCmpInst::FCMP_UNE: pred = "une"; break; |
| 608 | case FCmpInst::FCMP_TRUE: pred = "true"; break; |
| 609 | case ICmpInst::ICMP_EQ: pred = "eq"; break; |
| 610 | case ICmpInst::ICMP_NE: pred = "ne"; break; |
| 611 | case ICmpInst::ICMP_SGT: pred = "sgt"; break; |
| 612 | case ICmpInst::ICMP_SGE: pred = "sge"; break; |
| 613 | case ICmpInst::ICMP_SLT: pred = "slt"; break; |
| 614 | case ICmpInst::ICMP_SLE: pred = "sle"; break; |
| 615 | case ICmpInst::ICMP_UGT: pred = "ugt"; break; |
| 616 | case ICmpInst::ICMP_UGE: pred = "uge"; break; |
| 617 | case ICmpInst::ICMP_ULT: pred = "ult"; break; |
| 618 | case ICmpInst::ICMP_ULE: pred = "ule"; break; |
| 619 | } |
| 620 | return pred; |
| 621 | } |
| 622 | |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 623 | static void WriteConstantInt(raw_ostream &Out, const Constant *CV, |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 624 | std::map<const Type *, std::string> &TypeTable, |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 625 | SlotTracker *Machine) { |
Zhou Sheng | 75b871f | 2007-01-11 12:24:14 +0000 | [diff] [blame] | 626 | if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) { |
Chris Lattner | 17f7165 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 627 | if (CI->getType() == Type::Int1Ty) { |
Reid Spencer | cddc9df | 2007-01-12 04:24:46 +0000 | [diff] [blame] | 628 | Out << (CI->getZExtValue() ? "true" : "false"); |
Chris Lattner | 17f7165 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 629 | return; |
| 630 | } |
| 631 | Out << CI->getValue(); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) { |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 636 | if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEdouble || |
| 637 | &CFP->getValueAPF().getSemantics() == &APFloat::IEEEsingle) { |
| 638 | // We would like to output the FP constant value in exponential notation, |
| 639 | // but we cannot do this if doing so will lose precision. Check here to |
| 640 | // make sure that we only output it in exponential format if we can parse |
| 641 | // the value back and get the same value. |
| 642 | // |
| 643 | bool isDouble = &CFP->getValueAPF().getSemantics()==&APFloat::IEEEdouble; |
Chris Lattner | 17f7165 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 644 | double Val = isDouble ? CFP->getValueAPF().convertToDouble() : |
| 645 | CFP->getValueAPF().convertToFloat(); |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 646 | std::string StrVal = ftostr(CFP->getValueAPF()); |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 647 | |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 648 | // Check to make sure that the stringized number is not some string like |
| 649 | // "Inf" or NaN, that atof will accept, but the lexer will not. Check |
| 650 | // that the string matches the "[-+]?[0-9]" regex. |
| 651 | // |
| 652 | if ((StrVal[0] >= '0' && StrVal[0] <= '9') || |
| 653 | ((StrVal[0] == '-' || StrVal[0] == '+') && |
| 654 | (StrVal[1] >= '0' && StrVal[1] <= '9'))) { |
| 655 | // Reparse stringized version! |
| 656 | if (atof(StrVal.c_str()) == Val) { |
| 657 | Out << StrVal; |
| 658 | return; |
| 659 | } |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 660 | } |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 661 | // Otherwise we could not reparse it to exactly the same value, so we must |
| 662 | // output the string in hexadecimal format! |
| 663 | assert(sizeof(double) == sizeof(uint64_t) && |
| 664 | "assuming that double is 64 bits!"); |
Chris Lattner | 5505eed | 2008-11-10 04:30:26 +0000 | [diff] [blame^] | 665 | char Buffer[40]; |
| 666 | Out << "0x" << utohex_buffer(uint64_t(DoubleToBits(Val)), Buffer+40); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 667 | return; |
| 668 | } |
| 669 | |
| 670 | // Some form of long double. These appear as a magic letter identifying |
| 671 | // the type, then a fixed number of hex digits. |
| 672 | Out << "0x"; |
| 673 | if (&CFP->getValueAPF().getSemantics() == &APFloat::x87DoubleExtended) |
| 674 | Out << 'K'; |
| 675 | else if (&CFP->getValueAPF().getSemantics() == &APFloat::IEEEquad) |
| 676 | Out << 'L'; |
| 677 | else if (&CFP->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble) |
| 678 | Out << 'M'; |
| 679 | else |
| 680 | assert(0 && "Unsupported floating point type"); |
| 681 | // api needed to prevent premature destruction |
Dale Johannesen | 54306fe | 2008-10-09 18:53:47 +0000 | [diff] [blame] | 682 | APInt api = CFP->getValueAPF().bitcastToAPInt(); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 683 | const uint64_t* p = api.getRawData(); |
| 684 | uint64_t word = *p; |
| 685 | int shiftcount=60; |
| 686 | int width = api.getBitWidth(); |
| 687 | for (int j=0; j<width; j+=4, shiftcount-=4) { |
| 688 | unsigned int nibble = (word>>shiftcount) & 15; |
| 689 | if (nibble < 10) |
| 690 | Out << (unsigned char)(nibble + '0'); |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 691 | else |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 692 | Out << (unsigned char)(nibble - 10 + 'A'); |
| 693 | if (shiftcount == 0 && j+4 < width) { |
| 694 | word = *(++p); |
| 695 | shiftcount = 64; |
| 696 | if (width-j-4 < 64) |
| 697 | shiftcount = width-j-4; |
Dale Johannesen | 028084e | 2007-09-12 03:30:33 +0000 | [diff] [blame] | 698 | } |
| 699 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | |
| 703 | if (isa<ConstantAggregateZero>(CV)) { |
Chris Lattner | 76b2ff4 | 2004-02-15 05:55:15 +0000 | [diff] [blame] | 704 | Out << "zeroinitializer"; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | |
| 708 | if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) { |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 709 | // As a special case, print the array as a string if it is an array of |
Dan Gohman | e9bc2ba | 2008-05-12 16:34:30 +0000 | [diff] [blame] | 710 | // i8 with ConstantInt values. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 711 | // |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 712 | const Type *ETy = CA->getType()->getElementType(); |
Chris Lattner | 6ed87bd | 2006-01-23 23:03:36 +0000 | [diff] [blame] | 713 | if (CA->isString()) { |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 714 | Out << "c\""; |
Chris Lattner | 6ed87bd | 2006-01-23 23:03:36 +0000 | [diff] [blame] | 715 | PrintEscapedString(CA->getAsString(), Out); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 716 | Out << '"'; |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 717 | } else { // Cannot output in string format... |
Misha Brukman | 21bbdb9 | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 718 | Out << '['; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 719 | if (CA->getNumOperands()) { |
Misha Brukman | 21bbdb9 | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 720 | Out << ' '; |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 721 | printTypeInt(Out, ETy, TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 722 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 723 | WriteAsOperandInternal(Out, CA->getOperand(0), |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 724 | TypeTable, Machine); |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 725 | for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) { |
| 726 | Out << ", "; |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 727 | printTypeInt(Out, ETy, TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 728 | Out << ' '; |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 729 | WriteAsOperandInternal(Out, CA->getOperand(i), TypeTable, Machine); |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 730 | } |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 731 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 732 | } |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 733 | Out << ']'; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 734 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 735 | return; |
| 736 | } |
| 737 | |
| 738 | if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) { |
Andrew Lenharth | 0d124b8 | 2007-01-08 18:21:30 +0000 | [diff] [blame] | 739 | if (CS->getType()->isPacked()) |
| 740 | Out << '<'; |
Misha Brukman | 21bbdb9 | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 741 | Out << '{'; |
Jim Laskey | 3bb7874 | 2006-02-25 12:27:03 +0000 | [diff] [blame] | 742 | unsigned N = CS->getNumOperands(); |
| 743 | if (N) { |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 744 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 745 | printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 746 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 747 | |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 748 | WriteAsOperandInternal(Out, CS->getOperand(0), TypeTable, Machine); |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 749 | |
Jim Laskey | 3bb7874 | 2006-02-25 12:27:03 +0000 | [diff] [blame] | 750 | for (unsigned i = 1; i < N; i++) { |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 751 | Out << ", "; |
| 752 | printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 753 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 754 | |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 755 | WriteAsOperandInternal(Out, CS->getOperand(i), TypeTable, Machine); |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 756 | } |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 757 | Out << ' '; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 758 | } |
Jim Laskey | 3bb7874 | 2006-02-25 12:27:03 +0000 | [diff] [blame] | 759 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 760 | Out << '}'; |
Andrew Lenharth | 0d124b8 | 2007-01-08 18:21:30 +0000 | [diff] [blame] | 761 | if (CS->getType()->isPacked()) |
| 762 | Out << '>'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 763 | return; |
| 764 | } |
| 765 | |
| 766 | if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) { |
| 767 | const Type *ETy = CP->getType()->getElementType(); |
| 768 | assert(CP->getNumOperands() > 0 && |
| 769 | "Number of operands for a PackedConst must be > 0"); |
| 770 | Out << "< "; |
| 771 | printTypeInt(Out, ETy, TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 772 | Out << ' '; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 773 | WriteAsOperandInternal(Out, CP->getOperand(0), TypeTable, Machine); |
| 774 | for (unsigned i = 1, e = CP->getNumOperands(); i != e; ++i) { |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 775 | Out << ", "; |
| 776 | printTypeInt(Out, ETy, TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 777 | Out << ' '; |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 778 | WriteAsOperandInternal(Out, CP->getOperand(i), TypeTable, Machine); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 779 | } |
| 780 | Out << " >"; |
| 781 | return; |
| 782 | } |
| 783 | |
| 784 | if (isa<ConstantPointerNull>(CV)) { |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 785 | Out << "null"; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 786 | return; |
| 787 | } |
| 788 | |
| 789 | if (isa<UndefValue>(CV)) { |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 790 | Out << "undef"; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 791 | return; |
| 792 | } |
Chris Lattner | 5e0b9f2 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 793 | |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 794 | if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) { |
Reid Spencer | 812a1be | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 795 | Out << CE->getOpcodeName(); |
| 796 | if (CE->isCompare()) |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 797 | Out << ' ' << getPredicateText(CE->getPredicate()); |
Reid Spencer | 812a1be | 2006-12-04 05:19:18 +0000 | [diff] [blame] | 798 | Out << " ("; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 799 | |
Vikram S. Adve | b952b54 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 800 | for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { |
| 801 | printTypeInt(Out, (*OI)->getType(), TypeTable); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 802 | Out << ' '; |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 803 | WriteAsOperandInternal(Out, *OI, TypeTable, Machine); |
Vikram S. Adve | b952b54 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 804 | if (OI+1 != CE->op_end()) |
Chris Lattner | 3cd8c56 | 2002-07-30 18:54:25 +0000 | [diff] [blame] | 805 | Out << ", "; |
Vikram S. Adve | b952b54 | 2002-07-14 23:14:45 +0000 | [diff] [blame] | 806 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 807 | |
Dan Gohman | a76f0f7 | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 808 | if (CE->hasIndices()) { |
| 809 | const SmallVector<unsigned, 4> &Indices = CE->getIndices(); |
| 810 | for (unsigned i = 0, e = Indices.size(); i != e; ++i) |
| 811 | Out << ", " << Indices[i]; |
| 812 | } |
| 813 | |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 814 | if (CE->isCast()) { |
Chris Lattner | 83b396b | 2002-08-15 19:37:43 +0000 | [diff] [blame] | 815 | Out << " to "; |
| 816 | printTypeInt(Out, CE->getType(), TypeTable); |
| 817 | } |
Reid Spencer | 6c38f0b | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 818 | |
Misha Brukman | 21bbdb9 | 2004-06-04 21:11:51 +0000 | [diff] [blame] | 819 | Out << ')'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 820 | return; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 821 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 822 | |
| 823 | Out << "<placeholder or erroneous Constant>"; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 827 | /// WriteAsOperand - Write the name of the specified value out to the specified |
| 828 | /// ostream. This can be useful when you just want to print int %reg126, not |
| 829 | /// the whole instruction that generated it. |
| 830 | /// |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 831 | static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 832 | std::map<const Type*, std::string> &TypeTable, |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 833 | SlotTracker *Machine) { |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 834 | if (V->hasName()) { |
| 835 | PrintLLVMName(Out, V); |
| 836 | return; |
| 837 | } |
| 838 | |
| 839 | const Constant *CV = dyn_cast<Constant>(V); |
| 840 | if (CV && !isa<GlobalValue>(CV)) { |
| 841 | WriteConstantInt(Out, CV, TypeTable, Machine); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 842 | return; |
| 843 | } |
| 844 | |
| 845 | if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 846 | Out << "asm "; |
| 847 | if (IA->hasSideEffects()) |
| 848 | Out << "sideeffect "; |
| 849 | Out << '"'; |
| 850 | PrintEscapedString(IA->getAsmString(), Out); |
| 851 | Out << "\", \""; |
| 852 | PrintEscapedString(IA->getConstraintString(), Out); |
| 853 | Out << '"'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | |
| 857 | char Prefix = '%'; |
| 858 | int Slot; |
| 859 | if (Machine) { |
| 860 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 861 | Slot = Machine->getGlobalSlot(GV); |
| 862 | Prefix = '@'; |
| 863 | } else { |
| 864 | Slot = Machine->getLocalSlot(V); |
| 865 | } |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 866 | } else { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 867 | Machine = createSlotTracker(V); |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 868 | if (Machine) { |
| 869 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) { |
| 870 | Slot = Machine->getGlobalSlot(GV); |
| 871 | Prefix = '@'; |
| 872 | } else { |
| 873 | Slot = Machine->getLocalSlot(V); |
| 874 | } |
Chris Lattner | a2d810d | 2006-01-25 22:26:05 +0000 | [diff] [blame] | 875 | } else { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 876 | Slot = -1; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 877 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 878 | delete Machine; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 879 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 880 | |
| 881 | if (Slot != -1) |
| 882 | Out << Prefix << Slot; |
| 883 | else |
| 884 | Out << "<badref>"; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 885 | } |
| 886 | |
Misha Brukman | b22d09c | 2004-03-01 19:48:13 +0000 | [diff] [blame] | 887 | /// WriteAsOperand - Write the name of the specified value out to the specified |
| 888 | /// ostream. This can be useful when you just want to print int %reg126, not |
| 889 | /// the whole instruction that generated it. |
| 890 | /// |
Chris Lattner | 604e351 | 2008-08-19 04:47:09 +0000 | [diff] [blame] | 891 | void llvm::WriteAsOperand(std::ostream &Out, const Value *V, bool PrintType, |
| 892 | const Module *Context) { |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 893 | raw_os_ostream OS(Out); |
| 894 | WriteAsOperand(OS, V, PrintType, Context); |
| 895 | } |
| 896 | |
| 897 | void llvm::WriteAsOperand(raw_ostream &Out, const Value *V, bool PrintType, |
| 898 | const Module *Context) { |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 899 | std::map<const Type *, std::string> TypeNames; |
Chris Lattner | 5a9f63e | 2002-07-10 16:48:17 +0000 | [diff] [blame] | 900 | if (Context == 0) Context = getModuleFromVal(V); |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 901 | |
Chris Lattner | 98cf1f5 | 2002-11-20 18:36:02 +0000 | [diff] [blame] | 902 | if (Context) |
Chris Lattner | 5a9f63e | 2002-07-10 16:48:17 +0000 | [diff] [blame] | 903 | fillTypeNameTable(Context, TypeNames); |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 904 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 905 | if (PrintType) { |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 906 | printTypeInt(Out, V->getType(), TypeNames); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 907 | Out << ' '; |
| 908 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 909 | |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 910 | WriteAsOperandInternal(Out, V, TypeNames, 0); |
Chris Lattner | 5e5abe3 | 2001-07-20 19:15:21 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Reid Spencer | 58d30f2 | 2004-07-04 11:50:43 +0000 | [diff] [blame] | 913 | |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 914 | namespace { |
Chris Lattner | 2e9fee4 | 2001-07-12 23:35:26 +0000 | [diff] [blame] | 915 | |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 916 | class AssemblyWriter { |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 917 | raw_ostream &Out; |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 918 | SlotTracker &Machine; |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 919 | const Module *TheModule; |
Chris Lattner | ab7d1ab | 2003-05-08 02:08:14 +0000 | [diff] [blame] | 920 | std::map<const Type *, std::string> TypeNames; |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 921 | AssemblyAnnotationWriter *AnnotationWriter; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 922 | public: |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 923 | inline AssemblyWriter(raw_ostream &o, SlotTracker &Mac, const Module *M, |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 924 | AssemblyAnnotationWriter *AAW) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 925 | : Out(o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) { |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 926 | |
| 927 | // If the module has a symbol table, take all global types and stuff their |
| 928 | // names into the TypeNames map. |
| 929 | // |
Chris Lattner | b86620e | 2001-10-29 16:37:48 +0000 | [diff] [blame] | 930 | fillTypeNameTable(M, TypeNames); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 931 | } |
| 932 | |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 933 | void write(const Module *M) { printModule(M); } |
| 934 | |
| 935 | void write(const GlobalValue *G) { |
| 936 | if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(G)) |
| 937 | printGlobal(GV); |
| 938 | else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(G)) |
| 939 | printAlias(GA); |
| 940 | else if (const Function *F = dyn_cast<Function>(G)) |
| 941 | printFunction(F); |
| 942 | else |
| 943 | assert(0 && "Unknown global"); |
| 944 | } |
| 945 | |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 946 | void write(const BasicBlock *BB) { printBasicBlock(BB); } |
| 947 | void write(const Instruction *I) { printInstruction(*I); } |
| 948 | void write(const Type *Ty) { printType(Ty); } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 949 | |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 950 | void writeOperand(const Value *Op, bool PrintType); |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 951 | void writeParamOperand(const Value *Operand, Attributes Attrs); |
Chris Lattner | 1e19468 | 2002-04-18 18:53:13 +0000 | [diff] [blame] | 952 | |
Misha Brukman | 4685e26 | 2004-04-28 15:31:21 +0000 | [diff] [blame] | 953 | const Module* getModule() { return TheModule; } |
| 954 | |
Misha Brukman | d92f54a | 2004-11-15 19:30:05 +0000 | [diff] [blame] | 955 | private: |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 956 | void printModule(const Module *M); |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 957 | void printTypeSymbolTable(const TypeSymbolTable &ST); |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 958 | void printGlobal(const GlobalVariable *GV); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 959 | void printAlias(const GlobalAlias *GV); |
Chris Lattner | 57698e2 | 2002-03-26 18:01:55 +0000 | [diff] [blame] | 960 | void printFunction(const Function *F); |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 961 | void printArgument(const Argument *FA, Attributes Attrs); |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 962 | void printBasicBlock(const BasicBlock *BB); |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 963 | void printInstruction(const Instruction &I); |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 964 | |
| 965 | // printType - Go to extreme measures to attempt to print out a short, |
| 966 | // symbolic version of a type name. |
| 967 | // |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 968 | void printType(const Type *Ty) { |
| 969 | printTypeInt(Out, Ty, TypeNames); |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | // printTypeAtLeastOneLevel - Print out one level of the possibly complex type |
| 973 | // without considering any symbolic types that we may have equal to it. |
| 974 | // |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 975 | void printTypeAtLeastOneLevel(const Type *Ty); |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 976 | |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 977 | // printInfoComment - Print a little comment after the instruction indicating |
| 978 | // which slot it occupies. |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 979 | void printInfoComment(const Value &V); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 980 | }; |
Reid Spencer | f43ac62 | 2004-05-27 22:04:46 +0000 | [diff] [blame] | 981 | } // end of llvm namespace |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 982 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 983 | /// printTypeAtLeastOneLevel - Print out one level of the possibly complex type |
| 984 | /// without considering any symbolic types that we may have equal to it. |
| 985 | /// |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 986 | void AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) { |
| 987 | if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) { |
Reid Spencer | 7a9c62b | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 988 | Out << "i" << utostr(ITy->getBitWidth()); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 989 | return; |
| 990 | } |
| 991 | |
| 992 | if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) { |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 993 | printType(FTy->getReturnType()); |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 994 | Out << " ("; |
Chris Lattner | fa829be | 2004-02-09 04:14:01 +0000 | [diff] [blame] | 995 | for (FunctionType::param_iterator I = FTy->param_begin(), |
| 996 | E = FTy->param_end(); I != E; ++I) { |
| 997 | if (I != FTy->param_begin()) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 998 | Out << ", "; |
Chris Lattner | d84bb63 | 2002-04-16 21:36:08 +0000 | [diff] [blame] | 999 | printType(*I); |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 1000 | } |
| 1001 | if (FTy->isVarArg()) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1002 | if (FTy->getNumParams()) Out << ", "; |
| 1003 | Out << "..."; |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 1004 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1005 | Out << ')'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1006 | return; |
| 1007 | } |
| 1008 | |
| 1009 | if (const StructType *STy = dyn_cast<StructType>(Ty)) { |
Andrew Lenharth | dcb3c97 | 2006-12-08 18:06:16 +0000 | [diff] [blame] | 1010 | if (STy->isPacked()) |
| 1011 | Out << '<'; |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1012 | Out << "{ "; |
Chris Lattner | ac6db75 | 2004-02-09 04:37:31 +0000 | [diff] [blame] | 1013 | for (StructType::element_iterator I = STy->element_begin(), |
| 1014 | E = STy->element_end(); I != E; ++I) { |
| 1015 | if (I != STy->element_begin()) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1016 | Out << ", "; |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 1017 | printType(*I); |
| 1018 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1019 | Out << " }"; |
Andrew Lenharth | dcb3c97 | 2006-12-08 18:06:16 +0000 | [diff] [blame] | 1020 | if (STy->isPacked()) |
| 1021 | Out << '>'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) { |
Christopher Lamb | ac7d631 | 2007-12-18 03:49:35 +0000 | [diff] [blame] | 1026 | printType(PTy->getElementType()); |
| 1027 | if (unsigned AddressSpace = PTy->getAddressSpace()) |
| 1028 | Out << " addrspace(" << AddressSpace << ")"; |
| 1029 | Out << '*'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1034 | Out << '[' << ATy->getNumElements() << " x "; |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 1035 | printType(ATy->getElementType()); |
| 1036 | Out << ']'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1037 | return; |
| 1038 | } |
| 1039 | |
| 1040 | if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) { |
Reid Spencer | e203d35 | 2004-08-20 15:37:30 +0000 | [diff] [blame] | 1041 | Out << '<' << PTy->getNumElements() << " x "; |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 1042 | printType(PTy->getElementType()); |
| 1043 | Out << '>'; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1044 | return; |
Reid Spencer | e203d35 | 2004-08-20 15:37:30 +0000 | [diff] [blame] | 1045 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1046 | |
| 1047 | if (isa<OpaqueType>(Ty)) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1048 | Out << "opaque"; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1049 | return; |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 1050 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1051 | |
| 1052 | if (!Ty->isPrimitiveType()) |
| 1053 | Out << "<unknown derived type>"; |
| 1054 | printType(Ty); |
Chris Lattner | d816b53 | 2002-04-13 20:53:41 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 1058 | void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType) { |
| 1059 | if (Operand == 0) { |
Chris Lattner | 08f7d0c | 2005-02-24 16:58:29 +0000 | [diff] [blame] | 1060 | Out << "<null operand!>"; |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 1061 | } else { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1062 | if (PrintType) { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1063 | printType(Operand->getType()); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1064 | Out << ' '; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1065 | } |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 1066 | WriteAsOperandInternal(Out, Operand, TypeNames, &Machine); |
Chris Lattner | 08f7d0c | 2005-02-24 16:58:29 +0000 | [diff] [blame] | 1067 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Dale Johannesen | 89268bc | 2008-02-19 21:38:47 +0000 | [diff] [blame] | 1070 | void AssemblyWriter::writeParamOperand(const Value *Operand, |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 1071 | Attributes Attrs) { |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1072 | if (Operand == 0) { |
| 1073 | Out << "<null operand!>"; |
| 1074 | } else { |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1075 | // Print the type |
| 1076 | printType(Operand->getType()); |
| 1077 | // Print parameter attributes list |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1078 | if (Attrs != Attribute::None) |
| 1079 | Out << ' ' << Attribute::getAsString(Attrs); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1080 | Out << ' '; |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1081 | // Print the operand |
| 1082 | WriteAsOperandInternal(Out, Operand, TypeNames, &Machine); |
| 1083 | } |
| 1084 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1085 | |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1086 | void AssemblyWriter::printModule(const Module *M) { |
Chris Lattner | 4d8689e | 2005-03-02 23:12:40 +0000 | [diff] [blame] | 1087 | if (!M->getModuleIdentifier().empty() && |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1088 | // Don't print the ID if it will start a new line (which would |
Chris Lattner | 4d8689e | 2005-03-02 23:12:40 +0000 | [diff] [blame] | 1089 | // require a comment char before it). |
| 1090 | M->getModuleIdentifier().find('\n') == std::string::npos) |
| 1091 | Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n"; |
| 1092 | |
Owen Anderson | e223754 | 2006-10-18 02:21:12 +0000 | [diff] [blame] | 1093 | if (!M->getDataLayout().empty()) |
Chris Lattner | 0489716 | 2006-10-22 06:06:56 +0000 | [diff] [blame] | 1094 | Out << "target datalayout = \"" << M->getDataLayout() << "\"\n"; |
Reid Spencer | 48f98c8 | 2004-07-25 21:44:54 +0000 | [diff] [blame] | 1095 | if (!M->getTargetTriple().empty()) |
Reid Spencer | ffec7df | 2004-07-25 21:29:43 +0000 | [diff] [blame] | 1096 | Out << "target triple = \"" << M->getTargetTriple() << "\"\n"; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1097 | |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 1098 | if (!M->getModuleInlineAsm().empty()) { |
Chris Lattner | efaf35d | 2006-01-24 00:45:30 +0000 | [diff] [blame] | 1099 | // Split the string into lines, to make it easier to read the .ll file. |
Chris Lattner | eef2fe7 | 2006-01-24 04:13:11 +0000 | [diff] [blame] | 1100 | std::string Asm = M->getModuleInlineAsm(); |
Chris Lattner | efaf35d | 2006-01-24 00:45:30 +0000 | [diff] [blame] | 1101 | size_t CurPos = 0; |
| 1102 | size_t NewLine = Asm.find_first_of('\n', CurPos); |
| 1103 | while (NewLine != std::string::npos) { |
| 1104 | // We found a newline, print the portion of the asm string from the |
| 1105 | // last newline up to this newline. |
| 1106 | Out << "module asm \""; |
| 1107 | PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.begin()+NewLine), |
| 1108 | Out); |
| 1109 | Out << "\"\n"; |
| 1110 | CurPos = NewLine+1; |
| 1111 | NewLine = Asm.find_first_of('\n', CurPos); |
| 1112 | } |
Chris Lattner | 3acaf5c | 2006-01-24 00:40:17 +0000 | [diff] [blame] | 1113 | Out << "module asm \""; |
Chris Lattner | efaf35d | 2006-01-24 00:45:30 +0000 | [diff] [blame] | 1114 | PrintEscapedString(std::string(Asm.begin()+CurPos, Asm.end()), Out); |
Chris Lattner | 6ed87bd | 2006-01-23 23:03:36 +0000 | [diff] [blame] | 1115 | Out << "\"\n"; |
| 1116 | } |
| 1117 | |
Chris Lattner | 2cdd49d | 2004-09-14 05:06:58 +0000 | [diff] [blame] | 1118 | // Loop over the dependent libraries and emit them. |
Chris Lattner | 730cfe4 | 2004-09-14 04:51:44 +0000 | [diff] [blame] | 1119 | Module::lib_iterator LI = M->lib_begin(); |
| 1120 | Module::lib_iterator LE = M->lib_end(); |
Reid Spencer | 48f98c8 | 2004-07-25 21:44:54 +0000 | [diff] [blame] | 1121 | if (LI != LE) { |
Chris Lattner | 730cfe4 | 2004-09-14 04:51:44 +0000 | [diff] [blame] | 1122 | Out << "deplibs = [ "; |
| 1123 | while (LI != LE) { |
Chris Lattner | 2cdd49d | 2004-09-14 05:06:58 +0000 | [diff] [blame] | 1124 | Out << '"' << *LI << '"'; |
Reid Spencer | ffec7df | 2004-07-25 21:29:43 +0000 | [diff] [blame] | 1125 | ++LI; |
Chris Lattner | 730cfe4 | 2004-09-14 04:51:44 +0000 | [diff] [blame] | 1126 | if (LI != LE) |
| 1127 | Out << ", "; |
Reid Spencer | ffec7df | 2004-07-25 21:29:43 +0000 | [diff] [blame] | 1128 | } |
| 1129 | Out << " ]\n"; |
Reid Spencer | cc5ff64 | 2004-07-25 18:08:18 +0000 | [diff] [blame] | 1130 | } |
Reid Spencer | b9e0877 | 2004-09-13 23:44:23 +0000 | [diff] [blame] | 1131 | |
Chris Lattner | 2cdd49d | 2004-09-14 05:06:58 +0000 | [diff] [blame] | 1132 | // Loop over the symbol table, emitting all named constants. |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 1133 | printTypeSymbolTable(M->getTypeSymbolTable()); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1134 | |
Chris Lattner | 54932b0 | 2006-12-06 04:41:52 +0000 | [diff] [blame] | 1135 | for (Module::const_global_iterator I = M->global_begin(), E = M->global_end(); |
| 1136 | I != E; ++I) |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1137 | printGlobal(I); |
Chris Lattner | d274705 | 2007-04-26 02:24:10 +0000 | [diff] [blame] | 1138 | |
| 1139 | // Output all aliases. |
| 1140 | if (!M->alias_empty()) Out << "\n"; |
| 1141 | for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end(); |
| 1142 | I != E; ++I) |
| 1143 | printAlias(I); |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1144 | |
Chris Lattner | 2cdd49d | 2004-09-14 05:06:58 +0000 | [diff] [blame] | 1145 | // Output all of the functions. |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1146 | for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) |
| 1147 | printFunction(I); |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1150 | static void PrintLinkage(GlobalValue::LinkageTypes LT, raw_ostream &Out) { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1151 | switch (LT) { |
| 1152 | case GlobalValue::InternalLinkage: Out << "internal "; break; |
| 1153 | case GlobalValue::LinkOnceLinkage: Out << "linkonce "; break; |
| 1154 | case GlobalValue::WeakLinkage: Out << "weak "; break; |
| 1155 | case GlobalValue::CommonLinkage: Out << "common "; break; |
| 1156 | case GlobalValue::AppendingLinkage: Out << "appending "; break; |
| 1157 | case GlobalValue::DLLImportLinkage: Out << "dllimport "; break; |
| 1158 | case GlobalValue::DLLExportLinkage: Out << "dllexport "; break; |
| 1159 | case GlobalValue::ExternalWeakLinkage: Out << "extern_weak "; break; |
| 1160 | case GlobalValue::ExternalLinkage: break; |
| 1161 | case GlobalValue::GhostLinkage: |
| 1162 | Out << "GhostLinkage not allowed in AsmWriter!\n"; |
| 1163 | abort(); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | static void PrintVisibility(GlobalValue::VisibilityTypes Vis, |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1169 | raw_ostream &Out) { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1170 | switch (Vis) { |
| 1171 | default: assert(0 && "Invalid visibility style!"); |
| 1172 | case GlobalValue::DefaultVisibility: break; |
| 1173 | case GlobalValue::HiddenVisibility: Out << "hidden "; break; |
| 1174 | case GlobalValue::ProtectedVisibility: Out << "protected "; break; |
| 1175 | } |
| 1176 | } |
| 1177 | |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1178 | void AssemblyWriter::printGlobal(const GlobalVariable *GV) { |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1179 | if (GV->hasName()) { |
| 1180 | PrintLLVMName(Out, GV); |
| 1181 | Out << " = "; |
| 1182 | } |
Chris Lattner | 3779864 | 2001-09-18 04:01:05 +0000 | [diff] [blame] | 1183 | |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 1184 | if (!GV->hasInitializer() && GV->hasExternalLinkage()) |
| 1185 | Out << "external "; |
| 1186 | |
| 1187 | PrintLinkage(GV->getLinkage(), Out); |
| 1188 | PrintVisibility(GV->getVisibility(), Out); |
Lauro Ramos Venancio | 749e466 | 2007-04-12 18:32:50 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (GV->isThreadLocal()) Out << "thread_local "; |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1191 | Out << (GV->isConstant() ? "constant " : "global "); |
Chris Lattner | 2413b16 | 2001-12-04 00:03:30 +0000 | [diff] [blame] | 1192 | printType(GV->getType()->getElementType()); |
Chris Lattner | 3779864 | 2001-09-18 04:01:05 +0000 | [diff] [blame] | 1193 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1194 | if (GV->hasInitializer()) { |
| 1195 | Out << ' '; |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 1196 | writeOperand(GV->getInitializer(), false); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1197 | } |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1198 | |
Christopher Lamb | 54dd24c | 2007-12-11 08:59:05 +0000 | [diff] [blame] | 1199 | if (unsigned AddressSpace = GV->getType()->getAddressSpace()) |
| 1200 | Out << " addrspace(" << AddressSpace << ") "; |
| 1201 | |
Chris Lattner | 4b96c54 | 2005-11-12 00:10:19 +0000 | [diff] [blame] | 1202 | if (GV->hasSection()) |
| 1203 | Out << ", section \"" << GV->getSection() << '"'; |
| 1204 | if (GV->getAlignment()) |
Chris Lattner | f8a974d | 2005-11-06 06:48:53 +0000 | [diff] [blame] | 1205 | Out << ", align " << GV->getAlignment(); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1206 | |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1207 | printInfoComment(*GV); |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1208 | Out << '\n'; |
Chris Lattner | da97550 | 2001-09-10 07:58:01 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1211 | void AssemblyWriter::printAlias(const GlobalAlias *GA) { |
Dale Johannesen | 83e468a | 2008-06-03 18:14:29 +0000 | [diff] [blame] | 1212 | // Don't crash when dumping partially built GA |
| 1213 | if (!GA->hasName()) |
| 1214 | Out << "<<nameless>> = "; |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1215 | else { |
| 1216 | PrintLLVMName(Out, GA); |
| 1217 | Out << " = "; |
| 1218 | } |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1219 | PrintVisibility(GA->getVisibility(), Out); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1220 | |
| 1221 | Out << "alias "; |
| 1222 | |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1223 | PrintLinkage(GA->getLinkage(), Out); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1224 | |
Anton Korobeynikov | 546ea7e | 2007-04-29 18:02:48 +0000 | [diff] [blame] | 1225 | const Constant *Aliasee = GA->getAliasee(); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1226 | |
| 1227 | if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Aliasee)) { |
| 1228 | printType(GV->getType()); |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1229 | Out << ' '; |
| 1230 | PrintLLVMName(Out, GV); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1231 | } else if (const Function *F = dyn_cast<Function>(Aliasee)) { |
| 1232 | printType(F->getFunctionType()); |
| 1233 | Out << "* "; |
| 1234 | |
Chris Lattner | 17f7165 | 2008-08-17 07:19:36 +0000 | [diff] [blame] | 1235 | if (F->hasName()) |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1236 | PrintLLVMName(Out, F); |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1237 | else |
| 1238 | Out << "@\"\""; |
Anton Korobeynikov | 72d5d42 | 2008-03-22 08:17:17 +0000 | [diff] [blame] | 1239 | } else if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(Aliasee)) { |
| 1240 | printType(GA->getType()); |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1241 | Out << " "; |
| 1242 | PrintLLVMName(Out, GA); |
Anton Korobeynikov | b18f8f8 | 2007-04-28 13:45:00 +0000 | [diff] [blame] | 1243 | } else { |
| 1244 | const ConstantExpr *CE = 0; |
| 1245 | if ((CE = dyn_cast<ConstantExpr>(Aliasee)) && |
| 1246 | (CE->getOpcode() == Instruction::BitCast)) { |
| 1247 | writeOperand(CE, false); |
| 1248 | } else |
| 1249 | assert(0 && "Unsupported aliasee"); |
| 1250 | } |
| 1251 | |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1252 | printInfoComment(*GA); |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 1253 | Out << '\n'; |
Anton Korobeynikov | a97b694 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 1256 | void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) { |
Reid Spencer | e7e9671 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 1257 | // Print the types. |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 1258 | for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end(); |
| 1259 | TI != TE; ++TI) { |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 1260 | Out << '\t'; |
| 1261 | PrintLLVMName(Out, &TI->first[0], TI->first.size(), LocalPrefix); |
| 1262 | Out << " = type "; |
Reid Spencer | e7e9671 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 1263 | |
| 1264 | // Make sure we print out at least one level of the type structure, so |
| 1265 | // that we do not get %FILE = type %FILE |
| 1266 | // |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1267 | printTypeAtLeastOneLevel(TI->second); |
| 1268 | Out << '\n'; |
Reid Spencer | e7e9671 | 2004-05-25 08:53:40 +0000 | [diff] [blame] | 1269 | } |
Reid Spencer | 32af9e8 | 2007-01-06 07:24:44 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 1272 | /// printFunction - Print all aspects of a function. |
| 1273 | /// |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1274 | void AssemblyWriter::printFunction(const Function *F) { |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1275 | // Print out the return type and name. |
| 1276 | Out << '\n'; |
Chris Lattner | 379a8d2 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 1277 | |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1278 | if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, Out); |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 1279 | |
Reid Spencer | 5301e7c | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 1280 | if (F->isDeclaration()) |
Chris Lattner | 10f03a6 | 2007-08-19 22:15:26 +0000 | [diff] [blame] | 1281 | Out << "declare "; |
| 1282 | else |
Reid Spencer | 7ce2d2a | 2006-12-29 20:29:48 +0000 | [diff] [blame] | 1283 | Out << "define "; |
Chris Lattner | 3a36d2c | 2008-08-19 05:06:27 +0000 | [diff] [blame] | 1284 | |
| 1285 | PrintLinkage(F->getLinkage(), Out); |
| 1286 | PrintVisibility(F->getVisibility(), Out); |
Chris Lattner | 379a8d2 | 2003-04-16 20:28:45 +0000 | [diff] [blame] | 1287 | |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1288 | // Print the calling convention. |
| 1289 | switch (F->getCallingConv()) { |
| 1290 | case CallingConv::C: break; // default |
Anton Korobeynikov | 3c5b3df | 2006-09-20 22:03:51 +0000 | [diff] [blame] | 1291 | case CallingConv::Fast: Out << "fastcc "; break; |
| 1292 | case CallingConv::Cold: Out << "coldcc "; break; |
| 1293 | case CallingConv::X86_StdCall: Out << "x86_stdcallcc "; break; |
| 1294 | case CallingConv::X86_FastCall: Out << "x86_fastcallcc "; break; |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1295 | default: Out << "cc" << F->getCallingConv() << " "; break; |
| 1296 | } |
| 1297 | |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1298 | const FunctionType *FT = F->getFunctionType(); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1299 | const AttrListPtr &Attrs = F->getAttributes(); |
Devang Patel | 221fe42 | 2008-09-29 20:49:50 +0000 | [diff] [blame] | 1300 | Attributes RetAttrs = Attrs.getRetAttributes(); |
| 1301 | if (RetAttrs != Attribute::None) |
| 1302 | Out << Attribute::getAsString(Attrs.getRetAttributes()) << ' '; |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 1303 | printType(F->getReturnType()); |
| 1304 | Out << ' '; |
Chris Lattner | edceac3 | 2008-08-17 07:24:08 +0000 | [diff] [blame] | 1305 | if (F->hasName()) |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1306 | PrintLLVMName(Out, F); |
Chris Lattner | 5b33748 | 2003-10-18 05:57:43 +0000 | [diff] [blame] | 1307 | else |
Reid Spencer | 788e317 | 2007-01-26 08:02:52 +0000 | [diff] [blame] | 1308 | Out << "@\"\""; |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1309 | Out << '('; |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 1310 | Machine.incorporateFunction(F); |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1311 | |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1312 | // Loop over the arguments, printing them... |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1313 | |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1314 | unsigned Idx = 1; |
Chris Lattner | 82738fe | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 1315 | if (!F->isDeclaration()) { |
| 1316 | // If this isn't a declaration, print the argument names as well. |
| 1317 | for (Function::const_arg_iterator I = F->arg_begin(), E = F->arg_end(); |
| 1318 | I != E; ++I) { |
| 1319 | // Insert commas as we go... the first arg doesn't get a comma |
| 1320 | if (I != F->arg_begin()) Out << ", "; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1321 | printArgument(I, Attrs.getParamAttributes(Idx)); |
Chris Lattner | 82738fe | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 1322 | Idx++; |
| 1323 | } |
| 1324 | } else { |
| 1325 | // Otherwise, print the types from the function type. |
| 1326 | for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { |
| 1327 | // Insert commas as we go... the first arg doesn't get a comma |
| 1328 | if (i) Out << ", "; |
| 1329 | |
| 1330 | // Output type... |
| 1331 | printType(FT->getParamType(i)); |
| 1332 | |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1333 | Attributes ArgAttrs = Attrs.getParamAttributes(i+1); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1334 | if (ArgAttrs != Attribute::None) |
| 1335 | Out << ' ' << Attribute::getAsString(ArgAttrs); |
Chris Lattner | 82738fe | 2007-04-18 00:57:22 +0000 | [diff] [blame] | 1336 | } |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1337 | } |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1338 | |
| 1339 | // Finish printing arguments... |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1340 | if (FT->isVarArg()) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1341 | if (FT->getNumParams()) Out << ", "; |
| 1342 | Out << "..."; // Output varargs portion of signature! |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1343 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1344 | Out << ')'; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1345 | Attributes FnAttrs = Attrs.getFnAttributes(); |
| 1346 | if (FnAttrs != Attribute::None) |
| 1347 | Out << ' ' << Attribute::getAsString(Attrs.getFnAttributes()); |
Chris Lattner | 4b96c54 | 2005-11-12 00:10:19 +0000 | [diff] [blame] | 1348 | if (F->hasSection()) |
| 1349 | Out << " section \"" << F->getSection() << '"'; |
Chris Lattner | f8a974d | 2005-11-06 06:48:53 +0000 | [diff] [blame] | 1350 | if (F->getAlignment()) |
| 1351 | Out << " align " << F->getAlignment(); |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1352 | if (F->hasGC()) |
| 1353 | Out << " gc \"" << F->getGC() << '"'; |
Reid Spencer | 5301e7c | 2007-01-30 20:08:39 +0000 | [diff] [blame] | 1354 | if (F->isDeclaration()) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1355 | Out << "\n"; |
Chris Lattner | b2f02e5 | 2002-05-06 03:00:40 +0000 | [diff] [blame] | 1356 | } else { |
Chris Lattner | d5fbc8f | 2008-04-21 06:12:55 +0000 | [diff] [blame] | 1357 | Out << " {"; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1358 | |
Chris Lattner | 6915f8f | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 1359 | // Output all of its basic blocks... for the function |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1360 | for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I) |
| 1361 | printBasicBlock(I); |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1362 | |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1363 | Out << "}\n"; |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Reid Spencer | 16f2f7f | 2004-05-26 07:18:52 +0000 | [diff] [blame] | 1366 | Machine.purgeFunction(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1367 | } |
| 1368 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 1369 | /// printArgument - This member is called for every argument that is passed into |
| 1370 | /// the function. Simply print it out |
| 1371 | /// |
Dale Johannesen | 89268bc | 2008-02-19 21:38:47 +0000 | [diff] [blame] | 1372 | void AssemblyWriter::printArgument(const Argument *Arg, |
Devang Patel | ba3fa6c | 2008-09-23 23:03:40 +0000 | [diff] [blame] | 1373 | Attributes Attrs) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1374 | // Output type... |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1375 | printType(Arg->getType()); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1376 | |
Duncan Sands | ad0ea2d | 2007-11-27 13:23:08 +0000 | [diff] [blame] | 1377 | // Output parameter attributes list |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1378 | if (Attrs != Attribute::None) |
| 1379 | Out << ' ' << Attribute::getAsString(Attrs); |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1380 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1381 | // Output name, if available... |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1382 | if (Arg->hasName()) { |
| 1383 | Out << ' '; |
| 1384 | PrintLLVMName(Out, Arg); |
| 1385 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 1388 | /// printBasicBlock - This member is called for each basic block in a method. |
| 1389 | /// |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1390 | void AssemblyWriter::printBasicBlock(const BasicBlock *BB) { |
Nick Lewycky | 4d43d3c | 2008-04-25 16:53:59 +0000 | [diff] [blame] | 1391 | if (BB->hasName()) { // Print out the label if it exists... |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1392 | Out << "\n"; |
Chris Lattner | 1508d3f | 2008-08-19 05:16:28 +0000 | [diff] [blame] | 1393 | PrintLLVMName(Out, BB->getNameStart(), BB->getNameLen(), LabelPrefix); |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1394 | Out << ':'; |
Nick Lewycky | 4d43d3c | 2008-04-25 16:53:59 +0000 | [diff] [blame] | 1395 | } else if (!BB->use_empty()) { // Don't print block # of no uses... |
Chris Lattner | 67bec13 | 2008-04-21 04:20:33 +0000 | [diff] [blame] | 1396 | Out << "\n; <label>:"; |
Chris Lattner | 5e04332 | 2007-01-11 03:54:27 +0000 | [diff] [blame] | 1397 | int Slot = Machine.getLocalSlot(BB); |
Chris Lattner | 757ee0b | 2004-06-09 19:41:19 +0000 | [diff] [blame] | 1398 | if (Slot != -1) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1399 | Out << Slot; |
Chris Lattner | 757ee0b | 2004-06-09 19:41:19 +0000 | [diff] [blame] | 1400 | else |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1401 | Out << "<badref>"; |
Chris Lattner | 58185f2 | 2002-10-02 19:38:55 +0000 | [diff] [blame] | 1402 | } |
Chris Lattner | 2447ef5 | 2003-11-20 00:09:43 +0000 | [diff] [blame] | 1403 | |
| 1404 | if (BB->getParent() == 0) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1405 | Out << "\t\t; Error: Block without parent!"; |
Chris Lattner | ff834c0 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 1406 | else if (BB != &BB->getParent()->getEntryBlock()) { // Not the entry block? |
| 1407 | // Output predecessors for the block... |
| 1408 | Out << "\t\t;"; |
| 1409 | pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB); |
| 1410 | |
| 1411 | if (PI == PE) { |
| 1412 | Out << " No predecessors!"; |
| 1413 | } else { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1414 | Out << " preds = "; |
Chris Lattner | ff834c0 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 1415 | writeOperand(*PI, false); |
| 1416 | for (++PI; PI != PE; ++PI) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1417 | Out << ", "; |
Chris Lattner | 78e2e8b | 2006-12-06 06:24:27 +0000 | [diff] [blame] | 1418 | writeOperand(*PI, false); |
Chris Lattner | 00211f1 | 2003-11-16 22:59:57 +0000 | [diff] [blame] | 1419 | } |
Chris Lattner | 58185f2 | 2002-10-02 19:38:55 +0000 | [diff] [blame] | 1420 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1421 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1422 | |
Chris Lattner | ff834c0 | 2008-04-22 02:45:44 +0000 | [diff] [blame] | 1423 | Out << "\n"; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1424 | |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1425 | if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out); |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 1426 | |
Chris Lattner | fee714f | 2001-09-07 16:36:04 +0000 | [diff] [blame] | 1427 | // Output all of the instructions in the basic block... |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1428 | for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
| 1429 | printInstruction(*I); |
Chris Lattner | 96cdd27 | 2004-03-08 18:51:45 +0000 | [diff] [blame] | 1430 | |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1431 | if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1434 | |
Misha Brukman | c566ca36 | 2004-03-02 00:22:19 +0000 | [diff] [blame] | 1435 | /// printInfoComment - Print a little comment after the instruction indicating |
| 1436 | /// which slot it occupies. |
| 1437 | /// |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1438 | void AssemblyWriter::printInfoComment(const Value &V) { |
| 1439 | if (V.getType() != Type::VoidTy) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1440 | Out << "\t\t; <"; |
Chris Lattner | 585297e8 | 2008-08-19 05:26:17 +0000 | [diff] [blame] | 1441 | printType(V.getType()); |
| 1442 | Out << '>'; |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1443 | |
Chris Lattner | b25e5ea | 2008-08-29 17:19:30 +0000 | [diff] [blame] | 1444 | if (!V.hasName() && !isa<Instruction>(V)) { |
Chris Lattner | 5e04332 | 2007-01-11 03:54:27 +0000 | [diff] [blame] | 1445 | int SlotNum; |
| 1446 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(&V)) |
| 1447 | SlotNum = Machine.getGlobalSlot(GV); |
| 1448 | else |
| 1449 | SlotNum = Machine.getLocalSlot(&V); |
Chris Lattner | 757ee0b | 2004-06-09 19:41:19 +0000 | [diff] [blame] | 1450 | if (SlotNum == -1) |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1451 | Out << ":<badref>"; |
Reid Spencer | 8beac69 | 2004-06-09 15:26:53 +0000 | [diff] [blame] | 1452 | else |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1453 | Out << ':' << SlotNum; // Print out the def slot taken. |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1454 | } |
Chris Lattner | b6c21db | 2005-02-01 01:24:01 +0000 | [diff] [blame] | 1455 | Out << " [#uses=" << V.getNumUses() << ']'; // Output # uses |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
Reid Spencer | e7141c8 | 2006-08-28 01:02:49 +0000 | [diff] [blame] | 1459 | // This member is called for each Instruction in a function.. |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1460 | void AssemblyWriter::printInstruction(const Instruction &I) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1461 | if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, Out); |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 1462 | |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1463 | Out << '\t'; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1464 | |
| 1465 | // Print out name if it exists... |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1466 | if (I.hasName()) { |
| 1467 | PrintLLVMName(Out, &I); |
| 1468 | Out << " = "; |
Chris Lattner | b25e5ea | 2008-08-29 17:19:30 +0000 | [diff] [blame] | 1469 | } else if (I.getType() != Type::VoidTy) { |
| 1470 | // Print out the def slot taken. |
| 1471 | int SlotNum = Machine.getLocalSlot(&I); |
| 1472 | if (SlotNum == -1) |
| 1473 | Out << "<badref> = "; |
| 1474 | else |
| 1475 | Out << '%' << SlotNum << " = "; |
Chris Lattner | 033935d | 2008-08-17 04:40:13 +0000 | [diff] [blame] | 1476 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1477 | |
Chris Lattner | 0603845 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1478 | // If this is a volatile load or store, print out the volatile marker. |
Chris Lattner | 504f924 | 2003-09-08 17:45:59 +0000 | [diff] [blame] | 1479 | if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) || |
Chris Lattner | 0603845 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1480 | (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile())) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1481 | Out << "volatile "; |
Chris Lattner | 0603845 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 1482 | } else if (isa<CallInst>(I) && cast<CallInst>(I).isTailCall()) { |
| 1483 | // If this is a call, check if it's a tail call. |
| 1484 | Out << "tail "; |
| 1485 | } |
Chris Lattner | 504f924 | 2003-09-08 17:45:59 +0000 | [diff] [blame] | 1486 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1487 | // Print out the opcode... |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1488 | Out << I.getOpcodeName(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1489 | |
Reid Spencer | 45e5239 | 2006-12-03 06:27:29 +0000 | [diff] [blame] | 1490 | // Print out the compare instruction predicates |
Nate Begeman | d219570 | 2008-05-12 19:01:56 +0000 | [diff] [blame] | 1491 | if (const CmpInst *CI = dyn_cast<CmpInst>(&I)) |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1492 | Out << ' ' << getPredicateText(CI->getPredicate()); |
Reid Spencer | 45e5239 | 2006-12-03 06:27:29 +0000 | [diff] [blame] | 1493 | |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1494 | // Print out the type of the operands... |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1495 | const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1496 | |
| 1497 | // Special case conditional branches to swizzle the condition out to the front |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1498 | if (isa<BranchInst>(I) && I.getNumOperands() > 1) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1499 | Out << ' '; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1500 | writeOperand(I.getOperand(2), true); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1501 | Out << ", "; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1502 | writeOperand(Operand, true); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1503 | Out << ", "; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1504 | writeOperand(I.getOperand(1), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1505 | |
Chris Lattner | 8d48df2 | 2002-04-13 18:34:38 +0000 | [diff] [blame] | 1506 | } else if (isa<SwitchInst>(I)) { |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1507 | // Special case switch statement to get formatting nice and correct... |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1508 | Out << ' '; |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1509 | writeOperand(Operand , true); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1510 | Out << ", "; |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1511 | writeOperand(I.getOperand(1), true); |
| 1512 | Out << " ["; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1513 | |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1514 | for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; op += 2) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1515 | Out << "\n\t\t"; |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1516 | writeOperand(I.getOperand(op ), true); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1517 | Out << ", "; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1518 | writeOperand(I.getOperand(op+1), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1519 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1520 | Out << "\n\t]"; |
Chris Lattner | da55810 | 2001-10-02 03:41:24 +0000 | [diff] [blame] | 1521 | } else if (isa<PHINode>(I)) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1522 | Out << ' '; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1523 | printType(I.getType()); |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1524 | Out << ' '; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1525 | |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1526 | for (unsigned op = 0, Eop = I.getNumOperands(); op < Eop; op += 2) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1527 | if (op) Out << ", "; |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1528 | Out << "[ "; |
| 1529 | writeOperand(I.getOperand(op ), false); Out << ", "; |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1530 | writeOperand(I.getOperand(op+1), false); Out << " ]"; |
Chris Lattner | 931ef3b | 2001-06-11 15:04:20 +0000 | [diff] [blame] | 1531 | } |
Dan Gohman | a76f0f7 | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 1532 | } else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&I)) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1533 | Out << ' '; |
Dan Gohman | a76f0f7 | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 1534 | writeOperand(I.getOperand(0), true); |
| 1535 | for (const unsigned *i = EVI->idx_begin(), *e = EVI->idx_end(); i != e; ++i) |
| 1536 | Out << ", " << *i; |
| 1537 | } else if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&I)) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1538 | Out << ' '; |
| 1539 | writeOperand(I.getOperand(0), true); Out << ", "; |
Dan Gohman | a76f0f7 | 2008-05-31 19:12:39 +0000 | [diff] [blame] | 1540 | writeOperand(I.getOperand(1), true); |
| 1541 | for (const unsigned *i = IVI->idx_begin(), *e = IVI->idx_end(); i != e; ++i) |
| 1542 | Out << ", " << *i; |
Devang Patel | 59643e5 | 2008-02-23 00:35:18 +0000 | [diff] [blame] | 1543 | } else if (isa<ReturnInst>(I) && !Operand) { |
| 1544 | Out << " void"; |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1545 | } else if (const CallInst *CI = dyn_cast<CallInst>(&I)) { |
| 1546 | // Print the calling convention being used. |
| 1547 | switch (CI->getCallingConv()) { |
| 1548 | case CallingConv::C: break; // default |
Chris Lattner | 29d2085 | 2006-05-19 21:58:52 +0000 | [diff] [blame] | 1549 | case CallingConv::Fast: Out << " fastcc"; break; |
| 1550 | case CallingConv::Cold: Out << " coldcc"; break; |
Chris Lattner | f527037 | 2007-11-18 18:32:16 +0000 | [diff] [blame] | 1551 | case CallingConv::X86_StdCall: Out << " x86_stdcallcc"; break; |
| 1552 | case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break; |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1553 | default: Out << " cc" << CI->getCallingConv(); break; |
| 1554 | } |
| 1555 | |
Reid Spencer | 1517de3 | 2007-04-09 06:10:42 +0000 | [diff] [blame] | 1556 | const PointerType *PTy = cast<PointerType>(Operand->getType()); |
| 1557 | const FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); |
| 1558 | const Type *RetTy = FTy->getReturnType(); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1559 | const AttrListPtr &PAL = CI->getAttributes(); |
Chris Lattner | 2f2d947 | 2001-11-06 21:28:12 +0000 | [diff] [blame] | 1560 | |
Devang Patel | 221fe42 | 2008-09-29 20:49:50 +0000 | [diff] [blame] | 1561 | if (PAL.getRetAttributes() != Attribute::None) |
| 1562 | Out << ' ' << Attribute::getAsString(PAL.getRetAttributes()); |
| 1563 | |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1564 | // If possible, print out the short form of the call instruction. We can |
Chris Lattner | 6915f8f | 2002-04-07 22:49:37 +0000 | [diff] [blame] | 1565 | // only do this if the first argument is a pointer to a nonvararg function, |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1566 | // and if the return type is not a pointer to a function. |
Chris Lattner | 2f2d947 | 2001-11-06 21:28:12 +0000 | [diff] [blame] | 1567 | // |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1568 | Out << ' '; |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1569 | if (!FTy->isVarArg() && |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1570 | (!isa<PointerType>(RetTy) || |
Chris Lattner | d9a36a6 | 2002-07-25 20:58:51 +0000 | [diff] [blame] | 1571 | !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1572 | printType(RetTy); |
| 1573 | Out << ' '; |
Chris Lattner | 2f2d947 | 2001-11-06 21:28:12 +0000 | [diff] [blame] | 1574 | writeOperand(Operand, false); |
| 1575 | } else { |
| 1576 | writeOperand(Operand, true); |
| 1577 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1578 | Out << '('; |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1579 | for (unsigned op = 1, Eop = I.getNumOperands(); op < Eop; ++op) { |
| 1580 | if (op > 1) |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1581 | Out << ", "; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1582 | writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op)); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1583 | } |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1584 | Out << ')'; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1585 | if (PAL.getFnAttributes() != Attribute::None) |
| 1586 | Out << ' ' << Attribute::getAsString(PAL.getFnAttributes()); |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1587 | } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) { |
Reid Spencer | 1517de3 | 2007-04-09 06:10:42 +0000 | [diff] [blame] | 1588 | const PointerType *PTy = cast<PointerType>(Operand->getType()); |
| 1589 | const FunctionType *FTy = cast<FunctionType>(PTy->getElementType()); |
| 1590 | const Type *RetTy = FTy->getReturnType(); |
Devang Patel | 4c758ea | 2008-09-25 21:00:45 +0000 | [diff] [blame] | 1591 | const AttrListPtr &PAL = II->getAttributes(); |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1592 | |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1593 | // Print the calling convention being used. |
| 1594 | switch (II->getCallingConv()) { |
| 1595 | case CallingConv::C: break; // default |
Chris Lattner | 29d2085 | 2006-05-19 21:58:52 +0000 | [diff] [blame] | 1596 | case CallingConv::Fast: Out << " fastcc"; break; |
| 1597 | case CallingConv::Cold: Out << " coldcc"; break; |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1598 | case CallingConv::X86_StdCall: Out << " x86_stdcallcc"; break; |
| 1599 | case CallingConv::X86_FastCall: Out << " x86_fastcallcc"; break; |
Chris Lattner | f7b6d31 | 2005-05-06 20:26:43 +0000 | [diff] [blame] | 1600 | default: Out << " cc" << II->getCallingConv(); break; |
| 1601 | } |
| 1602 | |
Devang Patel | 221fe42 | 2008-09-29 20:49:50 +0000 | [diff] [blame] | 1603 | if (PAL.getRetAttributes() != Attribute::None) |
| 1604 | Out << ' ' << Attribute::getAsString(PAL.getRetAttributes()); |
| 1605 | |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1606 | // If possible, print out the short form of the invoke instruction. We can |
| 1607 | // only do this if the first argument is a pointer to a nonvararg function, |
| 1608 | // and if the return type is not a pointer to a function. |
| 1609 | // |
Dan Gohman | c7e00ba | 2008-10-15 18:02:08 +0000 | [diff] [blame] | 1610 | Out << ' '; |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1611 | if (!FTy->isVarArg() && |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1612 | (!isa<PointerType>(RetTy) || |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1613 | !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) { |
Dan Gohman | c7e00ba | 2008-10-15 18:02:08 +0000 | [diff] [blame] | 1614 | printType(RetTy); |
| 1615 | Out << ' '; |
Chris Lattner | 463d6a5 | 2003-08-05 15:34:45 +0000 | [diff] [blame] | 1616 | writeOperand(Operand, false); |
| 1617 | } else { |
| 1618 | writeOperand(Operand, true); |
| 1619 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1620 | Out << '('; |
Reid Spencer | 8c4914c | 2006-12-31 05:24:50 +0000 | [diff] [blame] | 1621 | for (unsigned op = 3, Eop = I.getNumOperands(); op < Eop; ++op) { |
| 1622 | if (op > 3) |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1623 | Out << ", "; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1624 | writeParamOperand(I.getOperand(op), PAL.getParamAttributes(op-2)); |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1627 | Out << ')'; |
Devang Patel | a05633e | 2008-09-26 22:53:05 +0000 | [diff] [blame] | 1628 | if (PAL.getFnAttributes() != Attribute::None) |
| 1629 | Out << ' ' << Attribute::getAsString(PAL.getFnAttributes()); |
| 1630 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1631 | Out << "\n\t\t\tto "; |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1632 | writeOperand(II->getNormalDest(), true); |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1633 | Out << " unwind "; |
Chris Lattner | fae8ab3 | 2004-02-08 21:44:31 +0000 | [diff] [blame] | 1634 | writeOperand(II->getUnwindDest(), true); |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1635 | |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1636 | } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(&I)) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1637 | Out << ' '; |
Chris Lattner | 8d48df2 | 2002-04-13 18:34:38 +0000 | [diff] [blame] | 1638 | printType(AI->getType()->getElementType()); |
| 1639 | if (AI->isArrayAllocation()) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1640 | Out << ", "; |
Chris Lattner | 8d48df2 | 2002-04-13 18:34:38 +0000 | [diff] [blame] | 1641 | writeOperand(AI->getArraySize(), true); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1642 | } |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 1643 | if (AI->getAlignment()) { |
Chris Lattner | 7aeee3a | 2005-11-05 21:20:34 +0000 | [diff] [blame] | 1644 | Out << ", align " << AI->getAlignment(); |
Nate Begeman | 848622f | 2005-11-05 09:21:28 +0000 | [diff] [blame] | 1645 | } |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1646 | } else if (isa<CastInst>(I)) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1647 | if (Operand) { |
| 1648 | Out << ' '; |
| 1649 | writeOperand(Operand, true); // Work with broken code |
| 1650 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1651 | Out << " to "; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1652 | printType(I.getType()); |
Chris Lattner | 5b33748 | 2003-10-18 05:57:43 +0000 | [diff] [blame] | 1653 | } else if (isa<VAArgInst>(I)) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1654 | if (Operand) { |
| 1655 | Out << ' '; |
| 1656 | writeOperand(Operand, true); // Work with broken code |
| 1657 | } |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1658 | Out << ", "; |
Chris Lattner | f70da10 | 2003-05-08 02:44:12 +0000 | [diff] [blame] | 1659 | printType(I.getType()); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1660 | } else if (Operand) { // Print the normal way... |
| 1661 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1662 | // PrintAllTypes - Instructions who have operands of all the same type |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1663 | // omit the type from all but the first operand. If the instruction has |
| 1664 | // different type operands (for example br), then they are all printed. |
| 1665 | bool PrintAllTypes = false; |
| 1666 | const Type *TheType = Operand->getType(); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1667 | |
Reid Spencer | 0cdd04f | 2007-02-02 13:54:55 +0000 | [diff] [blame] | 1668 | // Select, Store and ShuffleVector always print all types. |
Devang Patel | ce556d9 | 2008-03-04 22:05:14 +0000 | [diff] [blame] | 1669 | if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) |
| 1670 | || isa<ReturnInst>(I)) { |
Chris Lattner | deccfaf | 2003-04-16 20:20:02 +0000 | [diff] [blame] | 1671 | PrintAllTypes = true; |
| 1672 | } else { |
| 1673 | for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) { |
| 1674 | Operand = I.getOperand(i); |
| 1675 | if (Operand->getType() != TheType) { |
| 1676 | PrintAllTypes = true; // We have differing types! Print them all! |
| 1677 | break; |
| 1678 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1679 | } |
| 1680 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1681 | |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1682 | if (!PrintAllTypes) { |
Misha Brukman | a6619a9 | 2004-06-21 21:53:56 +0000 | [diff] [blame] | 1683 | Out << ' '; |
Chris Lattner | deccfaf | 2003-04-16 20:20:02 +0000 | [diff] [blame] | 1684 | printType(TheType); |
Chris Lattner | 7bfee41 | 2001-10-29 16:05:51 +0000 | [diff] [blame] | 1685 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1686 | |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1687 | Out << ' '; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1688 | for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) { |
Dan Gohman | 81313fd | 2008-09-14 17:21:12 +0000 | [diff] [blame] | 1689 | if (i) Out << ", "; |
Chris Lattner | 113f4f4 | 2002-06-25 16:13:24 +0000 | [diff] [blame] | 1690 | writeOperand(I.getOperand(i), PrintAllTypes); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1691 | } |
| 1692 | } |
Christopher Lamb | 8448570 | 2007-04-22 19:24:39 +0000 | [diff] [blame] | 1693 | |
| 1694 | // Print post operand alignment for load/store |
| 1695 | if (isa<LoadInst>(I) && cast<LoadInst>(I).getAlignment()) { |
| 1696 | Out << ", align " << cast<LoadInst>(I).getAlignment(); |
| 1697 | } else if (isa<StoreInst>(I) && cast<StoreInst>(I).getAlignment()) { |
| 1698 | Out << ", align " << cast<StoreInst>(I).getAlignment(); |
| 1699 | } |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1700 | |
Chris Lattner | 862e338 | 2001-10-13 06:42:36 +0000 | [diff] [blame] | 1701 | printInfoComment(I); |
Chris Lattner | 82ff923 | 2008-08-23 22:52:27 +0000 | [diff] [blame] | 1702 | Out << '\n'; |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | |
| 1706 | //===----------------------------------------------------------------------===// |
| 1707 | // External Interface declarations |
| 1708 | //===----------------------------------------------------------------------===// |
| 1709 | |
Chris Lattner | 8339f7d | 2003-10-30 23:41:03 +0000 | [diff] [blame] | 1710 | void Module::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const { |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1711 | raw_os_ostream OS(o); |
| 1712 | print(OS, AAW); |
| 1713 | } |
| 1714 | void Module::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const { |
Chris Lattner | e36fd8a | 2008-08-19 04:26:57 +0000 | [diff] [blame] | 1715 | SlotTracker SlotTable(this); |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1716 | AssemblyWriter W(OS, SlotTable, this, AAW); |
Chris Lattner | c0b4c7b | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 1717 | W.write(this); |
Chris Lattner | 2f7c963 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 1720 | void Type::print(std::ostream &o) const { |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1721 | raw_os_ostream OS(o); |
| 1722 | print(OS); |
| 1723 | } |
| 1724 | |
| 1725 | void Type::print(raw_ostream &o) const { |
Chris Lattner | c0b4c7b | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 1726 | if (this == 0) |
| 1727 | o << "<null Type>"; |
| 1728 | else |
| 1729 | o << getDescription(); |
| 1730 | } |
| 1731 | |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1732 | void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const { |
| 1733 | if (this == 0) { |
| 1734 | OS << "printing a <null> value\n"; |
| 1735 | return; |
| 1736 | } |
| 1737 | |
| 1738 | if (const Instruction *I = dyn_cast<Instruction>(this)) { |
| 1739 | const Function *F = I->getParent() ? I->getParent()->getParent() : 0; |
| 1740 | SlotTracker SlotTable(F); |
| 1741 | AssemblyWriter W(OS, SlotTable, F ? F->getParent() : 0, AAW); |
| 1742 | W.write(I); |
| 1743 | } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(this)) { |
| 1744 | SlotTracker SlotTable(BB->getParent()); |
| 1745 | AssemblyWriter W(OS, SlotTable, |
| 1746 | BB->getParent() ? BB->getParent()->getParent() : 0, AAW); |
| 1747 | W.write(BB); |
| 1748 | } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(this)) { |
| 1749 | SlotTracker SlotTable(GV->getParent()); |
| 1750 | AssemblyWriter W(OS, SlotTable, GV->getParent(), 0); |
| 1751 | W.write(GV); |
| 1752 | } else if (const Constant *C = dyn_cast<Constant>(this)) { |
Dan Gohman | fbd67be | 2008-10-01 15:09:37 +0000 | [diff] [blame] | 1753 | OS << C->getType()->getDescription() << ' '; |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1754 | std::map<const Type *, std::string> TypeTable; |
| 1755 | WriteConstantInt(OS, C, TypeTable, 0); |
| 1756 | } else if (const Argument *A = dyn_cast<Argument>(this)) { |
| 1757 | WriteAsOperand(OS, this, true, |
| 1758 | A->getParent() ? A->getParent()->getParent() : 0); |
| 1759 | } else if (isa<InlineAsm>(this)) { |
| 1760 | WriteAsOperand(OS, this, true, 0); |
| 1761 | } else { |
Chris Lattner | d758625 | 2008-08-24 18:33:17 +0000 | [diff] [blame] | 1762 | // FIXME: PseudoSourceValue breaks this! |
| 1763 | //assert(0 && "Unknown value to print out!"); |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | void Value::print(std::ostream &O, AssemblyAnnotationWriter *AAW) const { |
| 1768 | raw_os_ostream OS(O); |
| 1769 | print(OS, AAW); |
Chris Lattner | c0b4c7b | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Chris Lattner | dab94255 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 1772 | // Value::dump - allow easy printing of Values from the debugger. |
Chris Lattner | 820eebc | 2008-08-25 04:55:46 +0000 | [diff] [blame] | 1773 | void Value::dump() const { print(errs()); errs() << '\n'; errs().flush(); } |
Reid Spencer | 5264183 | 2004-05-25 18:14:38 +0000 | [diff] [blame] | 1774 | |
Chris Lattner | dab94255 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 1775 | // Type::dump - allow easy printing of Types from the debugger. |
Chris Lattner | 820eebc | 2008-08-25 04:55:46 +0000 | [diff] [blame] | 1776 | void Type::dump() const { print(errs()); errs() << '\n'; errs().flush(); } |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1777 | |
Chris Lattner | 41a83d9 | 2008-10-01 20:16:19 +0000 | [diff] [blame] | 1778 | // Type::dump - allow easy printing of Types from the debugger. |
| 1779 | // This one uses type names from the given context module |
| 1780 | void Type::dump(const Module *Context) const { |
| 1781 | WriteTypeSymbolic(errs(), this, Context); |
| 1782 | errs() << '\n'; |
| 1783 | errs().flush(); |
| 1784 | } |
| 1785 | |
Chris Lattner | dab94255 | 2008-08-25 17:03:15 +0000 | [diff] [blame] | 1786 | // Module::dump() - Allow printing of Modules from the debugger. |
Chris Lattner | 820eebc | 2008-08-25 04:55:46 +0000 | [diff] [blame] | 1787 | void Module::dump() const { print(errs(), 0); errs().flush(); } |
Chris Lattner | 0c19df4 | 2008-08-23 22:23:09 +0000 | [diff] [blame] | 1788 | |
Chris Lattner | c0b4c7b | 2002-04-08 22:03:40 +0000 | [diff] [blame] | 1789 | |