blob: bb9c75df01767e45ed38085a79eb745b1d55438d [file] [log] [blame]
Chris Lattner158e1f52006-02-05 05:50:24 +00001//===-- SparcAsmPrinter.cpp - Sparc LLVM assembly writer ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner158e1f52006-02-05 05:50:24 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to GAS-format SPARC assembly language.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner1ef9cd42006-12-19 22:59:26 +000015#define DEBUG_TYPE "asm-printer"
Chris Lattner158e1f52006-02-05 05:50:24 +000016#include "Sparc.h"
17#include "SparcInstrInfo.h"
Chris Lattner3773afe2009-06-19 15:48:10 +000018#include "SparcTargetMachine.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Module.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000022#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendling0f4c5812009-02-18 23:12:06 +000023#include "llvm/CodeGen/DwarfWriter.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000024#include "llvm/CodeGen/MachineFunctionPass.h"
25#include "llvm/CodeGen/MachineConstantPool.h"
26#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000027#include "llvm/MC/MCAsmInfo.h"
Chris Lattner4cd44982009-09-13 17:14:04 +000028#include "llvm/MC/MCStreamer.h"
29#include "llvm/MC/MCSymbol.h"
Chris Lattner5e693ed2009-07-28 03:13:23 +000030#include "llvm/Target/TargetLoweringObjectFile.h"
Daniel Dunbare8338102009-07-15 20:24:03 +000031#include "llvm/Target/TargetRegistry.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000032#include "llvm/ADT/Statistic.h"
33#include "llvm/ADT/StringExtras.h"
34#include "llvm/Support/CommandLine.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/FormattedStream.h"
Chris Lattner158e1f52006-02-05 05:50:24 +000037#include "llvm/Support/MathExtras.h"
38#include <cctype>
Anton Korobeynikov579f0712008-02-20 11:08:44 +000039#include <cstring>
Owen Anderson36b92ca2008-07-10 01:44:27 +000040#include <map>
Chris Lattner158e1f52006-02-05 05:50:24 +000041using namespace llvm;
42
Chris Lattner1ef9cd42006-12-19 22:59:26 +000043STATISTIC(EmittedInsts, "Number of machine instrs printed");
Chris Lattner158e1f52006-02-05 05:50:24 +000044
Chris Lattner1ef9cd42006-12-19 22:59:26 +000045namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +000046 class SparcAsmPrinter : public AsmPrinter {
Chris Lattner158e1f52006-02-05 05:50:24 +000047 /// We name each basic block in a Function with a unique number, so
48 /// that we can consistently refer to them later. This is cleared
49 /// at the beginning of each call to runOnMachineFunction().
50 ///
51 typedef std::map<const Value *, unsigned> ValueMapTy;
52 ValueMapTy NumberForBB;
Owen Andersonc043d132009-06-26 21:45:04 +000053 unsigned BBNumber;
Bill Wendlingc5437ea2009-02-24 08:30:20 +000054 public:
David Greenea31f96c2009-07-14 20:18:05 +000055 explicit SparcAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattner7b26fce2009-08-22 20:48:53 +000056 const MCAsmInfo *T, bool V)
Daniel Dunbar75c12e12009-07-01 01:48:54 +000057 : AsmPrinter(O, TM, T, V), BBNumber(0) {}
Chris Lattner158e1f52006-02-05 05:50:24 +000058
59 virtual const char *getPassName() const {
60 return "Sparc Assembly Printer";
61 }
62
Chris Lattner100865e2009-07-21 18:38:57 +000063 void PrintGlobalVariable(const GlobalVariable *GVar);
Chris Lattner158e1f52006-02-05 05:50:24 +000064 void printOperand(const MachineInstr *MI, int opNum);
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +000065 void printMemOperand(const MachineInstr *MI, int opNum,
66 const char *Modifier = 0);
Chris Lattner158e1f52006-02-05 05:50:24 +000067 void printCCOperand(const MachineInstr *MI, int opNum);
68
Chris Lattnerb94284b2009-08-08 01:32:19 +000069 void printInstruction(const MachineInstr *MI); // autogenerated.
Chris Lattnerad10b3b2009-09-13 20:19:22 +000070 static const char *getRegisterName(unsigned RegNo);
Chris Lattner06c5eed2009-09-13 20:08:00 +000071
Chris Lattner158e1f52006-02-05 05:50:24 +000072 bool runOnMachineFunction(MachineFunction &F);
Anton Korobeynikov3db21732008-10-10 10:15:03 +000073 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
74 unsigned AsmVariant, const char *ExtraCode);
75 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
76 unsigned AsmVariant, const char *ExtraCode);
Chris Lattner840c7002009-09-15 17:46:24 +000077
78 void emitFunctionHeader(const MachineFunction &MF);
79 bool printGetPCX(const MachineInstr *MI, unsigned OpNo);
Chris Lattner158e1f52006-02-05 05:50:24 +000080 };
81} // end of anonymous namespace
82
83#include "SparcGenAsmWriter.inc"
84
Evan Cheng32e53472008-02-02 08:39:46 +000085/// runOnMachineFunction - This uses the printInstruction()
Chris Lattner158e1f52006-02-05 05:50:24 +000086/// method to print assembly for each instruction.
87///
88bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendlingc5437ea2009-02-24 08:30:20 +000089 this->MF = &MF;
90
Chris Lattner158e1f52006-02-05 05:50:24 +000091 SetupMachineFunction(MF);
92
93 // Print out constants referenced by the function
94 EmitConstantPool(MF.getConstantPool());
95
96 // BBNumber is used here so that a given Printer will never give two
97 // BBs the same name. (If you have a better way, please let me know!)
Chris Lattner158e1f52006-02-05 05:50:24 +000098
99 O << "\n\n";
Chris Lattner840c7002009-09-15 17:46:24 +0000100 emitFunctionHeader(MF);
101
102
Richard Penningtonbd1fc362009-09-08 12:47:30 +0000103 // Emit pre-function debug information.
104 DW->BeginFunction(&MF);
Chris Lattner158e1f52006-02-05 05:50:24 +0000105
106 // Number each basic block so that we can consistently refer to them
107 // in PC-relative references.
Chris Lattnerd4d255a2006-10-05 02:48:40 +0000108 // FIXME: Why not use the MBB numbers?
Chris Lattner158e1f52006-02-05 05:50:24 +0000109 NumberForBB.clear();
110 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
111 I != E; ++I) {
112 NumberForBB[I->getBasicBlock()] = BBNumber++;
113 }
114
115 // Print out code for the function.
116 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
117 I != E; ++I) {
118 // Print a label for the basic block.
Nate Begemanb9d4f832006-05-02 05:37:32 +0000119 if (I != MF.begin()) {
Chris Lattner1d04aa72009-09-13 18:25:37 +0000120 EmitBasicBlockStart(I);
Nate Begemanb9d4f832006-05-02 05:37:32 +0000121 }
Chris Lattner158e1f52006-02-05 05:50:24 +0000122 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
123 II != E; ++II) {
124 // Print the assembly for the instruction.
Devang Patel051454a2009-10-06 02:19:11 +0000125 processDebugLoc(II, true);
Chris Lattner158e1f52006-02-05 05:50:24 +0000126 printInstruction(II);
Chris Lattner321bc992009-09-09 23:14:36 +0000127
David Greene659c1a92009-11-13 21:34:57 +0000128 if (VerboseAsm)
Chris Lattner321bc992009-09-09 23:14:36 +0000129 EmitComments(*II);
130 O << '\n';
Devang Patel051454a2009-10-06 02:19:11 +0000131 processDebugLoc(II, false);
Chris Lattner158e1f52006-02-05 05:50:24 +0000132 ++EmittedInsts;
133 }
134 }
135
Richard Penningtonbd1fc362009-09-08 12:47:30 +0000136 // Emit post-function debug information.
137 DW->EndFunction(&MF);
138
Chris Lattner158e1f52006-02-05 05:50:24 +0000139 // We didn't modify anything.
Chris Lattner719e9082010-01-16 00:21:18 +0000140 O << "\t.size\t";
141 CurrentFnSym->print(O, MAI);
142 O << ", .-";
143 CurrentFnSym->print(O, MAI);
144 O << '\n';
Chris Lattner158e1f52006-02-05 05:50:24 +0000145 return false;
146}
147
Chris Lattner840c7002009-09-15 17:46:24 +0000148void SparcAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
149 const Function *F = MF.getFunction();
150 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
151 EmitAlignment(MF.getAlignment(), F);
152
153 switch (F->getLinkage()) {
154 default: llvm_unreachable("Unknown linkage type");
155 case Function::PrivateLinkage:
156 case Function::InternalLinkage:
157 // Function is internal.
158 break;
159 case Function::DLLExportLinkage:
160 case Function::ExternalLinkage:
161 // Function is externally visible
Chris Lattner719e9082010-01-16 00:21:18 +0000162 O << "\t.global\t";
163 CurrentFnSym->print(O, MAI);
164 O << '\n';
Chris Lattner840c7002009-09-15 17:46:24 +0000165 break;
166 case Function::LinkerPrivateLinkage:
167 case Function::LinkOnceAnyLinkage:
168 case Function::LinkOnceODRLinkage:
169 case Function::WeakAnyLinkage:
170 case Function::WeakODRLinkage:
171 // Function is weak
Chris Lattnere6b1bef2010-01-16 00:51:39 +0000172 O << "\t.weak\t";
173 CurrentFnSym->print(O, MAI);
174 O << '\n';
Chris Lattner840c7002009-09-15 17:46:24 +0000175 break;
176 }
177
Chris Lattner719e9082010-01-16 00:21:18 +0000178 printVisibility(CurrentFnSym, F->getVisibility());
Chris Lattner840c7002009-09-15 17:46:24 +0000179
Chris Lattner719e9082010-01-16 00:21:18 +0000180 O << "\t.type\t";
181 CurrentFnSym->print(O, MAI);
182 O << ", #function\n";
183 CurrentFnSym->print(O, MAI);
184 O << ":\n";
Chris Lattner840c7002009-09-15 17:46:24 +0000185}
186
187
Chris Lattner158e1f52006-02-05 05:50:24 +0000188void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
189 const MachineOperand &MO = MI->getOperand (opNum);
Chris Lattner158e1f52006-02-05 05:50:24 +0000190 bool CloseParen = false;
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000191 if (MI->getOpcode() == SP::SETHIi && !MO.isReg() && !MO.isImm()) {
Chris Lattner158e1f52006-02-05 05:50:24 +0000192 O << "%hi(";
193 CloseParen = true;
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000194 } else if ((MI->getOpcode() == SP::ORri || MI->getOpcode() == SP::ADDri) &&
195 !MO.isReg() && !MO.isImm()) {
Chris Lattner158e1f52006-02-05 05:50:24 +0000196 O << "%lo(";
197 CloseParen = true;
198 }
199 switch (MO.getType()) {
Chris Lattner10b71c02006-05-04 18:05:43 +0000200 case MachineOperand::MO_Register:
Chris Lattnereb2cc682009-09-13 20:31:40 +0000201 O << "%" << LowercaseString(getRegisterName(MO.getReg()));
Chris Lattner158e1f52006-02-05 05:50:24 +0000202 break;
203
Chris Lattnerfef7a2d2006-05-04 17:21:20 +0000204 case MachineOperand::MO_Immediate:
Chris Lattner5c463782007-12-30 20:49:49 +0000205 O << (int)MO.getImm();
Chris Lattner158e1f52006-02-05 05:50:24 +0000206 break;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000207 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner4cd44982009-09-13 17:14:04 +0000208 GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
Chris Lattner158e1f52006-02-05 05:50:24 +0000209 return;
Chris Lattner158e1f52006-02-05 05:50:24 +0000210 case MachineOperand::MO_GlobalAddress:
Chris Lattner91687f62010-01-15 23:18:17 +0000211 GetGlobalValueSymbol(MO.getGlobal())->print(O, MAI);
Chris Lattner158e1f52006-02-05 05:50:24 +0000212 break;
213 case MachineOperand::MO_ExternalSymbol:
214 O << MO.getSymbolName();
215 break;
216 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattnere9a75a62009-08-22 21:43:10 +0000217 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
Chris Lattnera5bb3702007-12-30 23:10:15 +0000218 << MO.getIndex();
Chris Lattner158e1f52006-02-05 05:50:24 +0000219 break;
220 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000221 llvm_unreachable("<unknown operand type>");
Chris Lattner158e1f52006-02-05 05:50:24 +0000222 }
223 if (CloseParen) O << ")";
224}
225
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +0000226void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
227 const char *Modifier) {
Chris Lattner158e1f52006-02-05 05:50:24 +0000228 printOperand(MI, opNum);
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000229
Chris Lattnerfcb8a3a2006-02-10 07:35:42 +0000230 // If this is an ADD operand, emit it like normal operands.
231 if (Modifier && !strcmp(Modifier, "arith")) {
232 O << ", ";
233 printOperand(MI, opNum+1);
234 return;
235 }
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000236
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000237 if (MI->getOperand(opNum+1).isReg() &&
Chris Lattner158e1f52006-02-05 05:50:24 +0000238 MI->getOperand(opNum+1).getReg() == SP::G0)
239 return; // don't print "+%g0"
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000240 if (MI->getOperand(opNum+1).isImm() &&
Chris Lattner5c463782007-12-30 20:49:49 +0000241 MI->getOperand(opNum+1).getImm() == 0)
Chris Lattner158e1f52006-02-05 05:50:24 +0000242 return; // don't print "+0"
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000243
Chris Lattner158e1f52006-02-05 05:50:24 +0000244 O << "+";
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000245 if (MI->getOperand(opNum+1).isGlobal() ||
246 MI->getOperand(opNum+1).isCPI()) {
Chris Lattner158e1f52006-02-05 05:50:24 +0000247 O << "%lo(";
248 printOperand(MI, opNum+1);
249 O << ")";
250 } else {
251 printOperand(MI, opNum+1);
252 }
253}
254
Chris Lattner840c7002009-09-15 17:46:24 +0000255bool SparcAsmPrinter::printGetPCX(const MachineInstr *MI, unsigned opNum) {
256 std::string operand = "";
257 const MachineOperand &MO = MI->getOperand(opNum);
258 switch (MO.getType()) {
259 default: assert(0 && "Operand is not a register ");
260 case MachineOperand::MO_Register:
261 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
262 "Operand is not a physical register ");
263 operand = "%" + LowercaseString(getRegisterName(MO.getReg()));
264 break;
265 }
266
267 unsigned bbNum = NumberForBB[MI->getParent()->getBasicBlock()];
268
269 O << '\n' << ".LLGETPCH" << bbNum << ":\n";
270 O << "\tcall\t.LLGETPC" << bbNum << '\n' ;
271
272 O << "\t sethi\t"
273 << "%hi(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << bbNum << ")), "
274 << operand << '\n' ;
275
276 O << ".LLGETPC" << bbNum << ":\n" ;
277 O << "\tor\t" << operand
278 << ", %lo(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << bbNum << ")), "
279 << operand << '\n';
280 O << "\tadd\t" << operand << ", %o7, " << operand << '\n';
281
282 return true;
283}
284
Chris Lattner158e1f52006-02-05 05:50:24 +0000285void SparcAsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
Chris Lattner5c463782007-12-30 20:49:49 +0000286 int CC = (int)MI->getOperand(opNum).getImm();
Chris Lattner158e1f52006-02-05 05:50:24 +0000287 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
288}
289
Chris Lattner100865e2009-07-21 18:38:57 +0000290void SparcAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000291 const TargetData *TD = TM.getTargetData();
292
293 if (!GVar->hasInitializer())
294 return; // External global require no code
295
296 // Check to see if this is a special global used by LLVM, if so, emit it.
297 if (EmitSpecialLLVMGlobal(GVar))
298 return;
299
300 O << "\n\n";
Chris Lattner426f31f2010-01-16 01:12:01 +0000301 MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000302 Constant *C = GVar->getInitializer();
Duncan Sandsaf9eaa82009-05-09 07:06:46 +0000303 unsigned Size = TD->getTypeAllocSize(C->getType());
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000304 unsigned Align = TD->getPreferredAlignment(GVar);
305
Chris Lattner426f31f2010-01-16 01:12:01 +0000306 printVisibility(GVarSym, GVar->getVisibility());
Anton Korobeynikoved473292008-08-08 18:25:07 +0000307
Chris Lattner4b7dadb2009-08-19 05:49:37 +0000308 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
309 TM));
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000310
311 if (C->isNullValue() && !GVar->hasSection()) {
312 if (!GVar->isThreadLocal() &&
Duncan Sands12da8ce2009-03-07 15:45:40 +0000313 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000314 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
315
Chris Lattner426f31f2010-01-16 01:12:01 +0000316 if (GVar->hasLocalLinkage()) {
317 O << "\t.local ";
318 GVarSym->print(O, MAI);
319 O << '\n';
320 }
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000321
Chris Lattner426f31f2010-01-16 01:12:01 +0000322 O << MAI->getCOMMDirective();
323 GVarSym->print(O, MAI);
324 O << ',' << Size;
Chris Lattnere9a75a62009-08-22 21:43:10 +0000325 if (MAI->getCOMMDirectiveTakesAlignment())
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000326 O << ',' << (1 << Align);
327
328 O << '\n';
329 return;
330 }
331 }
332
333 switch (GVar->getLinkage()) {
Duncan Sands4581beb2009-03-11 20:14:15 +0000334 case GlobalValue::CommonLinkage:
Duncan Sands12da8ce2009-03-07 15:45:40 +0000335 case GlobalValue::LinkOnceAnyLinkage:
336 case GlobalValue::LinkOnceODRLinkage:
337 case GlobalValue::WeakAnyLinkage: // FIXME: Verify correct for weak.
338 case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak.
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000339 // Nonnull linkonce -> weak
Chris Lattner426f31f2010-01-16 01:12:01 +0000340 O << "\t.weak ";
341 GVarSym->print(O, MAI);
342 O << '\n';
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000343 break;
344 case GlobalValue::AppendingLinkage:
345 // FIXME: appending linkage variables should go into a section of
346 // their name or something. For now, just emit them as external.
347 case GlobalValue::ExternalLinkage:
348 // If external or appending, declare as a global symbol
Chris Lattner426f31f2010-01-16 01:12:01 +0000349 O << MAI->getGlobalDirective();
350 GVarSym->print(O, MAI);
351 O << '\n';
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000352 // FALL THROUGH
Rafael Espindola6de96a12009-01-15 20:18:42 +0000353 case GlobalValue::PrivateLinkage:
Bill Wendlinga3c6f6b2009-07-20 01:03:30 +0000354 case GlobalValue::LinkerPrivateLinkage:
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000355 case GlobalValue::InternalLinkage:
356 break;
357 case GlobalValue::GhostLinkage:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000358 llvm_unreachable("Should not have any unmaterialized functions!");
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000359 case GlobalValue::DLLImportLinkage:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000360 llvm_unreachable("DLLImport linkage is not supported by this target!");
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000361 case GlobalValue::DLLExportLinkage:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000362 llvm_unreachable("DLLExport linkage is not supported by this target!");
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000363 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000364 llvm_unreachable("Unknown linkage type!");
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000365 }
366
Anton Korobeynikovadb93532008-08-07 09:53:38 +0000367 EmitAlignment(Align, GVar);
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000368
Chris Lattnere9a75a62009-08-22 21:43:10 +0000369 if (MAI->hasDotTypeDotSizeDirective()) {
Chris Lattner426f31f2010-01-16 01:12:01 +0000370 O << "\t.type ";
371 GVarSym->print(O, MAI);
372 O << ",#object\n";
373 O << "\t.size ";
374 GVarSym->print(O, MAI);
375 O << ',' << Size << '\n';
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000376 }
377
Chris Lattner426f31f2010-01-16 01:12:01 +0000378 GVarSym->print(O, MAI);
379 O << ":\n";
Anton Korobeynikov1a11e8a2008-08-07 09:51:25 +0000380 EmitGlobalConstant(C);
381}
Anton Korobeynikov3db21732008-10-10 10:15:03 +0000382
383/// PrintAsmOperand - Print out an operand for an inline asm expression.
384///
385bool SparcAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
386 unsigned AsmVariant,
387 const char *ExtraCode) {
Anton Korobeynikovb80b4852008-10-10 20:29:50 +0000388 if (ExtraCode && ExtraCode[0]) {
389 if (ExtraCode[1] != 0) return true; // Unknown modifier.
390
391 switch (ExtraCode[0]) {
392 default: return true; // Unknown modifier.
393 case 'r':
394 break;
395 }
396 }
Anton Korobeynikov3db21732008-10-10 10:15:03 +0000397
398 printOperand(MI, OpNo);
399
400 return false;
401}
402
403bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
404 unsigned OpNo,
405 unsigned AsmVariant,
406 const char *ExtraCode) {
407 if (ExtraCode && ExtraCode[0])
408 return true; // Unknown modifier
409
410 O << '[';
411 printMemOperand(MI, OpNo);
412 O << ']';
413
414 return false;
415}
Douglas Gregor1b731d52009-06-16 20:12:29 +0000416
Bob Wilson5a495fe2009-06-23 23:59:40 +0000417// Force static initialization.
Daniel Dunbare8338102009-07-15 20:24:03 +0000418extern "C" void LLVMInitializeSparcAsmPrinter() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +0000419 RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
Daniel Dunbare8338102009-07-15 20:24:03 +0000420}