Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 1 | //===-- PowerPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --===// |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to PowerPC assembly language. This printer is |
Chris Lattner | 83660c5 | 2004-07-28 20:18:53 +0000 | [diff] [blame] | 12 | // the output mechanism used by `llc'. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 13 | // |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 14 | // Documentation at http://developer.apple.com/documentation/DeveloperTools/ |
| 15 | // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 16 | // |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 19 | #define DEBUG_TYPE "asmprinter" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 20 | #include "PowerPC.h" |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 21 | #include "PowerPCTargetMachine.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 22 | #include "llvm/Constants.h" |
| 23 | #include "llvm/DerivedTypes.h" |
| 24 | #include "llvm/Module.h" |
| 25 | #include "llvm/Assembly/Writer.h" |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/AsmPrinter.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineConstantPool.h" |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/ValueTypes.h" |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Mangler.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 32 | #include "llvm/Support/CommandLine.h" |
| 33 | #include "llvm/Support/Debug.h" |
| 34 | #include "llvm/ADT/Statistic.h" |
| 35 | #include "llvm/ADT/StringExtras.h" |
Misha Brukman | 0579449 | 2004-06-24 17:31:42 +0000 | [diff] [blame] | 36 | #include <set> |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 37 | using namespace llvm; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 38 | |
| 39 | namespace { |
| 40 | Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed"); |
| 41 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 42 | struct PPC32AsmPrinter : public AsmPrinter { |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 43 | std::set<std::string> FnStubs, GVStubs, LinkOnceStubs; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 44 | std::set<std::string> Strings; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 45 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 46 | PPC32AsmPrinter(std::ostream &O, TargetMachine &TM) |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 47 | : AsmPrinter(O, TM), LabelNumber(0) {} |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 48 | |
Misha Brukman | cf8d244 | 2004-07-26 16:28:33 +0000 | [diff] [blame] | 49 | /// Unique incrementer for label values for referencing Global values. |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 50 | /// |
Misha Brukman | cf8d244 | 2004-07-26 16:28:33 +0000 | [diff] [blame] | 51 | unsigned LabelNumber; |
| 52 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 53 | virtual const char *getPassName() const { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 54 | return "PowerPC Assembly Printer"; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 57 | PowerPCTargetMachine &getTM() { |
| 58 | return static_cast<PowerPCTargetMachine&>(TM); |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 61 | /// printInstruction - This method is automatically generated by tablegen |
| 62 | /// from the instruction set description. This method returns true if the |
| 63 | /// machine instruction was sufficiently described to print it, otherwise it |
| 64 | /// returns false. |
| 65 | bool printInstruction(const MachineInstr *MI); |
| 66 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 67 | void printMachineInstruction(const MachineInstr *MI); |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 68 | void printOp(const MachineOperand &MO, bool LoadAddrOp = false); |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 69 | |
| 70 | void printOperand(const MachineInstr *MI, unsigned OpNo, MVT::ValueType VT){ |
| 71 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 72 | if (MO.getType() == MachineOperand::MO_MachineRegister) { |
| 73 | assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??"); |
| 74 | O << LowercaseString(TM.getRegisterInfo()->get(MO.getReg()).Name); |
Chris Lattner | 0ea3171 | 2004-08-15 05:46:14 +0000 | [diff] [blame] | 75 | } else if (MO.isImmediate()) { |
| 76 | O << MO.getImmedValue(); |
Chris Lattner | 7bb424f | 2004-08-14 23:27:29 +0000 | [diff] [blame] | 77 | } else { |
| 78 | printOp(MO); |
| 79 | } |
| 80 | } |
| 81 | |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 82 | void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 83 | MVT::ValueType VT) { |
| 84 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
Chris Lattner | 12585ba | 2004-08-21 19:11:03 +0000 | [diff] [blame] | 85 | assert(value <= 31 && "Invalid u5imm argument!"); |
Nate Begeman | c330612 | 2004-08-21 05:56:39 +0000 | [diff] [blame] | 86 | O << (unsigned int)value; |
| 87 | } |
Nate Begeman | 07aada8 | 2004-08-30 02:28:06 +0000 | [diff] [blame] | 88 | void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 89 | MVT::ValueType VT) { |
| 90 | unsigned char value = MI->getOperand(OpNo).getImmedValue(); |
| 91 | assert(value <= 63 && "Invalid u6imm argument!"); |
| 92 | O << (unsigned int)value; |
| 93 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 94 | void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 95 | MVT::ValueType VT) { |
| 96 | O << (short)MI->getOperand(OpNo).getImmedValue(); |
| 97 | } |
Chris Lattner | 97b2a2e | 2004-08-15 05:20:16 +0000 | [diff] [blame] | 98 | void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo, |
| 99 | MVT::ValueType VT) { |
| 100 | O << (unsigned short)MI->getOperand(OpNo).getImmedValue(); |
| 101 | } |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 102 | void printBranchOperand(const MachineInstr *MI, unsigned OpNo, |
| 103 | MVT::ValueType VT) { |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 104 | |
| 105 | // Branches can take an immediate operand. This is used by the branch |
| 106 | // selection pass to print $+8, an eight byte displacement from the PC. |
| 107 | if (MI->getOperand(OpNo).isImmediate()) { |
| 108 | O << "$+" << MI->getOperand(OpNo).getImmedValue() << '\n'; |
| 109 | } else { |
| 110 | printOp(MI->getOperand(OpNo)); |
| 111 | } |
Nate Begeman | b7a8f2c | 2004-09-02 08:13:00 +0000 | [diff] [blame] | 112 | } |
| 113 | void printPICLabel(const MachineInstr *MI, unsigned OpNo, |
| 114 | MVT::ValueType VT) { |
| 115 | // FIXME: should probably be converted to cout.width and cout.fill |
| 116 | O << "\"L0000" << LabelNumber << "$pb\"\n"; |
| 117 | O << "\"L0000" << LabelNumber << "$pb\":"; |
| 118 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 119 | void printSymbolHi(const MachineInstr *MI, unsigned OpNo, |
| 120 | MVT::ValueType VT) { |
| 121 | O << "ha16("; |
| 122 | printOp(MI->getOperand(OpNo), true /* LoadAddrOp */); |
| 123 | O << "-\"L0000" << LabelNumber << "$pb\")"; |
| 124 | } |
| 125 | void printSymbolLo(const MachineInstr *MI, unsigned OpNo, |
| 126 | MVT::ValueType VT) { |
| 127 | // FIXME: Because LFS, LFD, and LWZ can be used either with a s16imm or |
| 128 | // a lo16 of a global or constant pool operand, we must handle both here. |
| 129 | // this isn't a great design, but it works for now. |
| 130 | if (MI->getOperand(OpNo).isImmediate()) { |
| 131 | O << (short)MI->getOperand(OpNo).getImmedValue(); |
| 132 | } else { |
| 133 | O << "lo16("; |
| 134 | printOp(MI->getOperand(OpNo), true /* LoadAddrOp */); |
| 135 | O << "-\"L0000" << LabelNumber << "$pb\")"; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | virtual void printConstantPool(MachineConstantPool *MCP) = 0; |
| 140 | virtual bool runOnMachineFunction(MachineFunction &F) = 0; |
| 141 | virtual bool doFinalization(Module &M) = 0; |
| 142 | }; |
| 143 | |
| 144 | // |
| 145 | // |
| 146 | struct DarwinAsmPrinter : public PPC32AsmPrinter { |
| 147 | |
| 148 | DarwinAsmPrinter(std::ostream &O, TargetMachine &TM) |
| 149 | : PPC32AsmPrinter(O, TM) { |
| 150 | CommentString = ";"; |
| 151 | GlobalPrefix = "_"; |
| 152 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 153 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 154 | AlignmentIsInBytes = false; // Alignment is by power of 2. |
| 155 | } |
| 156 | |
| 157 | virtual const char *getPassName() const { |
| 158 | return "Darwin PPC Assembly Printer"; |
| 159 | } |
Chris Lattner | 97b2a2e | 2004-08-15 05:20:16 +0000 | [diff] [blame] | 160 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 161 | void printConstantPool(MachineConstantPool *MCP); |
| 162 | bool runOnMachineFunction(MachineFunction &F); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 163 | bool doFinalization(Module &M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 164 | }; |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 165 | |
| 166 | // |
| 167 | // |
| 168 | struct AIXAsmPrinter : public PPC32AsmPrinter { |
| 169 | /// Map for labels corresponding to global variables |
| 170 | /// |
| 171 | std::map<const GlobalVariable*,std::string> GVToLabelMap; |
| 172 | |
| 173 | AIXAsmPrinter(std::ostream &O, TargetMachine &TM) |
| 174 | : PPC32AsmPrinter(O, TM) { |
| 175 | CommentString = "#"; |
| 176 | GlobalPrefix = "_"; |
| 177 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 178 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 179 | AlignmentIsInBytes = false; // Alignment is by power of 2. |
| 180 | } |
| 181 | |
| 182 | virtual const char *getPassName() const { |
| 183 | return "AIX PPC Assembly Printer"; |
| 184 | } |
| 185 | |
| 186 | void printConstantPool(MachineConstantPool *MCP); |
| 187 | bool runOnMachineFunction(MachineFunction &F); |
| 188 | bool doInitialization(Module &M); |
| 189 | bool doFinalization(Module &M); |
| 190 | }; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 191 | } // end of anonymous namespace |
| 192 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 193 | // SwitchSection - Switch to the specified section of the executable if we are |
| 194 | // not already in it! |
| 195 | // |
| 196 | static void SwitchSection(std::ostream &OS, std::string &CurSection, |
| 197 | const char *NewSection) { |
| 198 | if (CurSection != NewSection) { |
| 199 | CurSection = NewSection; |
| 200 | if (!CurSection.empty()) |
| 201 | OS << "\t" << NewSection << "\n"; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /// isStringCompatible - Can we treat the specified array as a string? |
| 206 | /// Only if it is an array of ubytes or non-negative sbytes. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 207 | /// |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 208 | static bool isStringCompatible(const ConstantArray *CVA) { |
| 209 | const Type *ETy = cast<ArrayType>(CVA->getType())->getElementType(); |
| 210 | if (ETy == Type::UByteTy) return true; |
| 211 | if (ETy != Type::SByteTy) return false; |
| 212 | |
| 213 | for (unsigned i = 0; i < CVA->getNumOperands(); ++i) |
| 214 | if (cast<ConstantSInt>(CVA->getOperand(i))->getValue() < 0) |
| 215 | return false; |
| 216 | |
| 217 | return true; |
| 218 | } |
| 219 | |
| 220 | /// toOctal - Convert the low order bits of X into an octal digit. |
| 221 | /// |
| 222 | static inline char toOctal(int X) { |
| 223 | return (X&7)+'0'; |
| 224 | } |
| 225 | |
| 226 | // Possible states while outputting ASCII strings |
| 227 | namespace { |
| 228 | enum StringSection { |
| 229 | None, |
| 230 | Alpha, |
| 231 | Numeric |
| 232 | }; |
| 233 | } |
| 234 | |
| 235 | /// SwitchStringSection - manage the changes required to output bytes as |
| 236 | /// characters in a string vs. numeric decimal values |
| 237 | /// |
| 238 | static inline void SwitchStringSection(std::ostream &O, StringSection NewSect, |
| 239 | StringSection &Current) { |
| 240 | if (Current == None) { |
| 241 | if (NewSect == Alpha) |
| 242 | O << "\t.byte \""; |
| 243 | else if (NewSect == Numeric) |
| 244 | O << "\t.byte "; |
| 245 | } else if (Current == Alpha) { |
| 246 | if (NewSect == None) |
| 247 | O << "\""; |
| 248 | else if (NewSect == Numeric) |
| 249 | O << "\"\n" |
| 250 | << "\t.byte "; |
| 251 | } else if (Current == Numeric) { |
| 252 | if (NewSect == Alpha) |
| 253 | O << '\n' |
| 254 | << "\t.byte \""; |
| 255 | else if (NewSect == Numeric) |
| 256 | O << ", "; |
| 257 | } |
| 258 | |
| 259 | Current = NewSect; |
| 260 | } |
| 261 | |
| 262 | /// getAsCString - Return the specified array as a C compatible |
| 263 | /// string, only if the predicate isStringCompatible is true. |
| 264 | /// |
| 265 | static void printAsCString(std::ostream &O, const ConstantArray *CVA) { |
| 266 | assert(isStringCompatible(CVA) && "Array is not string compatible!"); |
| 267 | |
| 268 | if (CVA->getNumOperands() == 0) |
| 269 | return; |
| 270 | |
| 271 | StringSection Current = None; |
| 272 | for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i) { |
| 273 | unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue(); |
| 274 | if (C == '"') { |
| 275 | SwitchStringSection(O, Alpha, Current); |
| 276 | O << "\"\""; |
| 277 | } else if (isprint(C)) { |
| 278 | SwitchStringSection(O, Alpha, Current); |
| 279 | O << C; |
| 280 | } else { |
| 281 | SwitchStringSection(O, Numeric, Current); |
| 282 | O << utostr((unsigned)C); |
| 283 | } |
| 284 | } |
| 285 | SwitchStringSection(O, None, Current); |
| 286 | O << '\n'; |
| 287 | } |
| 288 | |
| 289 | /// createDarwinAsmPrinterPass - Returns a pass that prints the PPC assembly |
| 290 | /// code for a MachineFunction to the given output stream, in a format that the |
| 291 | /// Darwin assembler can deal with. |
| 292 | /// |
| 293 | FunctionPass *llvm::createDarwinAsmPrinter(std::ostream &o, TargetMachine &tm) { |
| 294 | return new DarwinAsmPrinter(o, tm); |
| 295 | } |
| 296 | |
| 297 | /// createAIXAsmPrinterPass - Returns a pass that prints the PPC assembly code |
| 298 | /// for a MachineFunction to the given output stream, in a format that the |
| 299 | /// AIX 5L assembler can deal with. |
| 300 | /// |
| 301 | FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, TargetMachine &tm) { |
| 302 | return new AIXAsmPrinter(o, tm); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 305 | // Include the auto-generated portion of the assembly writer |
| 306 | #include "PowerPCGenAsmWriter.inc" |
| 307 | |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 308 | void PPC32AsmPrinter::printOp(const MachineOperand &MO, |
| 309 | bool LoadAddrOp /* = false */) { |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 310 | const MRegisterInfo &RI = *TM.getRegisterInfo(); |
| 311 | int new_symbol; |
| 312 | |
| 313 | switch (MO.getType()) { |
| 314 | case MachineOperand::MO_VirtualRegister: |
| 315 | if (Value *V = MO.getVRegValueOrNull()) { |
| 316 | O << "<" << V->getName() << ">"; |
| 317 | return; |
| 318 | } |
| 319 | // FALLTHROUGH |
| 320 | case MachineOperand::MO_MachineRegister: |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 321 | case MachineOperand::MO_CCRegister: |
Misha Brukman | 7f484a5 | 2004-06-24 23:51:00 +0000 | [diff] [blame] | 322 | O << LowercaseString(RI.get(MO.getReg()).Name); |
| 323 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 324 | |
| 325 | case MachineOperand::MO_SignExtendedImmed: |
Misha Brukman | af313fb | 2004-07-28 00:00:48 +0000 | [diff] [blame] | 326 | case MachineOperand::MO_UnextendedImmed: |
| 327 | std::cerr << "printOp() does not handle immediate values\n"; |
| 328 | abort(); |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 329 | return; |
| 330 | |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 331 | case MachineOperand::MO_PCRelativeDisp: |
| 332 | std::cerr << "Shouldn't use addPCDisp() when building PPC MachineInstrs"; |
| 333 | abort(); |
| 334 | return; |
| 335 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 336 | case MachineOperand::MO_MachineBasicBlock: { |
| 337 | MachineBasicBlock *MBBOp = MO.getMachineBasicBlock(); |
| 338 | O << ".LBB" << Mang->getValueName(MBBOp->getParent()->getFunction()) |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 339 | << "_" << MBBOp->getNumber() << "\t; " |
Misha Brukman | 2bf183c | 2004-06-25 15:42:10 +0000 | [diff] [blame] | 340 | << MBBOp->getBasicBlock()->getName(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 341 | return; |
| 342 | } |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 343 | |
| 344 | case MachineOperand::MO_ConstantPoolIndex: |
| 345 | O << ".CPI" << CurrentFnName << "_" << MO.getConstantPoolIndex(); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 346 | return; |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 347 | |
| 348 | case MachineOperand::MO_ExternalSymbol: |
| 349 | O << MO.getSymbolName(); |
| 350 | return; |
| 351 | |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 352 | case MachineOperand::MO_GlobalAddress: { |
| 353 | GlobalValue *GV = MO.getGlobal(); |
| 354 | std::string Name = Mang->getValueName(GV); |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 355 | |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 356 | // Dynamically-resolved functions need a stub for the function. Be |
| 357 | // wary however not to output $stub for external functions whose addresses |
| 358 | // are taken. Those should be emitted as $non_lazy_ptr below. |
| 359 | Function *F = dyn_cast<Function>(GV); |
| 360 | if (F && F->isExternal() && !LoadAddrOp && |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 361 | getTM().CalledFunctions.count(F)) { |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 362 | FnStubs.insert(Name); |
| 363 | O << "L" << Name << "$stub"; |
| 364 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 365 | } |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 366 | |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 367 | // External global variables need a non-lazily-resolved stub |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 368 | if (GV->isExternal() && getTM().AddressTaken.count(GV)) { |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 369 | GVStubs.insert(Name); |
| 370 | O << "L" << Name << "$non_lazy_ptr"; |
| 371 | return; |
| 372 | } |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 373 | |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 374 | if (F && LoadAddrOp && getTM().AddressTaken.count(GV)) { |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 375 | LinkOnceStubs.insert(Name); |
| 376 | O << "L" << Name << "$non_lazy_ptr"; |
| 377 | return; |
| 378 | } |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 379 | |
| 380 | O << Mang->getValueName(GV); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 381 | return; |
Nate Begeman | b73a711 | 2004-08-13 09:32:01 +0000 | [diff] [blame] | 382 | } |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 383 | |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 384 | default: |
Misha Brukman | 05fcd0c | 2004-07-08 17:58:04 +0000 | [diff] [blame] | 385 | O << "<unknown operand type: " << MO.getType() << ">"; |
Misha Brukman | 22e1207 | 2004-06-25 15:11:34 +0000 | [diff] [blame] | 386 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 390 | /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to |
| 391 | /// the current output stream. |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 392 | /// |
Misha Brukman | f2ccb77 | 2004-08-17 04:55:41 +0000 | [diff] [blame] | 393 | void PPC32AsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 394 | ++EmittedInsts; |
| 395 | if (printInstruction(MI)) |
| 396 | return; // Printer was automatically generated |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 397 | |
| 398 | assert(0 && "Unhandled instruction in asm writer!"); |
| 399 | abort(); |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 400 | return; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 403 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 404 | /// method to print assembly for each instruction. |
| 405 | /// |
| 406 | bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 407 | setupMachineFunction(MF); |
| 408 | O << "\n\n"; |
| 409 | |
| 410 | // Print out constants referenced by the function |
| 411 | printConstantPool(MF.getConstantPool()); |
| 412 | |
| 413 | // Print out labels for the function. |
| 414 | O << "\t.text\n"; |
| 415 | emitAlignment(2); |
| 416 | O << "\t.globl\t" << CurrentFnName << "\n"; |
| 417 | O << CurrentFnName << ":\n"; |
| 418 | |
| 419 | // Print out code for the function. |
| 420 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 421 | I != E; ++I) { |
| 422 | // Print a label for the basic block. |
| 423 | O << ".LBB" << CurrentFnName << "_" << I->getNumber() << ":\t" |
| 424 | << CommentString << " " << I->getBasicBlock()->getName() << "\n"; |
| 425 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 426 | II != E; ++II) { |
| 427 | // Print the assembly for the instruction. |
| 428 | O << "\t"; |
| 429 | printMachineInstruction(II); |
| 430 | } |
| 431 | } |
| 432 | ++LabelNumber; |
| 433 | |
| 434 | // We didn't modify anything. |
| 435 | return false; |
| 436 | } |
| 437 | |
| 438 | /// printConstantPool - Print to the current output stream assembly |
| 439 | /// representations of the constants in the constant pool MCP. This is |
| 440 | /// used to print out constants which have been "spilled to memory" by |
| 441 | /// the code generator. |
| 442 | /// |
| 443 | void DarwinAsmPrinter::printConstantPool(MachineConstantPool *MCP) { |
| 444 | const std::vector<Constant*> &CP = MCP->getConstants(); |
| 445 | const TargetData &TD = TM.getTargetData(); |
| 446 | |
| 447 | if (CP.empty()) return; |
| 448 | |
| 449 | for (unsigned i = 0, e = CP.size(); i != e; ++i) { |
| 450 | O << "\t.const\n"; |
| 451 | emitAlignment(TD.getTypeAlignmentShift(CP[i]->getType())); |
| 452 | O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t" << CommentString |
| 453 | << *CP[i] << "\n"; |
| 454 | emitGlobalConstant(CP[i]); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 458 | bool DarwinAsmPrinter::doFinalization(Module &M) { |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 459 | const TargetData &TD = TM.getTargetData(); |
| 460 | std::string CurSection; |
| 461 | |
| 462 | // Print out module-level global variables here. |
| 463 | for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) |
| 464 | if (I->hasInitializer()) { // External global require no code |
| 465 | O << "\n\n"; |
| 466 | std::string name = Mang->getValueName(I); |
| 467 | Constant *C = I->getInitializer(); |
| 468 | unsigned Size = TD.getTypeSize(C->getType()); |
Chris Lattner | 69d485e | 2004-08-17 19:26:03 +0000 | [diff] [blame] | 469 | unsigned Align = TD.getTypeAlignmentShift(C->getType()); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 470 | |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 471 | if (C->isNullValue() && /* FIXME: Verify correct */ |
| 472 | (I->hasInternalLinkage() || I->hasWeakLinkage())) { |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 473 | SwitchSection(O, CurSection, ".data"); |
| 474 | if (I->hasInternalLinkage()) |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 475 | O << ".lcomm " << name << "," << TD.getTypeSize(C->getType()) |
Chris Lattner | 69d485e | 2004-08-17 19:26:03 +0000 | [diff] [blame] | 476 | << "," << Align; |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 477 | else |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 478 | O << ".comm " << name << "," << TD.getTypeSize(C->getType()); |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 479 | O << "\t\t; "; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 480 | WriteAsOperand(O, I, true, true, &M); |
| 481 | O << "\n"; |
| 482 | } else { |
| 483 | switch (I->getLinkage()) { |
| 484 | case GlobalValue::LinkOnceLinkage: |
Misha Brukman | 97a296f | 2004-07-21 20:11:11 +0000 | [diff] [blame] | 485 | O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n" |
| 486 | << ".weak_definition " << name << '\n' |
| 487 | << ".private_extern " << name << '\n' |
| 488 | << ".section __DATA,__datacoal_nt,coalesced,no_toc\n"; |
| 489 | LinkOnceStubs.insert(name); |
| 490 | break; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 491 | case GlobalValue::WeakLinkage: // FIXME: Verify correct for weak. |
| 492 | // Nonnull linkonce -> weak |
| 493 | O << "\t.weak " << name << "\n"; |
| 494 | SwitchSection(O, CurSection, ""); |
| 495 | O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n"; |
| 496 | break; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 497 | case GlobalValue::AppendingLinkage: |
| 498 | // FIXME: appending linkage variables should go into a section of |
| 499 | // their name or something. For now, just emit them as external. |
| 500 | case GlobalValue::ExternalLinkage: |
| 501 | // If external or appending, declare as a global symbol |
| 502 | O << "\t.globl " << name << "\n"; |
| 503 | // FALL THROUGH |
| 504 | case GlobalValue::InternalLinkage: |
Misha Brukman | 61297ee | 2004-06-29 23:40:57 +0000 | [diff] [blame] | 505 | SwitchSection(O, CurSection, ".data"); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 506 | break; |
| 507 | } |
| 508 | |
Chris Lattner | 69d485e | 2004-08-17 19:26:03 +0000 | [diff] [blame] | 509 | emitAlignment(Align); |
Misha Brukman | 218bec7 | 2004-06-29 17:13:26 +0000 | [diff] [blame] | 510 | O << name << ":\t\t\t\t; "; |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 511 | WriteAsOperand(O, I, true, true, &M); |
| 512 | O << " = "; |
| 513 | WriteAsOperand(O, C, false, false, &M); |
| 514 | O << "\n"; |
| 515 | emitGlobalConstant(C); |
| 516 | } |
| 517 | } |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 518 | |
| 519 | // Output stubs for dynamically-linked functions |
| 520 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
| 521 | i != e; ++i) |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 522 | { |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 523 | O << ".data\n"; |
| 524 | O << ".section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32\n"; |
Chris Lattner | 69d485e | 2004-08-17 19:26:03 +0000 | [diff] [blame] | 525 | emitAlignment(2); |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 526 | O << "L" << *i << "$stub:\n"; |
| 527 | O << "\t.indirect_symbol " << *i << "\n"; |
| 528 | O << "\tmflr r0\n"; |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 529 | O << "\tbcl 20,31,L0$" << *i << "\n"; |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 530 | O << "L0$" << *i << ":\n"; |
| 531 | O << "\tmflr r11\n"; |
| 532 | O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n"; |
| 533 | O << "\tmtlr r0\n"; |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 534 | O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n"; |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 535 | O << "\tmtctr r12\n"; |
| 536 | O << "\tbctr\n"; |
| 537 | O << ".data\n"; |
| 538 | O << ".lazy_symbol_pointer\n"; |
| 539 | O << "L" << *i << "$lazy_ptr:\n"; |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 540 | O << "\t.indirect_symbol " << *i << "\n"; |
| 541 | O << "\t.long dyld_stub_binding_helper\n"; |
Misha Brukman | 46fd00a | 2004-06-24 23:04:11 +0000 | [diff] [blame] | 542 | } |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 543 | |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 544 | O << "\n"; |
| 545 | |
| 546 | // Output stubs for external global variables |
| 547 | if (GVStubs.begin() != GVStubs.end()) |
Misha Brukman | e2eceb5 | 2004-07-23 16:08:20 +0000 | [diff] [blame] | 548 | O << ".data\n.non_lazy_symbol_pointer\n"; |
Misha Brukman | da2b13f | 2004-07-16 20:29:04 +0000 | [diff] [blame] | 549 | for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end(); |
| 550 | i != e; ++i) { |
| 551 | O << "L" << *i << "$non_lazy_ptr:\n"; |
| 552 | O << "\t.indirect_symbol " << *i << "\n"; |
| 553 | O << "\t.long\t0\n"; |
| 554 | } |
| 555 | |
Nate Begeman | e59bf59 | 2004-08-14 22:09:10 +0000 | [diff] [blame] | 556 | // Output stubs for link-once variables |
| 557 | if (LinkOnceStubs.begin() != LinkOnceStubs.end()) |
| 558 | O << ".data\n.align 2\n"; |
| 559 | for (std::set<std::string>::iterator i = LinkOnceStubs.begin(), |
| 560 | e = LinkOnceStubs.end(); i != e; ++i) { |
| 561 | O << "L" << *i << "$non_lazy_ptr:\n" |
| 562 | << "\t.long\t" << *i << '\n'; |
| 563 | } |
| 564 | |
Chris Lattner | a384079 | 2004-08-16 23:25:21 +0000 | [diff] [blame] | 565 | AsmPrinter::doFinalization(M); |
Misha Brukman | 5dfe3a9 | 2004-06-21 16:55:25 +0000 | [diff] [blame] | 566 | return false; // success |
| 567 | } |
Nate Begeman | ed42853 | 2004-09-04 05:00:00 +0000 | [diff] [blame^] | 568 | |
| 569 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 570 | /// method to print assembly for each instruction. |
| 571 | /// |
| 572 | bool AIXAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 573 | CurrentFnName = MF.getFunction()->getName(); |
| 574 | |
| 575 | // Print out constants referenced by the function |
| 576 | printConstantPool(MF.getConstantPool()); |
| 577 | |
| 578 | // Print out header for the function. |
| 579 | O << "\t.csect .text[PR]\n" |
| 580 | << "\t.align 2\n" |
| 581 | << "\t.globl " << CurrentFnName << '\n' |
| 582 | << "\t.globl ." << CurrentFnName << '\n' |
| 583 | << "\t.csect " << CurrentFnName << "[DS],3\n" |
| 584 | << CurrentFnName << ":\n" |
| 585 | << "\t.llong ." << CurrentFnName << ", TOC[tc0], 0\n" |
| 586 | << "\t.csect .text[PR]\n" |
| 587 | << '.' << CurrentFnName << ":\n"; |
| 588 | |
| 589 | // Print out code for the function. |
| 590 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 591 | I != E; ++I) { |
| 592 | // Print a label for the basic block. |
| 593 | O << "LBB" << CurrentFnName << "_" << I->getNumber() << ":\t# " |
| 594 | << I->getBasicBlock()->getName() << "\n"; |
| 595 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 596 | II != E; ++II) { |
| 597 | // Print the assembly for the instruction. |
| 598 | O << "\t"; |
| 599 | printMachineInstruction(II); |
| 600 | } |
| 601 | } |
| 602 | ++LabelNumber; |
| 603 | |
| 604 | O << "LT.." << CurrentFnName << ":\n" |
| 605 | << "\t.long 0\n" |
| 606 | << "\t.byte 0,0,32,65,128,0,0,0\n" |
| 607 | << "\t.long LT.." << CurrentFnName << "-." << CurrentFnName << '\n' |
| 608 | << "\t.short 3\n" |
| 609 | << "\t.byte \"" << CurrentFnName << "\"\n" |
| 610 | << "\t.align 2\n"; |
| 611 | |
| 612 | // We didn't modify anything. |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | /// printConstantPool - Print to the current output stream assembly |
| 617 | /// representations of the constants in the constant pool MCP. This is |
| 618 | /// used to print out constants which have been "spilled to memory" by |
| 619 | /// the code generator. |
| 620 | /// |
| 621 | void AIXAsmPrinter::printConstantPool(MachineConstantPool *MCP) { |
| 622 | const std::vector<Constant*> &CP = MCP->getConstants(); |
| 623 | const TargetData &TD = TM.getTargetData(); |
| 624 | |
| 625 | if (CP.empty()) return; |
| 626 | |
| 627 | for (unsigned i = 0, e = CP.size(); i != e; ++i) { |
| 628 | O << "\t.const\n"; |
| 629 | O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType()) |
| 630 | << "\n"; |
| 631 | O << ".CPI" << CurrentFnName << "_" << i << ":\t\t\t\t\t;" |
| 632 | << *CP[i] << "\n"; |
| 633 | emitGlobalConstant(CP[i]); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | bool AIXAsmPrinter::doInitialization(Module &M) { |
| 638 | const TargetData &TD = TM.getTargetData(); |
| 639 | std::string CurSection; |
| 640 | |
| 641 | O << "\t.machine \"ppc64\"\n" |
| 642 | << "\t.toc\n" |
| 643 | << "\t.csect .text[PR]\n"; |
| 644 | |
| 645 | // Print out module-level global variables |
| 646 | for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) { |
| 647 | if (!I->hasInitializer()) |
| 648 | continue; |
| 649 | |
| 650 | std::string Name = I->getName(); |
| 651 | Constant *C = I->getInitializer(); |
| 652 | // N.B.: We are defaulting to writable strings |
| 653 | if (I->hasExternalLinkage()) { |
| 654 | O << "\t.globl " << Name << '\n' |
| 655 | << "\t.csect .data[RW],3\n"; |
| 656 | } else { |
| 657 | O << "\t.csect _global.rw_c[RW],3\n"; |
| 658 | } |
| 659 | O << Name << ":\n"; |
| 660 | emitGlobalConstant(C); |
| 661 | } |
| 662 | |
| 663 | // Output labels for globals |
| 664 | if (M.gbegin() != M.gend()) O << "\t.toc\n"; |
| 665 | for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) { |
| 666 | const GlobalVariable *GV = I; |
| 667 | // Do not output labels for unused variables |
| 668 | if (GV->isExternal() && GV->use_begin() == GV->use_end()) |
| 669 | continue; |
| 670 | |
| 671 | std::string Name = GV->getName(); |
| 672 | std::string Label = "LC.." + utostr(LabelNumber++); |
| 673 | GVToLabelMap[GV] = Label; |
| 674 | O << Label << ":\n" |
| 675 | << "\t.tc " << Name << "[TC]," << Name; |
| 676 | if (GV->isExternal()) O << "[RW]"; |
| 677 | O << '\n'; |
| 678 | } |
| 679 | |
| 680 | Mang = new Mangler(M, "."); |
| 681 | return false; // success |
| 682 | } |
| 683 | |
| 684 | bool AIXAsmPrinter::doFinalization(Module &M) { |
| 685 | const TargetData &TD = TM.getTargetData(); |
| 686 | // Print out module-level global variables |
| 687 | for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) { |
| 688 | if (I->hasInitializer() || I->hasExternalLinkage()) |
| 689 | continue; |
| 690 | |
| 691 | std::string Name = I->getName(); |
| 692 | if (I->hasInternalLinkage()) { |
| 693 | O << "\t.lcomm " << Name << ",16,_global.bss_c"; |
| 694 | } else { |
| 695 | O << "\t.comm " << Name << "," << TD.getTypeSize(I->getType()) |
| 696 | << "," << log2((unsigned)TD.getTypeAlignment(I->getType())); |
| 697 | } |
| 698 | O << "\t\t# "; |
| 699 | WriteAsOperand(O, I, true, true, &M); |
| 700 | O << "\n"; |
| 701 | } |
| 702 | |
| 703 | O << "_section_.text:\n" |
| 704 | << "\t.csect .data[RW],3\n" |
| 705 | << "\t.llong _section_.text\n"; |
| 706 | |
| 707 | delete Mang; |
| 708 | return false; // success |
| 709 | } |