blob: cd85dd467f4c88b3c539092f22d0553036a24536 [file] [log] [blame]
Chris Lattner7c90f732006-02-05 05:50:24 +00001//===-- SparcAsmPrinter.cpp - Sparc LLVM assembly writer ------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaeke4acfd032004-03-04 06:00:41 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaeke4acfd032004-03-04 06:00:41 +00008//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
Chris Lattner7c90f732006-02-05 05:50:24 +000011// of machine-dependent LLVM code to GAS-format SPARC assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner95b2c7d2006-12-19 22:59:26 +000015#define DEBUG_TYPE "asm-printer"
Chris Lattner7c90f732006-02-05 05:50:24 +000016#include "Sparc.h"
17#include "SparcInstrInfo.h"
Chris Lattner225503a2009-06-19 15:48:10 +000018#include "SparcTargetMachine.h"
Brian Gaeke4acfd032004-03-04 06:00:41 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Module.h"
Chris Lattner1dbed162005-12-17 07:04:29 +000022#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000023#include "llvm/CodeGen/DwarfWriter.h"
Brian Gaeke4acfd032004-03-04 06:00:41 +000024#include "llvm/CodeGen/MachineFunctionPass.h"
25#include "llvm/CodeGen/MachineConstantPool.h"
26#include "llvm/CodeGen/MachineInstr.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000027#include "llvm/MC/MCAsmInfo.h"
Chris Lattner325d3dc2009-09-13 17:14:04 +000028#include "llvm/MC/MCStreamer.h"
29#include "llvm/MC/MCSymbol.h"
Chris Lattnerf0144122009-07-28 03:13:23 +000030#include "llvm/Target/TargetLoweringObjectFile.h"
Daniel Dunbar51b198a2009-07-15 20:24:03 +000031#include "llvm/Target/TargetRegistry.h"
Brian Gaeke74dfcf12004-09-02 02:37:43 +000032#include "llvm/ADT/Statistic.h"
33#include "llvm/ADT/StringExtras.h"
34#include "llvm/Support/CommandLine.h"
Chris Lattner6c2f9e12009-08-19 05:49:37 +000035#include "llvm/Support/ErrorHandling.h"
36#include "llvm/Support/FormattedStream.h"
37#include "llvm/Support/Mangler.h"
Jim Laskeyb8df7c22005-08-17 20:04:34 +000038#include "llvm/Support/MathExtras.h"
Brian Gaekea8b00ca2004-03-06 05:30:21 +000039#include <cctype>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000040#include <cstring>
Owen Andersonc0078482008-07-10 01:44:27 +000041#include <map>
Brian Gaeke4acfd032004-03-04 06:00:41 +000042using namespace llvm;
43
Chris Lattner95b2c7d2006-12-19 22:59:26 +000044STATISTIC(EmittedInsts, "Number of machine instrs printed");
Brian Gaeke4acfd032004-03-04 06:00:41 +000045
Chris Lattner95b2c7d2006-12-19 22:59:26 +000046namespace {
Nick Lewycky6726b6d2009-10-25 06:33:48 +000047 class SparcAsmPrinter : public AsmPrinter {
Brian Gaeke4acfd032004-03-04 06:00:41 +000048 /// We name each basic block in a Function with a unique number, so
49 /// that we can consistently refer to them later. This is cleared
50 /// at the beginning of each call to runOnMachineFunction().
51 ///
52 typedef std::map<const Value *, unsigned> ValueMapTy;
53 ValueMapTy NumberForBB;
Owen Anderson2af72d42009-06-26 21:45:04 +000054 unsigned BBNumber;
Bill Wendling57f0db82009-02-24 08:30:20 +000055 public:
David Greene71847812009-07-14 20:18:05 +000056 explicit SparcAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Chris Lattneraf76e592009-08-22 20:48:53 +000057 const MCAsmInfo *T, bool V)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000058 : AsmPrinter(O, TM, T, V), BBNumber(0) {}
Brian Gaeke4acfd032004-03-04 06:00:41 +000059
Brian Gaeke4acfd032004-03-04 06:00:41 +000060 virtual const char *getPassName() const {
Chris Lattner7c90f732006-02-05 05:50:24 +000061 return "Sparc Assembly Printer";
Brian Gaeke4acfd032004-03-04 06:00:41 +000062 }
63
Chris Lattner40bbebd2009-07-21 18:38:57 +000064 void PrintGlobalVariable(const GlobalVariable *GVar);
Brian Gaeke446ae112004-06-15 19:52:59 +000065 void printOperand(const MachineInstr *MI, int opNum);
Chris Lattnerad7a3e62006-02-10 07:35:42 +000066 void printMemOperand(const MachineInstr *MI, int opNum,
67 const char *Modifier = 0);
Chris Lattner7c90f732006-02-05 05:50:24 +000068 void printCCOperand(const MachineInstr *MI, int opNum);
Chris Lattner6788faa2006-01-31 06:49:09 +000069
Chris Lattner41aefdc2009-08-08 01:32:19 +000070 void printInstruction(const MachineInstr *MI); // autogenerated.
Chris Lattnerd95148f2009-09-13 20:19:22 +000071 static const char *getRegisterName(unsigned RegNo);
Chris Lattner05af2612009-09-13 20:08:00 +000072
Misha Brukmanb5f662f2005-04-21 23:30:14 +000073 bool runOnMachineFunction(MachineFunction &F);
Anton Korobeynikovf3693302008-10-10 10:15:03 +000074 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
75 unsigned AsmVariant, const char *ExtraCode);
76 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
77 unsigned AsmVariant, const char *ExtraCode);
Chris Lattnerdb486a62009-09-15 17:46:24 +000078
79 void emitFunctionHeader(const MachineFunction &MF);
80 bool printGetPCX(const MachineInstr *MI, unsigned OpNo);
Brian Gaeke4acfd032004-03-04 06:00:41 +000081 };
82} // end of anonymous namespace
83
Chris Lattner7c90f732006-02-05 05:50:24 +000084#include "SparcGenAsmWriter.inc"
Chris Lattner994b7352005-12-16 06:34:17 +000085
Evan Cheng4eecdeb2008-02-02 08:39:46 +000086/// runOnMachineFunction - This uses the printInstruction()
Brian Gaeke4acfd032004-03-04 06:00:41 +000087/// method to print assembly for each instruction.
88///
Chris Lattner7c90f732006-02-05 05:50:24 +000089bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling57f0db82009-02-24 08:30:20 +000090 this->MF = &MF;
91
Chris Lattner1dbed162005-12-17 07:04:29 +000092 SetupMachineFunction(MF);
93
Chris Lattnerb5e9eb62005-12-17 07:11:43 +000094 // Print out constants referenced by the function
95 EmitConstantPool(MF.getConstantPool());
96
Brian Gaeke4acfd032004-03-04 06:00:41 +000097 // BBNumber is used here so that a given Printer will never give two
98 // BBs the same name. (If you have a better way, please let me know!)
Brian Gaeke4acfd032004-03-04 06:00:41 +000099
100 O << "\n\n";
Chris Lattnerdb486a62009-09-15 17:46:24 +0000101 emitFunctionHeader(MF);
102
103
Richard Pennington930e4d92009-09-08 12:47:30 +0000104 // Emit pre-function debug information.
105 DW->BeginFunction(&MF);
Brian Gaeke4acfd032004-03-04 06:00:41 +0000106
107 // Number each basic block so that we can consistently refer to them
108 // in PC-relative references.
Chris Lattner29bd9e12006-10-05 02:48:40 +0000109 // FIXME: Why not use the MBB numbers?
Brian Gaeke4acfd032004-03-04 06:00:41 +0000110 NumberForBB.clear();
111 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
112 I != E; ++I) {
113 NumberForBB[I->getBasicBlock()] = BBNumber++;
114 }
115
116 // Print out code for the function.
117 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
118 I != E; ++I) {
119 // Print a label for the basic block.
Nate Begemancdf38c42006-05-02 05:37:32 +0000120 if (I != MF.begin()) {
Chris Lattner70a54c02009-09-13 18:25:37 +0000121 EmitBasicBlockStart(I);
Nate Begemancdf38c42006-05-02 05:37:32 +0000122 }
Brian Gaeke4acfd032004-03-04 06:00:41 +0000123 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
Misha Brukman27177f82005-04-22 18:06:01 +0000124 II != E; ++II) {
Brian Gaeke4acfd032004-03-04 06:00:41 +0000125 // Print the assembly for the instruction.
Devang Patelaf0e2722009-10-06 02:19:11 +0000126 processDebugLoc(II, true);
Chris Lattner0d8fcd32005-12-17 06:54:41 +0000127 printInstruction(II);
Chris Lattnerc5ea2632009-09-09 23:14:36 +0000128
David Greene1924aab2009-11-13 21:34:57 +0000129 if (VerboseAsm)
Chris Lattnerc5ea2632009-09-09 23:14:36 +0000130 EmitComments(*II);
131 O << '\n';
Devang Patelaf0e2722009-10-06 02:19:11 +0000132 processDebugLoc(II, false);
Chris Lattner1dbed162005-12-17 07:04:29 +0000133 ++EmittedInsts;
Brian Gaeke4acfd032004-03-04 06:00:41 +0000134 }
135 }
136
Richard Pennington930e4d92009-09-08 12:47:30 +0000137 // Emit post-function debug information.
138 DW->EndFunction(&MF);
139
Brian Gaeke4acfd032004-03-04 06:00:41 +0000140 // We didn't modify anything.
Chris Lattnerdb486a62009-09-15 17:46:24 +0000141 O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
Brian Gaeke4acfd032004-03-04 06:00:41 +0000142 return false;
143}
144
Chris Lattnerdb486a62009-09-15 17:46:24 +0000145void SparcAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
146 const Function *F = MF.getFunction();
147 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
148 EmitAlignment(MF.getAlignment(), F);
149
150 switch (F->getLinkage()) {
151 default: llvm_unreachable("Unknown linkage type");
152 case Function::PrivateLinkage:
153 case Function::InternalLinkage:
154 // Function is internal.
155 break;
156 case Function::DLLExportLinkage:
157 case Function::ExternalLinkage:
158 // Function is externally visible
159 O << "\t.global\t" << CurrentFnName << '\n';
160 break;
161 case Function::LinkerPrivateLinkage:
162 case Function::LinkOnceAnyLinkage:
163 case Function::LinkOnceODRLinkage:
164 case Function::WeakAnyLinkage:
165 case Function::WeakODRLinkage:
166 // Function is weak
167 O << "\t.weak\t" << CurrentFnName << '\n' ;
168 break;
169 }
170
171 printVisibility(CurrentFnName, F->getVisibility());
172
173 O << "\t.type\t" << CurrentFnName << ", #function\n";
174 O << CurrentFnName << ":\n";
175}
176
177
Chris Lattner7c90f732006-02-05 05:50:24 +0000178void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000179 const MachineOperand &MO = MI->getOperand (opNum);
Brian Gaeke446ae112004-06-15 19:52:59 +0000180 bool CloseParen = false;
Dan Gohmand735b802008-10-03 15:45:36 +0000181 if (MI->getOpcode() == SP::SETHIi && !MO.isReg() && !MO.isImm()) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000182 O << "%hi(";
183 CloseParen = true;
Dan Gohmand735b802008-10-03 15:45:36 +0000184 } else if ((MI->getOpcode() == SP::ORri || MI->getOpcode() == SP::ADDri) &&
185 !MO.isReg() && !MO.isImm()) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000186 O << "%lo(";
187 CloseParen = true;
188 }
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000189 switch (MO.getType()) {
Chris Lattner2d90ac72006-05-04 18:05:43 +0000190 case MachineOperand::MO_Register:
Chris Lattner762ccea2009-09-13 20:31:40 +0000191 O << "%" << LowercaseString(getRegisterName(MO.getReg()));
Brian Gaeke446ae112004-06-15 19:52:59 +0000192 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000193
Chris Lattner63b3d712006-05-04 17:21:20 +0000194 case MachineOperand::MO_Immediate:
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000195 O << (int)MO.getImm();
Brian Gaeke446ae112004-06-15 19:52:59 +0000196 break;
Nate Begeman37efe672006-04-22 18:53:45 +0000197 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner325d3dc2009-09-13 17:14:04 +0000198 GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
Brian Gaeke09c13092004-06-17 19:39:23 +0000199 return;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000200 case MachineOperand::MO_GlobalAddress:
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000201 O << Mang->getMangledName(MO.getGlobal());
Brian Gaeke446ae112004-06-15 19:52:59 +0000202 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000203 case MachineOperand::MO_ExternalSymbol:
204 O << MO.getSymbolName();
Brian Gaeke446ae112004-06-15 19:52:59 +0000205 break;
Brian Gaeke8a0ae9e2004-06-27 22:50:44 +0000206 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattner33adcfb2009-08-22 21:43:10 +0000207 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
Chris Lattner8aa797a2007-12-30 23:10:15 +0000208 << MO.getIndex();
Brian Gaeke8a0ae9e2004-06-27 22:50:44 +0000209 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000210 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000211 llvm_unreachable("<unknown operand type>");
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000212 }
Brian Gaeke446ae112004-06-15 19:52:59 +0000213 if (CloseParen) O << ")";
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000214}
215
Chris Lattnerad7a3e62006-02-10 07:35:42 +0000216void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
217 const char *Modifier) {
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000218 printOperand(MI, opNum);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000219
Chris Lattnerad7a3e62006-02-10 07:35:42 +0000220 // If this is an ADD operand, emit it like normal operands.
221 if (Modifier && !strcmp(Modifier, "arith")) {
222 O << ", ";
223 printOperand(MI, opNum+1);
224 return;
225 }
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000226
Dan Gohmand735b802008-10-03 15:45:36 +0000227 if (MI->getOperand(opNum+1).isReg() &&
Chris Lattner7c90f732006-02-05 05:50:24 +0000228 MI->getOperand(opNum+1).getReg() == SP::G0)
Chris Lattner76acc872005-12-18 02:37:35 +0000229 return; // don't print "+%g0"
Dan Gohmand735b802008-10-03 15:45:36 +0000230 if (MI->getOperand(opNum+1).isImm() &&
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000231 MI->getOperand(opNum+1).getImm() == 0)
Chris Lattner76acc872005-12-18 02:37:35 +0000232 return; // don't print "+0"
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000233
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000234 O << "+";
Dan Gohmand735b802008-10-03 15:45:36 +0000235 if (MI->getOperand(opNum+1).isGlobal() ||
236 MI->getOperand(opNum+1).isCPI()) {
Chris Lattnere1389ad2005-12-18 02:27:00 +0000237 O << "%lo(";
238 printOperand(MI, opNum+1);
239 O << ")";
240 } else {
241 printOperand(MI, opNum+1);
242 }
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000243}
244
Chris Lattnerdb486a62009-09-15 17:46:24 +0000245bool SparcAsmPrinter::printGetPCX(const MachineInstr *MI, unsigned opNum) {
246 std::string operand = "";
247 const MachineOperand &MO = MI->getOperand(opNum);
248 switch (MO.getType()) {
249 default: assert(0 && "Operand is not a register ");
250 case MachineOperand::MO_Register:
251 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
252 "Operand is not a physical register ");
253 operand = "%" + LowercaseString(getRegisterName(MO.getReg()));
254 break;
255 }
256
257 unsigned bbNum = NumberForBB[MI->getParent()->getBasicBlock()];
258
259 O << '\n' << ".LLGETPCH" << bbNum << ":\n";
260 O << "\tcall\t.LLGETPC" << bbNum << '\n' ;
261
262 O << "\t sethi\t"
263 << "%hi(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << bbNum << ")), "
264 << operand << '\n' ;
265
266 O << ".LLGETPC" << bbNum << ":\n" ;
267 O << "\tor\t" << operand
268 << ", %lo(_GLOBAL_OFFSET_TABLE_+(.-.LLGETPCH" << bbNum << ")), "
269 << operand << '\n';
270 O << "\tadd\t" << operand << ", %o7, " << operand << '\n';
271
272 return true;
273}
274
Chris Lattner7c90f732006-02-05 05:50:24 +0000275void SparcAsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000276 int CC = (int)MI->getOperand(opNum).getImm();
Chris Lattner7c90f732006-02-05 05:50:24 +0000277 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
Chris Lattner6788faa2006-01-31 06:49:09 +0000278}
279
Chris Lattner40bbebd2009-07-21 18:38:57 +0000280void SparcAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000281 const TargetData *TD = TM.getTargetData();
282
283 if (!GVar->hasInitializer())
284 return; // External global require no code
285
286 // Check to see if this is a special global used by LLVM, if so, emit it.
287 if (EmitSpecialLLVMGlobal(GVar))
288 return;
289
290 O << "\n\n";
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000291 std::string name = Mang->getMangledName(GVar);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000292 Constant *C = GVar->getInitializer();
Duncan Sands777d2302009-05-09 07:06:46 +0000293 unsigned Size = TD->getTypeAllocSize(C->getType());
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000294 unsigned Align = TD->getPreferredAlignment(GVar);
295
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000296 printVisibility(name, GVar->getVisibility());
297
Chris Lattner6c2f9e12009-08-19 05:49:37 +0000298 OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
299 TM));
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000300
301 if (C->isNullValue() && !GVar->hasSection()) {
302 if (!GVar->isThreadLocal() &&
Duncan Sands667d4b82009-03-07 15:45:40 +0000303 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000304 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
305
Rafael Espindolabb46f522009-01-15 20:18:42 +0000306 if (GVar->hasLocalLinkage())
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000307 O << "\t.local " << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000308
Chris Lattner33adcfb2009-08-22 21:43:10 +0000309 O << MAI->getCOMMDirective() << name << ',' << Size;
310 if (MAI->getCOMMDirectiveTakesAlignment())
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000311 O << ',' << (1 << Align);
312
313 O << '\n';
314 return;
315 }
316 }
317
318 switch (GVar->getLinkage()) {
Duncan Sands4dc2b392009-03-11 20:14:15 +0000319 case GlobalValue::CommonLinkage:
Duncan Sands667d4b82009-03-07 15:45:40 +0000320 case GlobalValue::LinkOnceAnyLinkage:
321 case GlobalValue::LinkOnceODRLinkage:
322 case GlobalValue::WeakAnyLinkage: // FIXME: Verify correct for weak.
323 case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak.
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000324 // Nonnull linkonce -> weak
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000325 O << "\t.weak " << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000326 break;
327 case GlobalValue::AppendingLinkage:
328 // FIXME: appending linkage variables should go into a section of
329 // their name or something. For now, just emit them as external.
330 case GlobalValue::ExternalLinkage:
331 // If external or appending, declare as a global symbol
Chris Lattner33adcfb2009-08-22 21:43:10 +0000332 O << MAI->getGlobalDirective() << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000333 // FALL THROUGH
Rafael Espindolabb46f522009-01-15 20:18:42 +0000334 case GlobalValue::PrivateLinkage:
Bill Wendling3d10a5a2009-07-20 01:03:30 +0000335 case GlobalValue::LinkerPrivateLinkage:
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000336 case GlobalValue::InternalLinkage:
337 break;
338 case GlobalValue::GhostLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000339 llvm_unreachable("Should not have any unmaterialized functions!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000340 case GlobalValue::DLLImportLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000341 llvm_unreachable("DLLImport linkage is not supported by this target!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000342 case GlobalValue::DLLExportLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000343 llvm_unreachable("DLLExport linkage is not supported by this target!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000344 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000345 llvm_unreachable("Unknown linkage type!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000346 }
347
Anton Korobeynikovfcd99bb2008-08-07 09:53:38 +0000348 EmitAlignment(Align, GVar);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000349
Chris Lattner33adcfb2009-08-22 21:43:10 +0000350 if (MAI->hasDotTypeDotSizeDirective()) {
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000351 O << "\t.type " << name << ",#object\n";
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000352 O << "\t.size " << name << ',' << Size << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000353 }
354
355 O << name << ":\n";
356 EmitGlobalConstant(C);
357}
Anton Korobeynikovf3693302008-10-10 10:15:03 +0000358
359/// PrintAsmOperand - Print out an operand for an inline asm expression.
360///
361bool SparcAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
362 unsigned AsmVariant,
363 const char *ExtraCode) {
Anton Korobeynikov4cf5e2e2008-10-10 20:29:50 +0000364 if (ExtraCode && ExtraCode[0]) {
365 if (ExtraCode[1] != 0) return true; // Unknown modifier.
366
367 switch (ExtraCode[0]) {
368 default: return true; // Unknown modifier.
369 case 'r':
370 break;
371 }
372 }
Anton Korobeynikovf3693302008-10-10 10:15:03 +0000373
374 printOperand(MI, OpNo);
375
376 return false;
377}
378
379bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
380 unsigned OpNo,
381 unsigned AsmVariant,
382 const char *ExtraCode) {
383 if (ExtraCode && ExtraCode[0])
384 return true; // Unknown modifier
385
386 O << '[';
387 printMemOperand(MI, OpNo);
388 O << ']';
389
390 return false;
391}
Douglas Gregor1555a232009-06-16 20:12:29 +0000392
Bob Wilsona96751f2009-06-23 23:59:40 +0000393// Force static initialization.
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000394extern "C" void LLVMInitializeSparcAsmPrinter() {
Daniel Dunbar0c795d62009-07-25 06:49:55 +0000395 RegisterAsmPrinter<SparcAsmPrinter> X(TheSparcTarget);
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000396}