blob: abbe95a852ece90722789fc72eae9085a27c7255 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00003// 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.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
9//
Misha Brukman05fcd0c2004-07-08 17:58:04 +000010// 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 Lattner83660c52004-07-28 20:18:53 +000012// the output mechanism used by `llc'.
Misha Brukman5dfe3a92004-06-21 16:55:25 +000013//
Misha Brukman05fcd0c2004-07-08 17:58:04 +000014// Documentation at http://developer.apple.com/documentation/DeveloperTools/
15// Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
Misha Brukman218bec72004-06-29 17:13:26 +000016//
Misha Brukman5dfe3a92004-06-21 16:55:25 +000017//===----------------------------------------------------------------------===//
18
Misha Brukman05794492004-06-24 17:31:42 +000019#define DEBUG_TYPE "asmprinter"
Chris Lattner26689592005-10-14 23:51:18 +000020#include "PPC.h"
Chris Lattner16e71f22005-10-14 23:59:06 +000021#include "PPCTargetMachine.h"
Chris Lattner26689592005-10-14 23:51:18 +000022#include "PPCSubtarget.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000023#include "llvm/Constants.h"
24#include "llvm/DerivedTypes.h"
25#include "llvm/Module.h"
26#include "llvm/Assembly/Writer.h"
Chris Lattnera3840792004-08-16 23:25:21 +000027#include "llvm/CodeGen/AsmPrinter.h"
Jim Laskeya7cea6f2006-01-04 13:52:30 +000028#include "llvm/CodeGen/DwarfWriter.h"
Jim Laskeyf5395ce2005-12-16 22:45:29 +000029#include "llvm/CodeGen/MachineDebugInfo.h"
Misha Brukman05794492004-06-24 17:31:42 +000030#include "llvm/CodeGen/MachineFunctionPass.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000031#include "llvm/CodeGen/MachineInstr.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000032#include "llvm/Support/Mangler.h"
Nate Begemana11c2e82004-09-04 14:51:26 +000033#include "llvm/Support/MathExtras.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000034#include "llvm/Support/CommandLine.h"
35#include "llvm/Support/Debug.h"
Nate Begeman17304c32004-10-26 06:02:38 +000036#include "llvm/Target/MRegisterInfo.h"
Nate Begemand4c8bea2004-11-25 07:09:01 +000037#include "llvm/Target/TargetInstrInfo.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000038#include "llvm/ADT/Statistic.h"
39#include "llvm/ADT/StringExtras.h"
Misha Brukman05794492004-06-24 17:31:42 +000040#include <set>
Chris Lattnera3840792004-08-16 23:25:21 +000041using namespace llvm;
Misha Brukman5dfe3a92004-06-21 16:55:25 +000042
43namespace {
44 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
45
Chris Lattnerac7fd7f2005-11-14 18:52:46 +000046 class PPCAsmPrinter : public AsmPrinter {
Chris Lattnerd717b192005-12-11 07:45:47 +000047 public:
Chris Lattnera637c322005-12-16 00:22:14 +000048 std::set<std::string> FnStubs, GVStubs;
Chris Lattnerac7fd7f2005-11-14 18:52:46 +000049
Chris Lattner4c7b43b2005-10-14 23:37:35 +000050 PPCAsmPrinter(std::ostream &O, TargetMachine &TM)
Chris Lattner07455362005-11-21 08:14:07 +000051 : AsmPrinter(O, TM) {}
Misha Brukmanb5f662f2005-04-21 23:30:14 +000052
Misha Brukman5dfe3a92004-06-21 16:55:25 +000053 virtual const char *getPassName() const {
Nate Begemaned428532004-09-04 05:00:00 +000054 return "PowerPC Assembly Printer";
Misha Brukman5dfe3a92004-06-21 16:55:25 +000055 }
56
Nate Begeman21e463b2005-10-16 05:39:50 +000057 PPCTargetMachine &getTM() {
58 return static_cast<PPCTargetMachine&>(TM);
Chris Lattnera3840792004-08-16 23:25:21 +000059 }
60
Nate Begemanadeb43d2005-07-20 22:42:00 +000061 unsigned enumRegToMachineReg(unsigned enumReg) {
62 switch (enumReg) {
63 default: assert(0 && "Unhandled register!"); break;
64 case PPC::CR0: return 0;
65 case PPC::CR1: return 1;
66 case PPC::CR2: return 2;
67 case PPC::CR3: return 3;
68 case PPC::CR4: return 4;
69 case PPC::CR5: return 5;
70 case PPC::CR6: return 6;
71 case PPC::CR7: return 7;
72 }
73 abort();
74 }
75
Nate Begemane59bf592004-08-14 22:09:10 +000076 /// printInstruction - This method is automatically generated by tablegen
77 /// from the instruction set description. This method returns true if the
78 /// machine instruction was sufficiently described to print it, otherwise it
79 /// returns false.
80 bool printInstruction(const MachineInstr *MI);
81
Misha Brukman5dfe3a92004-06-21 16:55:25 +000082 void printMachineInstruction(const MachineInstr *MI);
Chris Lattner9ba13e42005-11-17 19:25:59 +000083 void printOp(const MachineOperand &MO);
Chris Lattner7bb424f2004-08-14 23:27:29 +000084
Nate Begeman391c5d22005-11-30 18:54:35 +000085 void printOperand(const MachineInstr *MI, unsigned OpNo){
Chris Lattner7bb424f2004-08-14 23:27:29 +000086 const MachineOperand &MO = MI->getOperand(OpNo);
87 if (MO.getType() == MachineOperand::MO_MachineRegister) {
88 assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??");
Chris Lattner9dc4d3c2005-08-22 22:00:02 +000089 O << TM.getRegisterInfo()->get(MO.getReg()).Name;
Chris Lattner0ea31712004-08-15 05:46:14 +000090 } else if (MO.isImmediate()) {
91 O << MO.getImmedValue();
Chris Lattner7bb424f2004-08-14 23:27:29 +000092 } else {
93 printOp(MO);
94 }
95 }
96
Nate Begeman391c5d22005-11-30 18:54:35 +000097 void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Nate Begemanc3306122004-08-21 05:56:39 +000098 unsigned char value = MI->getOperand(OpNo).getImmedValue();
Chris Lattner12585ba2004-08-21 19:11:03 +000099 assert(value <= 31 && "Invalid u5imm argument!");
Nate Begemanc3306122004-08-21 05:56:39 +0000100 O << (unsigned int)value;
101 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000102 void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman07aada82004-08-30 02:28:06 +0000103 unsigned char value = MI->getOperand(OpNo).getImmedValue();
104 assert(value <= 63 && "Invalid u6imm argument!");
105 O << (unsigned int)value;
106 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000107 void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Nate Begemaned428532004-09-04 05:00:00 +0000108 O << (short)MI->getOperand(OpNo).getImmedValue();
109 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000110 void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner97b2a2e2004-08-15 05:20:16 +0000111 O << (unsigned short)MI->getOperand(OpNo).getImmedValue();
112 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000113 void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner841d12d2005-10-18 16:51:22 +0000114 O << (short)MI->getOperand(OpNo).getImmedValue()*4;
115 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000116 void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
Nate Begemaned428532004-09-04 05:00:00 +0000117 // Branches can take an immediate operand. This is used by the branch
118 // selection pass to print $+8, an eight byte displacement from the PC.
119 if (MI->getOperand(OpNo).isImmediate()) {
Nate Begeman27499e32005-04-10 01:48:29 +0000120 O << "$+" << MI->getOperand(OpNo).getImmedValue();
Nate Begemaned428532004-09-04 05:00:00 +0000121 } else {
Chris Lattner3e7f86a2005-11-17 19:16:08 +0000122 printOp(MI->getOperand(OpNo));
Nate Begemaned428532004-09-04 05:00:00 +0000123 }
Nate Begemanb7a8f2c2004-09-02 08:13:00 +0000124 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000125 void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattner9ba13e42005-11-17 19:25:59 +0000126 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattner9542f9712005-11-17 19:40:30 +0000127 if (!PPCGenerateStaticCode) {
Chris Lattnera637c322005-12-16 00:22:14 +0000128 if (MO.getType() == MachineOperand::MO_GlobalAddress) {
129 GlobalValue *GV = MO.getGlobal();
130 if (((GV->isExternal() || GV->hasWeakLinkage() ||
131 GV->hasLinkOnceLinkage()))) {
132 // Dynamically-resolved functions need a stub for the function.
133 std::string Name = Mang->getValueName(GV);
134 FnStubs.insert(Name);
135 O << "L" << Name << "$stub";
136 return;
137 }
138 }
Chris Lattner9542f9712005-11-17 19:40:30 +0000139 if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
140 std::string Name(GlobalPrefix); Name += MO.getSymbolName();
141 FnStubs.insert(Name);
142 O << "L" << Name << "$stub";
143 return;
Chris Lattner9542f9712005-11-17 19:40:30 +0000144 }
Chris Lattner9ba13e42005-11-17 19:25:59 +0000145 }
Chris Lattner9542f9712005-11-17 19:40:30 +0000146
147 printOp(MI->getOperand(OpNo));
Chris Lattner3e7f86a2005-11-17 19:16:08 +0000148 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000149 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman422b0ce2005-11-16 00:48:01 +0000150 O << (int)MI->getOperand(OpNo).getImmedValue()*4;
151 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000152 void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera637c322005-12-16 00:22:14 +0000153 O << "\"L" << getFunctionNumber() << "$pb\"\n";
154 O << "\"L" << getFunctionNumber() << "$pb\":";
Nate Begemanb7a8f2c2004-09-02 08:13:00 +0000155 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000156 void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman2497e632005-07-21 20:44:43 +0000157 if (MI->getOperand(OpNo).isImmediate()) {
Nate Begeman391c5d22005-11-30 18:54:35 +0000158 printS16ImmOperand(MI, OpNo);
Nate Begeman2497e632005-07-21 20:44:43 +0000159 } else {
160 O << "ha16(";
161 printOp(MI->getOperand(OpNo));
162 if (PICEnabled)
Chris Lattnera637c322005-12-16 00:22:14 +0000163 O << "-\"L" << getFunctionNumber() << "$pb\")";
Nate Begeman2497e632005-07-21 20:44:43 +0000164 else
165 O << ')';
166 }
Nate Begemaned428532004-09-04 05:00:00 +0000167 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000168 void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
Nate Begemaned428532004-09-04 05:00:00 +0000169 if (MI->getOperand(OpNo).isImmediate()) {
Nate Begeman391c5d22005-11-30 18:54:35 +0000170 printS16ImmOperand(MI, OpNo);
Nate Begemaned428532004-09-04 05:00:00 +0000171 } else {
172 O << "lo16(";
Nate Begemand4c8bea2004-11-25 07:09:01 +0000173 printOp(MI->getOperand(OpNo));
Nate Begeman2497e632005-07-21 20:44:43 +0000174 if (PICEnabled)
Chris Lattnera637c322005-12-16 00:22:14 +0000175 O << "-\"L" << getFunctionNumber() << "$pb\")";
Nate Begeman2497e632005-07-21 20:44:43 +0000176 else
177 O << ')';
Nate Begemaned428532004-09-04 05:00:00 +0000178 }
179 }
Nate Begeman391c5d22005-11-30 18:54:35 +0000180 void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
Nate Begemanadeb43d2005-07-20 22:42:00 +0000181 unsigned CCReg = MI->getOperand(OpNo).getReg();
182 unsigned RegNo = enumRegToMachineReg(CCReg);
183 O << (0x80 >> RegNo);
184 }
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000185 // The new addressing mode printers, currently empty
186 void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
187 printSymbolLo(MI, OpNo);
188 O << '(';
189 printOperand(MI, OpNo+1);
190 O << ')';
191 }
192 void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman88276b82005-12-19 23:40:42 +0000193 // When used as the base register, r0 reads constant zero rather than
194 // the value contained in the register. For this reason, the darwin
195 // assembler requires that we print r0 as 0 (no r) when used as the base.
196 const MachineOperand &MO = MI->getOperand(OpNo);
197 if (MO.getReg() == PPC::R0)
198 O << '0';
199 else
200 O << TM.getRegisterInfo()->get(MO.getReg()).Name;
Nate Begeman7fd1edd2005-12-19 23:25:09 +0000201 O << ", ";
202 printOperand(MI, OpNo+1);
203 }
204
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000205 virtual bool runOnMachineFunction(MachineFunction &F) = 0;
Nate Begemaned428532004-09-04 05:00:00 +0000206 virtual bool doFinalization(Module &M) = 0;
Jim Laskeyb2efb852006-01-04 22:28:25 +0000207
Nate Begemaned428532004-09-04 05:00:00 +0000208 };
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000209
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000210 /// DarwinDwarfWriter - Dwarf debug info writer customized for Darwin/Mac OS X
211 ///
212 struct DarwinDwarfWriter : public DwarfWriter {
213 // Ctor.
Jim Laskeyb2efb852006-01-04 22:28:25 +0000214 DarwinDwarfWriter(std::ostream &o, AsmPrinter *ap)
215 : DwarfWriter(o, ap)
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000216 {
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000217 needsSet = true;
218 DwarfAbbrevSection = ".section __DWARFA,__debug_abbrev,regular,debug";
219 DwarfInfoSection = ".section __DWARFA,__debug_info,regular,debug";
220 DwarfLineSection = ".section __DWARFA,__debug_line,regular,debug";
221 }
222 };
223
Misha Brukman3e0b51a2004-09-05 02:42:44 +0000224 /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS
225 /// X
226 ///
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000227 struct DarwinAsmPrinter : public PPCAsmPrinter {
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000228
229 DarwinDwarfWriter DW;
Nate Begemaned428532004-09-04 05:00:00 +0000230
231 DarwinAsmPrinter(std::ostream &O, TargetMachine &TM)
Jim Laskeyb2efb852006-01-04 22:28:25 +0000232 : PPCAsmPrinter(O, TM), DW(O, this)
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000233 {
Nate Begemaned428532004-09-04 05:00:00 +0000234 CommentString = ";";
235 GlobalPrefix = "_";
Chris Lattnerf55366e2005-11-21 06:47:58 +0000236 PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
Nate Begemaned428532004-09-04 05:00:00 +0000237 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
238 Data64bitsDirective = 0; // we can't emit a 64-bit unit
239 AlignmentIsInBytes = false; // Alignment is by power of 2.
Chris Lattnerc569e612005-11-21 08:26:15 +0000240 ConstantPoolSection = "\t.const\t";
Chris Lattnerd717b192005-12-11 07:45:47 +0000241 LCOMMDirective = "\t.lcomm\t";
Chris Lattnerd1239b72005-12-13 06:32:50 +0000242 StaticCtorsSection = ".mod_init_func";
243 StaticDtorsSection = ".mod_term_func";
Nate Begemaned428532004-09-04 05:00:00 +0000244 }
245
246 virtual const char *getPassName() const {
247 return "Darwin PPC Assembly Printer";
248 }
Chris Lattner646f7af2005-12-09 18:24:29 +0000249
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000250 bool runOnMachineFunction(MachineFunction &F);
Nate Begeman18ed0292005-07-21 01:25:49 +0000251 bool doInitialization(Module &M);
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000252 bool doFinalization(Module &M);
Jim Laskeyb2efb852006-01-04 22:28:25 +0000253
254 void getAnalysisUsage(AnalysisUsage &AU) const {
255 AU.addRequired<MachineDebugInfo>();
256 }
257
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000258 };
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000259
Misha Brukman3e0b51a2004-09-05 02:42:44 +0000260 /// AIXAsmPrinter - PowerPC assembly printer, customized for AIX
261 ///
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000262 struct AIXAsmPrinter : public PPCAsmPrinter {
Nate Begemaned428532004-09-04 05:00:00 +0000263 /// Map for labels corresponding to global variables
264 ///
265 std::map<const GlobalVariable*,std::string> GVToLabelMap;
266
267 AIXAsmPrinter(std::ostream &O, TargetMachine &TM)
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000268 : PPCAsmPrinter(O, TM) {
Nate Begemaned428532004-09-04 05:00:00 +0000269 CommentString = "#";
Chris Lattner3459bfb2005-11-10 18:20:29 +0000270 GlobalPrefix = ".";
Nate Begemaned428532004-09-04 05:00:00 +0000271 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
272 Data64bitsDirective = 0; // we can't emit a 64-bit unit
273 AlignmentIsInBytes = false; // Alignment is by power of 2.
Chris Lattnerc569e612005-11-21 08:26:15 +0000274 ConstantPoolSection = "\t.const\t";
Nate Begemaned428532004-09-04 05:00:00 +0000275 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000276
Nate Begemaned428532004-09-04 05:00:00 +0000277 virtual const char *getPassName() const {
278 return "AIX PPC Assembly Printer";
279 }
280
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000281 bool runOnMachineFunction(MachineFunction &F);
Nate Begemaned428532004-09-04 05:00:00 +0000282 bool doInitialization(Module &M);
283 bool doFinalization(Module &M);
284 };
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000285} // end of anonymous namespace
286
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000287/// createDarwinAsmPrinterPass - Returns a pass that prints the PPC assembly
288/// code for a MachineFunction to the given output stream, in a format that the
Nate Begemaned428532004-09-04 05:00:00 +0000289/// Darwin assembler can deal with.
290///
291FunctionPass *llvm::createDarwinAsmPrinter(std::ostream &o, TargetMachine &tm) {
292 return new DarwinAsmPrinter(o, tm);
293}
294
295/// createAIXAsmPrinterPass - Returns a pass that prints the PPC assembly code
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000296/// for a MachineFunction to the given output stream, in a format that the
Nate Begemaned428532004-09-04 05:00:00 +0000297/// AIX 5L assembler can deal with.
298///
299FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, TargetMachine &tm) {
300 return new AIXAsmPrinter(o, tm);
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000301}
302
Nate Begemane59bf592004-08-14 22:09:10 +0000303// Include the auto-generated portion of the assembly writer
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000304#include "PPCGenAsmWriter.inc"
Nate Begemane59bf592004-08-14 22:09:10 +0000305
Chris Lattner9ba13e42005-11-17 19:25:59 +0000306void PPCAsmPrinter::printOp(const MachineOperand &MO) {
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000307 const MRegisterInfo &RI = *TM.getRegisterInfo();
308 int new_symbol;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000309
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000310 switch (MO.getType()) {
311 case MachineOperand::MO_VirtualRegister:
312 if (Value *V = MO.getVRegValueOrNull()) {
313 O << "<" << V->getName() << ">";
314 return;
315 }
316 // FALLTHROUGH
317 case MachineOperand::MO_MachineRegister:
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000318 case MachineOperand::MO_CCRegister:
Chris Lattner9dc4d3c2005-08-22 22:00:02 +0000319 O << RI.get(MO.getReg()).Name;
Misha Brukman7f484a52004-06-24 23:51:00 +0000320 return;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000321
322 case MachineOperand::MO_SignExtendedImmed:
Misha Brukmanaf313fb2004-07-28 00:00:48 +0000323 case MachineOperand::MO_UnextendedImmed:
324 std::cerr << "printOp() does not handle immediate values\n";
325 abort();
Misha Brukman97a296f2004-07-21 20:11:11 +0000326 return;
327
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000328 case MachineOperand::MO_PCRelativeDisp:
329 std::cerr << "Shouldn't use addPCDisp() when building PPC MachineInstrs";
330 abort();
331 return;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000332
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000333 case MachineOperand::MO_MachineBasicBlock: {
334 MachineBasicBlock *MBBOp = MO.getMachineBasicBlock();
Chris Lattner07455362005-11-21 08:14:07 +0000335 O << PrivateGlobalPrefix << "BB" << getFunctionNumber() << "_"
Chris Lattner7f9ccde2005-11-21 07:41:05 +0000336 << MBBOp->getNumber() << "\t; " << MBBOp->getBasicBlock()->getName();
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000337 return;
338 }
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000339
340 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner07455362005-11-21 08:14:07 +0000341 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber()
Chris Lattnerf55366e2005-11-21 06:47:58 +0000342 << '_' << MO.getConstantPoolIndex();
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000343 return;
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000344 case MachineOperand::MO_ExternalSymbol:
Chris Lattnera637c322005-12-16 00:22:14 +0000345 // Computing the address of an external symbol, not calling it.
346 if (!PPCGenerateStaticCode) {
347 std::string Name(GlobalPrefix); Name += MO.getSymbolName();
348 GVStubs.insert(Name);
349 O << "L" << Name << "$non_lazy_ptr";
350 return;
351 }
Nate Begeman01d05262005-03-30 01:45:43 +0000352 O << GlobalPrefix << MO.getSymbolName();
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000353 return;
Nate Begemanb73a7112004-08-13 09:32:01 +0000354 case MachineOperand::MO_GlobalAddress: {
Chris Lattnera637c322005-12-16 00:22:14 +0000355 // Computing the address of a global symbol, not calling it.
Nate Begemanb73a7112004-08-13 09:32:01 +0000356 GlobalValue *GV = MO.getGlobal();
357 std::string Name = Mang->getValueName(GV);
Nate Begeman50fb3c42005-12-24 01:00:15 +0000358 int offset = MO.getOffset();
Misha Brukmane2eceb52004-07-23 16:08:20 +0000359
Nate Begemanfcf4a422004-10-17 23:01:34 +0000360 // External or weakly linked global variables need non-lazily-resolved stubs
Chris Lattnera637c322005-12-16 00:22:14 +0000361 if (!PPCGenerateStaticCode) {
362 if (((GV->isExternal() || GV->hasWeakLinkage() ||
363 GV->hasLinkOnceLinkage()))) {
Nate Begemand4c8bea2004-11-25 07:09:01 +0000364 GVStubs.insert(Name);
Chris Lattnera637c322005-12-16 00:22:14 +0000365 O << "L" << Name << "$non_lazy_ptr";
366 return;
367 }
Nate Begemanb73a7112004-08-13 09:32:01 +0000368 }
Nate Begemand4c8bea2004-11-25 07:09:01 +0000369
Chris Lattner9542f9712005-11-17 19:40:30 +0000370 O << Name;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000371 return;
Nate Begemanb73a7112004-08-13 09:32:01 +0000372 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000373
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000374 default:
Misha Brukman05fcd0c2004-07-08 17:58:04 +0000375 O << "<unknown operand type: " << MO.getType() << ">";
Misha Brukman22e12072004-06-25 15:11:34 +0000376 return;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000377 }
378}
379
Nate Begemane59bf592004-08-14 22:09:10 +0000380/// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
381/// the current output stream.
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000382///
Chris Lattner4c7b43b2005-10-14 23:37:35 +0000383void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
Nate Begemane59bf592004-08-14 22:09:10 +0000384 ++EmittedInsts;
Chris Lattner617742b2005-10-14 22:44:13 +0000385
Nate Begemanad5f65c2005-04-05 18:19:50 +0000386 // Check for slwi/srwi mnemonics.
387 if (MI->getOpcode() == PPC::RLWINM) {
388 bool FoundMnemonic = false;
389 unsigned char SH = MI->getOperand(2).getImmedValue();
390 unsigned char MB = MI->getOperand(3).getImmedValue();
391 unsigned char ME = MI->getOperand(4).getImmedValue();
392 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
393 O << "slwi "; FoundMnemonic = true;
394 }
395 if (SH <= 31 && MB == (32-SH) && ME == 31) {
396 O << "srwi "; FoundMnemonic = true;
397 SH = 32-SH;
398 }
399 if (FoundMnemonic) {
Nate Begeman391c5d22005-11-30 18:54:35 +0000400 printOperand(MI, 0);
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000401 O << ", ";
Nate Begeman391c5d22005-11-30 18:54:35 +0000402 printOperand(MI, 1);
Nate Begemanad5f65c2005-04-05 18:19:50 +0000403 O << ", " << (unsigned int)SH << "\n";
404 return;
405 }
406 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000407
Nate Begemane59bf592004-08-14 22:09:10 +0000408 if (printInstruction(MI))
409 return; // Printer was automatically generated
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000410
Nate Begemaned428532004-09-04 05:00:00 +0000411 assert(0 && "Unhandled instruction in asm writer!");
412 abort();
Nate Begemane59bf592004-08-14 22:09:10 +0000413 return;
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000414}
415
Chris Lattneref658742005-11-21 07:57:37 +0000416
Nate Begemaned428532004-09-04 05:00:00 +0000417/// runOnMachineFunction - This uses the printMachineInstruction()
418/// method to print assembly for each instruction.
419///
420bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner8b8b9512005-11-21 07:51:23 +0000421 SetupMachineFunction(MF);
Nate Begemaned428532004-09-04 05:00:00 +0000422 O << "\n\n";
Jim Laskeyf5395ce2005-12-16 22:45:29 +0000423
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000424 // Emit pre-function debug information.
425 DW.BeginFunction();
Nate Begemaned428532004-09-04 05:00:00 +0000426
427 // Print out constants referenced by the function
Chris Lattnerc569e612005-11-21 08:26:15 +0000428 EmitConstantPool(MF.getConstantPool());
Nate Begemaned428532004-09-04 05:00:00 +0000429
430 // Print out labels for the function.
Chris Lattnerac7fd7f2005-11-14 18:52:46 +0000431 const Function *F = MF.getFunction();
Chris Lattnera637c322005-12-16 00:22:14 +0000432 switch (F->getLinkage()) {
433 default: assert(0 && "Unknown linkage type!");
434 case Function::InternalLinkage: // Symbols default to internal.
435 SwitchSection(".text", F);
436 EmitAlignment(4, F);
437 break;
438 case Function::ExternalLinkage:
439 SwitchSection(".text", F);
440 EmitAlignment(4, F);
Chris Lattnerf02a9162005-10-28 18:44:07 +0000441 O << "\t.globl\t" << CurrentFnName << "\n";
Chris Lattnera637c322005-12-16 00:22:14 +0000442 break;
443 case Function::WeakLinkage:
444 case Function::LinkOnceLinkage:
445 SwitchSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions",
446 F);
447 O << "\t.globl\t" << CurrentFnName << "\n";
448 O << "\t.weak_definition\t" << CurrentFnName << "\n";
449 break;
450 }
Nate Begemaned428532004-09-04 05:00:00 +0000451 O << CurrentFnName << ":\n";
452
453 // Print out code for the function.
454 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
455 I != E; ++I) {
456 // Print a label for the basic block.
Chris Lattner1db1adb2005-08-21 19:09:33 +0000457 if (I != MF.begin()) {
Chris Lattner07455362005-11-21 08:14:07 +0000458 O << PrivateGlobalPrefix << "BB" << getFunctionNumber() << '_'
Chris Lattner7f9ccde2005-11-21 07:41:05 +0000459 << I->getNumber() << ":\t";
Chris Lattner1db1adb2005-08-21 19:09:33 +0000460 if (!I->getBasicBlock()->getName().empty())
461 O << CommentString << " " << I->getBasicBlock()->getName();
462 O << "\n";
463 }
Nate Begemaned428532004-09-04 05:00:00 +0000464 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
465 II != E; ++II) {
466 // Print the assembly for the instruction.
467 O << "\t";
468 printMachineInstruction(II);
469 }
470 }
Nate Begemaned428532004-09-04 05:00:00 +0000471
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000472 // Emit post-function debug information.
473 DW.EndFunction();
474
Nate Begemaned428532004-09-04 05:00:00 +0000475 // We didn't modify anything.
476 return false;
477}
478
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000479
Nate Begeman18ed0292005-07-21 01:25:49 +0000480bool DarwinAsmPrinter::doInitialization(Module &M) {
Chris Lattner3c304a32005-08-05 22:05:03 +0000481 if (TM.getSubtarget<PPCSubtarget>().isGigaProcessor())
482 O << "\t.machine ppc970\n";
Nate Begeman18ed0292005-07-21 01:25:49 +0000483 AsmPrinter::doInitialization(M);
Chris Lattner85eac0d2005-11-10 19:33:43 +0000484
485 // Darwin wants symbols to be quoted if they have complex names.
486 Mang->setUseQuotes(true);
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000487
488 // Emit initial debug information.
Jim Laskeyb2efb852006-01-04 22:28:25 +0000489 DW.SetDebugInfo(getAnalysisToUpdate<MachineDebugInfo>());
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000490 DW.BeginModule();
Nate Begeman18ed0292005-07-21 01:25:49 +0000491 return false;
492}
493
Nate Begemaned428532004-09-04 05:00:00 +0000494bool DarwinAsmPrinter::doFinalization(Module &M) {
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000495 const TargetData &TD = TM.getTargetData();
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000496
497 // Print out module-level global variables here.
Chris Lattnerced704b2005-11-14 19:00:30 +0000498 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
Chris Lattnerdeea4162005-12-13 04:33:58 +0000499 I != E; ++I) {
500 if (!I->hasInitializer()) continue; // External global require no code
501
Chris Lattnerd1239b72005-12-13 06:32:50 +0000502 // Check to see if this is a special global used by LLVM, if so, emit it.
503 if (I->hasAppendingLinkage() && EmitSpecialLLVMGlobal(I))
504 continue;
Chris Lattnerdeea4162005-12-13 04:33:58 +0000505
506 O << '\n';
507 std::string name = Mang->getValueName(I);
508 Constant *C = I->getInitializer();
509 unsigned Size = TD.getTypeSize(C->getType());
510 unsigned Align = TD.getTypeAlignmentShift(C->getType());
511
512 if (C->isNullValue() && /* FIXME: Verify correct */
513 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
514 I->hasLinkOnceLinkage())) {
515 SwitchSection(".data", I);
516 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
517 if (I->hasInternalLinkage())
518 O << LCOMMDirective << name << "," << Size << "," << Align;
519 else
520 O << ".comm " << name << "," << Size;
521 O << "\t\t; '" << I->getName() << "'\n";
522 } else {
523 switch (I->getLinkage()) {
524 case GlobalValue::LinkOnceLinkage:
Chris Lattnerdeea4162005-12-13 04:33:58 +0000525 case GlobalValue::WeakLinkage:
Chris Lattnercec26fc2005-12-22 21:15:17 +0000526 O << "\t.globl " << name << '\n'
527 << "\t.weak_definition " << name << '\n';
Chris Lattnera637c322005-12-16 00:22:14 +0000528 SwitchSection(".section __DATA,__datacoal_nt,coalesced", I);
Chris Lattnerdeea4162005-12-13 04:33:58 +0000529 break;
530 case GlobalValue::AppendingLinkage:
531 // FIXME: appending linkage variables should go into a section of
532 // their name or something. For now, just emit them as external.
533 case GlobalValue::ExternalLinkage:
534 // If external or appending, declare as a global symbol
535 O << "\t.globl " << name << "\n";
536 // FALL THROUGH
537 case GlobalValue::InternalLinkage:
538 SwitchSection(".data", I);
539 break;
540 default:
541 std::cerr << "Unknown linkage type!";
542 abort();
543 }
544
545 EmitAlignment(Align, I);
546 O << name << ":\t\t\t\t; '" << I->getName() << "'\n";
547 EmitGlobalConstant(C);
548 }
549 }
Misha Brukmanda2b13f2004-07-16 20:29:04 +0000550
551 // Output stubs for dynamically-linked functions
Chris Lattnerdeea4162005-12-13 04:33:58 +0000552 if (PICEnabled) {
553 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
554 i != e; ++i) {
Chris Lattnera637c322005-12-16 00:22:14 +0000555 SwitchSection(".section __TEXT,__picsymbolstub1,symbol_stubs,"
556 "pure_instructions,32", 0);
Chris Lattnerdeea4162005-12-13 04:33:58 +0000557 EmitAlignment(2);
558 O << "L" << *i << "$stub:\n";
559 O << "\t.indirect_symbol " << *i << "\n";
560 O << "\tmflr r0\n";
561 O << "\tbcl 20,31,L0$" << *i << "\n";
562 O << "L0$" << *i << ":\n";
563 O << "\tmflr r11\n";
564 O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n";
565 O << "\tmtlr r0\n";
566 O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n";
567 O << "\tmtctr r12\n";
568 O << "\tbctr\n";
Chris Lattnera637c322005-12-16 00:22:14 +0000569 SwitchSection(".lazy_symbol_pointer", 0);
Chris Lattnerdeea4162005-12-13 04:33:58 +0000570 O << "L" << *i << "$lazy_ptr:\n";
571 O << "\t.indirect_symbol " << *i << "\n";
572 O << "\t.long dyld_stub_binding_helper\n";
573 }
574 } else {
575 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
576 i != e; ++i) {
Chris Lattnera637c322005-12-16 00:22:14 +0000577 SwitchSection(".section __TEXT,__symbol_stub1,symbol_stubs,"
578 "pure_instructions,16", 0);
Chris Lattnerdeea4162005-12-13 04:33:58 +0000579 EmitAlignment(4);
580 O << "L" << *i << "$stub:\n";
581 O << "\t.indirect_symbol " << *i << "\n";
582 O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n";
583 O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n";
584 O << "\tmtctr r12\n";
585 O << "\tbctr\n";
Chris Lattnera637c322005-12-16 00:22:14 +0000586 SwitchSection(".lazy_symbol_pointer", 0);
Chris Lattnerdeea4162005-12-13 04:33:58 +0000587 O << "L" << *i << "$lazy_ptr:\n";
588 O << "\t.indirect_symbol " << *i << "\n";
589 O << "\t.long dyld_stub_binding_helper\n";
Nate Begeman2497e632005-07-21 20:44:43 +0000590 }
Misha Brukman46fd00a2004-06-24 23:04:11 +0000591 }
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000592
Misha Brukmanda2b13f2004-07-16 20:29:04 +0000593 O << "\n";
594
Chris Lattnera637c322005-12-16 00:22:14 +0000595 // Output stubs for external and common global variables.
596 if (GVStubs.begin() != GVStubs.end()) {
597 SwitchSection(".non_lazy_symbol_pointer", 0);
598 for (std::set<std::string>::iterator I = GVStubs.begin(),
599 E = GVStubs.end(); I != E; ++I) {
600 O << "L" << *I << "$non_lazy_ptr:\n";
601 O << "\t.indirect_symbol " << *I << "\n";
602 O << "\t.long\t0\n";
Chris Lattnerdeea4162005-12-13 04:33:58 +0000603 }
Nate Begemane59bf592004-08-14 22:09:10 +0000604 }
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000605
Chris Lattner5b0ac992005-11-01 00:12:36 +0000606 // Funny Darwin hack: This flag tells the linker that no global symbols
607 // contain code that falls through to other global symbols (e.g. the obvious
608 // implementation of multiple entry points). If this doesn't occur, the
609 // linker can safely perform dead code stripping. Since LLVM never generates
610 // code that does this, it is always safe to set.
611 O << "\t.subsections_via_symbols\n";
612
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000613 // Emit initial debug information.
614 DW.EndModule();
615
Chris Lattnera3840792004-08-16 23:25:21 +0000616 AsmPrinter::doFinalization(M);
Misha Brukman5dfe3a92004-06-21 16:55:25 +0000617 return false; // success
618}
Nate Begemaned428532004-09-04 05:00:00 +0000619
Jim Laskeyb2efb852006-01-04 22:28:25 +0000620/// runOnMachineFunction - This uses the e()
Nate Begemaned428532004-09-04 05:00:00 +0000621/// method to print assembly for each instruction.
622///
623bool AIXAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner6d5a4f62005-11-21 08:02:41 +0000624 SetupMachineFunction(MF);
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000625
Nate Begemaned428532004-09-04 05:00:00 +0000626 // Print out constants referenced by the function
Chris Lattnerc569e612005-11-21 08:26:15 +0000627 EmitConstantPool(MF.getConstantPool());
Nate Begemaned428532004-09-04 05:00:00 +0000628
629 // Print out header for the function.
630 O << "\t.csect .text[PR]\n"
631 << "\t.align 2\n"
632 << "\t.globl " << CurrentFnName << '\n'
633 << "\t.globl ." << CurrentFnName << '\n'
634 << "\t.csect " << CurrentFnName << "[DS],3\n"
635 << CurrentFnName << ":\n"
636 << "\t.llong ." << CurrentFnName << ", TOC[tc0], 0\n"
637 << "\t.csect .text[PR]\n"
638 << '.' << CurrentFnName << ":\n";
639
640 // Print out code for the function.
641 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
642 I != E; ++I) {
643 // Print a label for the basic block.
Chris Lattner07455362005-11-21 08:14:07 +0000644 O << PrivateGlobalPrefix << "BB" << getFunctionNumber() << '_'
645 << I->getNumber()
Chris Lattner6d5a4f62005-11-21 08:02:41 +0000646 << ":\t" << CommentString << I->getBasicBlock()->getName() << '\n';
Nate Begemaned428532004-09-04 05:00:00 +0000647 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
648 II != E; ++II) {
649 // Print the assembly for the instruction.
650 O << "\t";
651 printMachineInstruction(II);
652 }
653 }
Nate Begemaned428532004-09-04 05:00:00 +0000654
655 O << "LT.." << CurrentFnName << ":\n"
656 << "\t.long 0\n"
657 << "\t.byte 0,0,32,65,128,0,0,0\n"
658 << "\t.long LT.." << CurrentFnName << "-." << CurrentFnName << '\n'
659 << "\t.short 3\n"
660 << "\t.byte \"" << CurrentFnName << "\"\n"
661 << "\t.align 2\n";
662
663 // We didn't modify anything.
664 return false;
665}
666
Nate Begemaned428532004-09-04 05:00:00 +0000667bool AIXAsmPrinter::doInitialization(Module &M) {
Chris Lattnerac7fd7f2005-11-14 18:52:46 +0000668 SwitchSection("", 0);
Nate Begemaned428532004-09-04 05:00:00 +0000669 const TargetData &TD = TM.getTargetData();
Nate Begemaned428532004-09-04 05:00:00 +0000670
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000671 O << "\t.machine \"ppc64\"\n"
Nate Begemaned428532004-09-04 05:00:00 +0000672 << "\t.toc\n"
673 << "\t.csect .text[PR]\n";
674
675 // Print out module-level global variables
Chris Lattner2e00d7d2005-07-26 19:03:27 +0000676 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
677 I != E; ++I) {
Nate Begemaned428532004-09-04 05:00:00 +0000678 if (!I->hasInitializer())
679 continue;
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000680
Nate Begemaned428532004-09-04 05:00:00 +0000681 std::string Name = I->getName();
682 Constant *C = I->getInitializer();
683 // N.B.: We are defaulting to writable strings
Misha Brukmanb5f662f2005-04-21 23:30:14 +0000684 if (I->hasExternalLinkage()) {
Nate Begemaned428532004-09-04 05:00:00 +0000685 O << "\t.globl " << Name << '\n'
686 << "\t.csect .data[RW],3\n";
687 } else {
688 O << "\t.csect _global.rw_c[RW],3\n";
689 }
690 O << Name << ":\n";
Chris Lattner8b8b9512005-11-21 07:51:23 +0000691 EmitGlobalConstant(C);
Nate Begemaned428532004-09-04 05:00:00 +0000692 }
693
694 // Output labels for globals
Chris Lattnere4d5c442005-03-15 04:54:21 +0000695 if (M.global_begin() != M.global_end()) O << "\t.toc\n";
Chris Lattner2e00d7d2005-07-26 19:03:27 +0000696 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
697 I != E; ++I) {
Nate Begemaned428532004-09-04 05:00:00 +0000698 const GlobalVariable *GV = I;
699 // Do not output labels for unused variables
700 if (GV->isExternal() && GV->use_begin() == GV->use_end())
701 continue;
702
Chris Lattner07455362005-11-21 08:14:07 +0000703 IncrementFunctionNumber();
Nate Begemaned428532004-09-04 05:00:00 +0000704 std::string Name = GV->getName();
Chris Lattner07455362005-11-21 08:14:07 +0000705 std::string Label = "LC.." + utostr(getFunctionNumber());
Nate Begemaned428532004-09-04 05:00:00 +0000706 GVToLabelMap[GV] = Label;
707 O << Label << ":\n"
708 << "\t.tc " << Name << "[TC]," << Name;
709 if (GV->isExternal()) O << "[RW]";
710 O << '\n';
Chris Lattner07455362005-11-21 08:14:07 +0000711 }
Nate Begemaned428532004-09-04 05:00:00 +0000712
Chris Lattner3459bfb2005-11-10 18:20:29 +0000713 AsmPrinter::doInitialization(M);
Nate Begemaned428532004-09-04 05:00:00 +0000714 return false; // success
715}
716
717bool AIXAsmPrinter::doFinalization(Module &M) {
718 const TargetData &TD = TM.getTargetData();
719 // Print out module-level global variables
Chris Lattner2e00d7d2005-07-26 19:03:27 +0000720 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
721 I != E; ++I) {
Nate Begemaned428532004-09-04 05:00:00 +0000722 if (I->hasInitializer() || I->hasExternalLinkage())
723 continue;
724
725 std::string Name = I->getName();
726 if (I->hasInternalLinkage()) {
727 O << "\t.lcomm " << Name << ",16,_global.bss_c";
728 } else {
729 O << "\t.comm " << Name << "," << TD.getTypeSize(I->getType())
Chris Lattner0561b3f2005-08-02 19:26:06 +0000730 << "," << Log2_32((unsigned)TD.getTypeAlignment(I->getType()));
Nate Begemaned428532004-09-04 05:00:00 +0000731 }
Chris Lattner6d5a4f62005-11-21 08:02:41 +0000732 O << "\t\t" << CommentString << " ";
Chris Lattner8ca02912005-10-03 07:08:36 +0000733 WriteAsOperand(O, I, false, true, &M);
Nate Begemaned428532004-09-04 05:00:00 +0000734 O << "\n";
735 }
736
737 O << "_section_.text:\n"
738 << "\t.csect .data[RW],3\n"
739 << "\t.llong _section_.text\n";
Chris Lattner3459bfb2005-11-10 18:20:29 +0000740 AsmPrinter::doFinalization(M);
Nate Begemaned428532004-09-04 05:00:00 +0000741 return false; // success
742}