blob: eb0f2f1b36714cf20a6e50f04f72937dbc4f3942 [file] [log] [blame]
Chris Lattnera80ba712004-08-16 23:15:22 +00001//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
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//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng932f0222006-03-03 02:04:29 +000014#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng246ae0d2006-03-01 22:18:09 +000015#include "llvm/Assembly/Writer.h"
Nate Begeman8cfa57b2005-12-06 06:18:55 +000016#include "llvm/DerivedTypes.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000017#include "llvm/Constants.h"
Chris Lattner450de392005-11-10 18:36:17 +000018#include "llvm/Module.h"
Chris Lattner3b4fd322005-11-21 08:25:09 +000019#include "llvm/CodeGen/MachineConstantPool.h"
Nate Begeman37efe672006-04-22 18:53:45 +000020#include "llvm/CodeGen/MachineJumpTableInfo.h"
Jim Laskeyf1cdea12007-01-25 15:12:02 +000021#include "llvm/Support/CommandLine.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000022#include "llvm/Support/Mangler.h"
Jim Laskeycb6682f2005-08-17 19:34:49 +000023#include "llvm/Support/MathExtras.h"
Bill Wendlingbdc679d2006-11-29 00:39:47 +000024#include "llvm/Support/Streams.h"
Jim Laskey563321a2006-09-06 18:34:40 +000025#include "llvm/Target/TargetAsmInfo.h"
Owen Anderson07000c62006-05-12 06:33:49 +000026#include "llvm/Target/TargetData.h"
Chris Lattner0336fdb2006-10-06 22:50:56 +000027#include "llvm/Target/TargetLowering.h"
Chris Lattnera80ba712004-08-16 23:15:22 +000028#include "llvm/Target/TargetMachine.h"
Chris Lattner66099132006-02-01 22:41:11 +000029#include <cerrno>
Chris Lattnera80ba712004-08-16 23:15:22 +000030using namespace llvm;
31
Jim Laskeyf1cdea12007-01-25 15:12:02 +000032static cl::opt<bool>
33AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
34
Jim Laskeya0f3d172006-09-07 22:06:40 +000035AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
36 const TargetAsmInfo *T)
Jim Laskey563321a2006-09-06 18:34:40 +000037: FunctionNumber(0), O(o), TM(tm), TAI(T)
38{}
Chris Lattnered138932005-12-13 06:32:10 +000039
Chris Lattner52f06702006-10-05 02:42:47 +000040std::string AsmPrinter::getSectionForFunction(const Function &F) const {
41 return TAI->getTextSection();
42}
43
Chris Lattnered138932005-12-13 06:32:10 +000044
Chris Lattner4632d7a2006-05-09 04:59:56 +000045/// SwitchToTextSection - Switch to the specified text section of the executable
46/// if we are not already in it!
Chris Lattnerac28fbd2005-11-21 07:06:27 +000047///
Chris Lattner4632d7a2006-05-09 04:59:56 +000048void AsmPrinter::SwitchToTextSection(const char *NewSection,
49 const GlobalValue *GV) {
Chris Lattnerac28fbd2005-11-21 07:06:27 +000050 std::string NS;
Chris Lattnera7090ae2006-05-09 05:24:50 +000051 if (GV && GV->hasSection())
Jim Laskey563321a2006-09-06 18:34:40 +000052 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
Chris Lattnera7090ae2006-05-09 05:24:50 +000053 else
54 NS = NewSection;
55
56 // If we're already in this section, we're done.
57 if (CurrentSection == NS) return;
Jeff Cohen51b776d2006-05-02 03:58:45 +000058
Chris Lattner7faec9b2006-05-09 05:33:48 +000059 // Close the current section, if applicable.
Jim Laskey563321a2006-09-06 18:34:40 +000060 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
61 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
Jeff Cohen51b776d2006-05-02 03:58:45 +000062
Chris Lattner7faec9b2006-05-09 05:33:48 +000063 CurrentSection = NS;
64
65 if (!CurrentSection.empty())
Jim Laskey563321a2006-09-06 18:34:40 +000066 O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
Chris Lattnerac28fbd2005-11-21 07:06:27 +000067}
68
Nate Begeman2f1ae882006-07-27 01:13:04 +000069/// SwitchToDataSection - Switch to the specified data section of the executable
Chris Lattner4632d7a2006-05-09 04:59:56 +000070/// if we are not already in it!
71///
72void AsmPrinter::SwitchToDataSection(const char *NewSection,
73 const GlobalValue *GV) {
74 std::string NS;
Chris Lattnerb81cb612006-05-09 05:23:12 +000075 if (GV && GV->hasSection())
Jim Laskey563321a2006-09-06 18:34:40 +000076 NS = TAI->getSwitchToSectionDirective() + GV->getSection();
Chris Lattnerb81cb612006-05-09 05:23:12 +000077 else
78 NS = NewSection;
Chris Lattner4632d7a2006-05-09 04:59:56 +000079
Chris Lattnerb81cb612006-05-09 05:23:12 +000080 // If we're already in this section, we're done.
81 if (CurrentSection == NS) return;
82
Chris Lattner7faec9b2006-05-09 05:33:48 +000083 // Close the current section, if applicable.
Jim Laskey563321a2006-09-06 18:34:40 +000084 if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
85 O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
Chris Lattner7faec9b2006-05-09 05:33:48 +000086
87 CurrentSection = NS;
Chris Lattner4632d7a2006-05-09 04:59:56 +000088
Chris Lattner7faec9b2006-05-09 05:33:48 +000089 if (!CurrentSection.empty())
Jim Laskey563321a2006-09-06 18:34:40 +000090 O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
Chris Lattner4632d7a2006-05-09 04:59:56 +000091}
92
93
Chris Lattnera80ba712004-08-16 23:15:22 +000094bool AsmPrinter::doInitialization(Module &M) {
Jim Laskey563321a2006-09-06 18:34:40 +000095 Mang = new Mangler(M, TAI->getGlobalPrefix());
Chris Lattner2c1b1592006-01-23 23:47:53 +000096
Chris Lattner3e2fa7a2006-01-24 04:16:34 +000097 if (!M.getModuleInlineAsm().empty())
Jim Laskey563321a2006-09-06 18:34:40 +000098 O << TAI->getCommentString() << " Start of file scope inline assembly\n"
Chris Lattner3e2fa7a2006-01-24 04:16:34 +000099 << M.getModuleInlineAsm()
Jim Laskey563321a2006-09-06 18:34:40 +0000100 << "\n" << TAI->getCommentString()
101 << " End of file scope inline assembly\n";
Chris Lattner2c1b1592006-01-23 23:47:53 +0000102
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000103 SwitchToDataSection(""); // Reset back to no section.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000104
Jim Laskey44c3b9f2007-01-26 21:22:28 +0000105 if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>()) {
106 MMI->AnalyzeModule(M);
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000107 }
108
Chris Lattnera80ba712004-08-16 23:15:22 +0000109 return false;
110}
111
112bool AsmPrinter::doFinalization(Module &M) {
Rafael Espindola15404d02006-12-18 03:37:18 +0000113 if (TAI->getWeakRefDirective()) {
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000114 if (!ExtWeakSymbols.empty())
Rafael Espindola15404d02006-12-18 03:37:18 +0000115 SwitchToDataSection("");
116
117 for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
118 e = ExtWeakSymbols.end(); i != e; ++i) {
119 const GlobalValue *GV = *i;
120 std::string Name = Mang->getValueName(GV);
121 O << TAI->getWeakRefDirective() << Name << "\n";
122 }
123 }
124
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000125 if (TAI->getSetDirective()) {
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000126 if (!M.alias_empty())
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000127 SwitchToTextSection(TAI->getTextSection());
128
129 O << "\n";
130 for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
131 I!=E; ++I) {
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000132 std::string Name = Mang->getValueName(I);
133 std::string Target;
134
Anton Korobeynikovc6c98af2007-04-29 18:02:48 +0000135 if (const GlobalValue *GV = I->getAliasedGlobal())
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000136 Target = Mang->getValueName(GV);
Anton Korobeynikovc6c98af2007-04-29 18:02:48 +0000137 else
138 assert(0 && "Unsupported aliasee");
Anton Korobeynikova80e1182007-04-28 13:45:00 +0000139
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000140 if (I->hasExternalLinkage())
141 O << "\t.globl\t" << Name << "\n";
142 else if (I->hasWeakLinkage())
143 O << TAI->getWeakRefDirective() << Name << "\n";
144 else if (!I->hasInternalLinkage())
145 assert(0 && "Invalid alias linkage");
146
147 O << TAI->getSetDirective() << Name << ", " << Target << "\n";
148 }
149 }
150
Chris Lattnera80ba712004-08-16 23:15:22 +0000151 delete Mang; Mang = 0;
152 return false;
153}
154
Chris Lattner25045bd2005-11-21 07:51:36 +0000155void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000156 // What's my mangled name?
Chris Lattner450de392005-11-10 18:36:17 +0000157 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner77bc2282005-11-21 08:13:27 +0000158 IncrementFunctionNumber();
Chris Lattnera80ba712004-08-16 23:15:22 +0000159}
160
Chris Lattner3b4fd322005-11-21 08:25:09 +0000161/// EmitConstantPool - Print to the current output stream assembly
162/// representations of the constants in the constant pool MCP. This is
163/// used to print out constants which have been "spilled to memory" by
164/// the code generator.
165///
166void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerfa77d432006-02-09 04:22:52 +0000167 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattner3b4fd322005-11-21 08:25:09 +0000168 if (CP.empty()) return;
Evan Cheng2d2cec12006-06-29 00:26:09 +0000169
170 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
171 // in special sections.
172 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
173 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
174 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
175 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
Evan Chengd6594ae2006-09-12 21:00:35 +0000176 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
Chris Lattner3b4fd322005-11-21 08:25:09 +0000177 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Evan Cheng2d2cec12006-06-29 00:26:09 +0000178 MachineConstantPoolEntry CPE = CP[i];
Evan Chengd5a99d72006-09-14 07:35:00 +0000179 const Type *Ty = CPE.getType();
Jim Laskey563321a2006-09-06 18:34:40 +0000180 if (TAI->getFourByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000181 TM.getTargetData()->getTypeSize(Ty) == 4)
182 FourByteCPs.push_back(std::make_pair(CPE, i));
Evan Cheng61c958e2006-09-07 18:50:20 +0000183 else if (TAI->getEightByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000184 TM.getTargetData()->getTypeSize(Ty) == 8)
185 EightByteCPs.push_back(std::make_pair(CPE, i));
Evan Cheng61c958e2006-09-07 18:50:20 +0000186 else if (TAI->getSixteenByteConstantSection() &&
Evan Cheng2d2cec12006-06-29 00:26:09 +0000187 TM.getTargetData()->getTypeSize(Ty) == 16)
188 SixteenByteCPs.push_back(std::make_pair(CPE, i));
189 else
190 OtherCPs.push_back(std::make_pair(CPE, i));
191 }
192
193 unsigned Alignment = MCP->getConstantPoolAlignment();
Jim Laskey563321a2006-09-06 18:34:40 +0000194 EmitConstantPool(Alignment, TAI->getFourByteConstantSection(), FourByteCPs);
195 EmitConstantPool(Alignment, TAI->getEightByteConstantSection(), EightByteCPs);
196 EmitConstantPool(Alignment, TAI->getSixteenByteConstantSection(),
197 SixteenByteCPs);
198 EmitConstantPool(Alignment, TAI->getConstantPoolSection(), OtherCPs);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000199}
200
201void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
202 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
203 if (CP.empty()) return;
204
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000205 SwitchToDataSection(Section);
Evan Cheng2d2cec12006-06-29 00:26:09 +0000206 EmitAlignment(Alignment);
207 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Jim Laskey563321a2006-09-06 18:34:40 +0000208 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
209 << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
Evan Chengd5a99d72006-09-14 07:35:00 +0000210 WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
211 if (CP[i].first.isMachineConstantPoolEntry())
Evan Chengd6594ae2006-09-12 21:00:35 +0000212 EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
Evan Chengd5a99d72006-09-14 07:35:00 +0000213 else
Evan Chengd6594ae2006-09-12 21:00:35 +0000214 EmitGlobalConstant(CP[i].first.Val.ConstVal);
Chris Lattner3029f922006-02-09 04:46:04 +0000215 if (i != e-1) {
Evan Chengd5a99d72006-09-14 07:35:00 +0000216 const Type *Ty = CP[i].first.getType();
Evan Cheng2d2cec12006-06-29 00:26:09 +0000217 unsigned EntSize =
Evan Chengd6594ae2006-09-12 21:00:35 +0000218 TM.getTargetData()->getTypeSize(Ty);
Evan Chengd5a99d72006-09-14 07:35:00 +0000219 unsigned ValEnd = CP[i].first.getOffset() + EntSize;
Chris Lattner3029f922006-02-09 04:46:04 +0000220 // Emit inter-object padding for alignment.
Evan Chengd5a99d72006-09-14 07:35:00 +0000221 EmitZeros(CP[i+1].first.getOffset()-ValEnd);
Chris Lattner3029f922006-02-09 04:46:04 +0000222 }
Chris Lattner3b4fd322005-11-21 08:25:09 +0000223 }
224}
225
Nate Begeman37efe672006-04-22 18:53:45 +0000226/// EmitJumpTableInfo - Print assembly representations of the jump tables used
227/// by the current function to the current output stream.
228///
Chris Lattner1da31ee2006-10-05 03:01:21 +0000229void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
230 MachineFunction &MF) {
Nate Begeman37efe672006-04-22 18:53:45 +0000231 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
232 if (JT.empty()) return;
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000233 bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000234
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000235 // Use JumpTableDirective otherwise honor the entry size from the jump table
236 // info.
Andrew Lenharthbeec30e2006-09-24 19:45:58 +0000237 const char *JTEntryDirective = TAI->getJumpTableDirective();
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000238 bool HadJTEntryDirective = JTEntryDirective != NULL;
239 if (!HadJTEntryDirective) {
240 JTEntryDirective = MJTI->getEntrySize() == 4 ?
241 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
242 }
Nate Begeman37efe672006-04-22 18:53:45 +0000243
Nate Begeman2f1ae882006-07-27 01:13:04 +0000244 // Pick the directive to use to print the jump table entries, and switch to
245 // the appropriate section.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000246 TargetLowering *LoweringInfo = TM.getTargetLowering();
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000247
248 const char* JumpTableDataSection = TAI->getJumpTableDataSection();
249 if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
250 !JumpTableDataSection) {
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000251 // In PIC mode, we need to emit the jump table to the same section as the
252 // function body itself, otherwise the label differences won't make sense.
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000253 // We should also do if the section name is NULL.
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000254 const Function *F = MF.getFunction();
255 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000256 } else {
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000257 SwitchToDataSection(JumpTableDataSection);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000258 }
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000259
260 EmitAlignment(Log2_32(MJTI->getAlignment()));
Chris Lattner0c4e6782006-07-15 01:34:12 +0000261
Nate Begeman37efe672006-04-22 18:53:45 +0000262 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000263 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
Chris Lattner07371882006-10-28 18:10:06 +0000264
265 // If this jump table was deleted, ignore it.
266 if (JTBBs.empty()) continue;
Nate Begeman52a51e382006-08-12 21:29:52 +0000267
268 // For PIC codegen, if possible we want to use the SetDirective to reduce
269 // the number of relocations the assembler will generate for the jump table.
270 // Set directives are all printed before the jump table itself.
271 std::set<MachineBasicBlock*> EmittedSets;
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000272 if (TAI->getSetDirective() && IsPic)
Nate Begeman52a51e382006-08-12 21:29:52 +0000273 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
274 if (EmittedSets.insert(JTBBs[ii]).second)
275 printSetLabel(i, JTBBs[ii]);
276
Chris Lattner393a8ee2007-01-18 01:12:56 +0000277 // On some targets (e.g. darwin) we want to emit two consequtive labels
278 // before each jump table. The first label is never referenced, but tells
279 // the assembler and linker the extents of the jump table object. The
280 // second label is actually referenced by the code.
281 if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
282 O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
283
Jim Laskey563321a2006-09-06 18:34:40 +0000284 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
285 << '_' << i << ":\n";
Nate Begeman52a51e382006-08-12 21:29:52 +0000286
Nate Begeman37efe672006-04-22 18:53:45 +0000287 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Nate Begeman4d9bbdc2006-07-27 16:46:58 +0000288 O << JTEntryDirective << ' ';
Nate Begeman52a51e382006-08-12 21:29:52 +0000289 // If we have emitted set directives for the jump table entries, print
290 // them rather than the entries themselves. If we're emitting PIC, then
291 // emit the table entries as differences between two text section labels.
292 // If we're emitting non-PIC code, then emit the entries as direct
293 // references to the target basic blocks.
294 if (!EmittedSets.empty()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000295 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
296 << '_' << i << "_set_" << JTBBs[ii]->getNumber();
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000297 } else if (IsPic) {
Nate Begeman52a51e382006-08-12 21:29:52 +0000298 printBasicBlockLabel(JTBBs[ii], false, false);
Chris Lattner393a8ee2007-01-18 01:12:56 +0000299 // If the arch uses custom Jump Table directives, don't calc relative to
300 // JT
Jim Laskeyacd80ac2006-12-14 19:17:33 +0000301 if (!HadJTEntryDirective)
302 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
303 << getFunctionNumber() << '_' << i;
Nate Begeman52a51e382006-08-12 21:29:52 +0000304 } else {
305 printBasicBlockLabel(JTBBs[ii], false, false);
Nate Begeman2f1ae882006-07-27 01:13:04 +0000306 }
Nate Begeman37efe672006-04-22 18:53:45 +0000307 O << '\n';
308 }
309 }
310}
311
Chris Lattnered138932005-12-13 06:32:10 +0000312/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
313/// special global used by LLVM. If so, emit it and return true, otherwise
314/// do nothing and return false.
315bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Jim Laskey78098112006-03-07 22:00:35 +0000316 // Ignore debug and non-emitted data.
317 if (GV->getSection() == "llvm.metadata") return true;
318
319 if (!GV->hasAppendingLinkage()) return false;
320
321 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnered138932005-12-13 06:32:10 +0000322
Chris Lattnercb05af82006-09-26 03:38:18 +0000323 if (GV->getName() == "llvm.used") {
324 if (TAI->getUsedDirective() != 0) // No need to emit this at all.
325 EmitLLVMUsedList(GV->getInitializer());
326 return true;
327 }
Chris Lattnered138932005-12-13 06:32:10 +0000328
Chris Lattner5166b822006-01-12 19:17:23 +0000329 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000330 SwitchToDataSection(TAI->getStaticCtorsSection());
Chris Lattnered138932005-12-13 06:32:10 +0000331 EmitAlignment(2, 0);
332 EmitXXStructorList(GV->getInitializer());
333 return true;
334 }
335
Chris Lattner5166b822006-01-12 19:17:23 +0000336 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000337 SwitchToDataSection(TAI->getStaticDtorsSection());
Chris Lattnered138932005-12-13 06:32:10 +0000338 EmitAlignment(2, 0);
339 EmitXXStructorList(GV->getInitializer());
340 return true;
341 }
342
343 return false;
344}
345
Chris Lattnercb05af82006-09-26 03:38:18 +0000346/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
347/// global in the specified llvm.used list as being used with this directive.
348void AsmPrinter::EmitLLVMUsedList(Constant *List) {
349 const char *Directive = TAI->getUsedDirective();
350
351 // Should be an array of 'sbyte*'.
352 ConstantArray *InitList = dyn_cast<ConstantArray>(List);
353 if (InitList == 0) return;
354
355 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
356 O << Directive;
357 EmitConstantValueOnly(InitList->getOperand(i));
358 O << "\n";
359 }
360}
361
Chris Lattnered138932005-12-13 06:32:10 +0000362/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
363/// function pointers, ignoring the init priority.
364void AsmPrinter::EmitXXStructorList(Constant *List) {
365 // Should be an array of '{ int, void ()* }' structs. The first value is the
366 // init priority, which we ignore.
367 if (!isa<ConstantArray>(List)) return;
368 ConstantArray *InitList = cast<ConstantArray>(List);
369 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
370 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
371 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner8de324b2005-12-21 01:17:37 +0000372
373 if (CS->getOperand(1)->isNullValue())
374 return; // Found a null terminator, exit printing.
375 // Emit the function pointer.
Chris Lattnered138932005-12-13 06:32:10 +0000376 EmitGlobalConstant(CS->getOperand(1));
377 }
378}
Chris Lattner3b4fd322005-11-21 08:25:09 +0000379
Jim Laskeya1a19f82006-10-17 13:41:07 +0000380/// getGlobalLinkName - Returns the asm/link name of of the specified
381/// global variable. Should be overridden by each target asm printer to
382/// generate the appropriate value.
Jim Laskey99e41ee2006-10-17 17:17:24 +0000383const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
384 std::string LinkName;
Jim Laskey03742482006-11-20 20:29:06 +0000385
386 if (isa<Function>(GV)) {
387 LinkName += TAI->getFunctionAddrPrefix();
388 LinkName += Mang->getValueName(GV);
389 LinkName += TAI->getFunctionAddrSuffix();
390 } else {
391 LinkName += TAI->getGlobalVarAddrPrefix();
392 LinkName += Mang->getValueName(GV);
393 LinkName += TAI->getGlobalVarAddrSuffix();
394 }
395
Jim Laskey99e41ee2006-10-17 17:17:24 +0000396 return LinkName;
Jim Laskeya1a19f82006-10-17 13:41:07 +0000397}
398
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000399/// EmitExternalGlobal - Emit the external reference to a global variable.
400/// Should be overridden if an indirect reference should be used.
401void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
402 O << getGlobalLinkName(GV);
403}
404
405
406
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000407//===----------------------------------------------------------------------===//
408/// LEB 128 number encoding.
409
410/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
411/// representing an unsigned leb128 value.
412void AsmPrinter::PrintULEB128(unsigned Value) const {
413 do {
414 unsigned Byte = Value & 0x7f;
415 Value >>= 7;
416 if (Value) Byte |= 0x80;
417 O << "0x" << std::hex << Byte << std::dec;
418 if (Value) O << ", ";
419 } while (Value);
420}
421
422/// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
423/// value.
424unsigned AsmPrinter::SizeULEB128(unsigned Value) {
425 unsigned Size = 0;
426 do {
427 Value >>= 7;
428 Size += sizeof(int8_t);
429 } while (Value);
430 return Size;
431}
432
433/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
434/// representing a signed leb128 value.
435void AsmPrinter::PrintSLEB128(int Value) const {
436 int Sign = Value >> (8 * sizeof(Value) - 1);
437 bool IsMore;
438
439 do {
440 unsigned Byte = Value & 0x7f;
441 Value >>= 7;
442 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
443 if (IsMore) Byte |= 0x80;
444 O << "0x" << std::hex << Byte << std::dec;
445 if (IsMore) O << ", ";
446 } while (IsMore);
447}
448
449/// SizeSLEB128 - Compute the number of bytes required for a signed leb128
450/// value.
451unsigned AsmPrinter::SizeSLEB128(int Value) {
452 unsigned Size = 0;
453 int Sign = Value >> (8 * sizeof(Value) - 1);
454 bool IsMore;
455
456 do {
457 unsigned Byte = Value & 0x7f;
458 Value >>= 7;
459 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
460 Size += sizeof(int8_t);
461 } while (IsMore);
462 return Size;
463}
464
465//===--------------------------------------------------------------------===//
466// Emission and print routines
467//
468
469/// PrintHex - Print a value as a hexidecimal value.
470///
471void AsmPrinter::PrintHex(int Value) const {
472 O << "0x" << std::hex << Value << std::dec;
473}
474
475/// EOL - Print a newline character to asm stream. If a comment is present
476/// then it will be printed first. Comments should not contain '\n'.
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000477void AsmPrinter::EOL() const {
478 O << "\n";
479}
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000480void AsmPrinter::EOL(const std::string &Comment) const {
481 if (AsmVerbose && !Comment.empty()) {
482 O << "\t"
483 << TAI->getCommentString()
484 << " "
485 << Comment;
486 }
487 O << "\n";
488}
489
490/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
491/// unsigned leb128 value.
492void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
493 if (TAI->hasLEB128()) {
494 O << "\t.uleb128\t"
495 << Value;
496 } else {
497 O << TAI->getData8bitsDirective();
498 PrintULEB128(Value);
499 }
500}
501
502/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
503/// signed leb128 value.
504void AsmPrinter::EmitSLEB128Bytes(int Value) const {
505 if (TAI->hasLEB128()) {
506 O << "\t.sleb128\t"
507 << Value;
508 } else {
509 O << TAI->getData8bitsDirective();
510 PrintSLEB128(Value);
511 }
512}
513
514/// EmitInt8 - Emit a byte directive and value.
515///
516void AsmPrinter::EmitInt8(int Value) const {
517 O << TAI->getData8bitsDirective();
518 PrintHex(Value & 0xFF);
519}
520
521/// EmitInt16 - Emit a short directive and value.
522///
523void AsmPrinter::EmitInt16(int Value) const {
524 O << TAI->getData16bitsDirective();
525 PrintHex(Value & 0xFFFF);
526}
527
528/// EmitInt32 - Emit a long directive and value.
529///
530void AsmPrinter::EmitInt32(int Value) const {
531 O << TAI->getData32bitsDirective();
532 PrintHex(Value);
533}
534
535/// EmitInt64 - Emit a long long directive and value.
536///
537void AsmPrinter::EmitInt64(uint64_t Value) const {
538 if (TAI->getData64bitsDirective()) {
539 O << TAI->getData64bitsDirective();
540 PrintHex(Value);
541 } else {
542 if (TM.getTargetData()->isBigEndian()) {
543 EmitInt32(unsigned(Value >> 32)); O << "\n";
544 EmitInt32(unsigned(Value));
545 } else {
546 EmitInt32(unsigned(Value)); O << "\n";
547 EmitInt32(unsigned(Value >> 32));
548 }
549 }
550}
551
552/// toOctal - Convert the low order bits of X into an octal digit.
553///
554static inline char toOctal(int X) {
555 return (X&7)+'0';
556}
557
558/// printStringChar - Print a char, escaped if necessary.
559///
560static void printStringChar(std::ostream &O, unsigned char C) {
561 if (C == '"') {
562 O << "\\\"";
563 } else if (C == '\\') {
564 O << "\\\\";
565 } else if (isprint(C)) {
566 O << C;
567 } else {
568 switch(C) {
569 case '\b': O << "\\b"; break;
570 case '\f': O << "\\f"; break;
571 case '\n': O << "\\n"; break;
572 case '\r': O << "\\r"; break;
573 case '\t': O << "\\t"; break;
574 default:
575 O << '\\';
576 O << toOctal(C >> 6);
577 O << toOctal(C >> 3);
578 O << toOctal(C >> 0);
579 break;
580 }
581 }
582}
583
584/// EmitString - Emit a string with quotes and a null terminator.
585/// Special characters are emitted properly.
586/// \literal (Eg. '\t') \endliteral
587void AsmPrinter::EmitString(const std::string &String) const {
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000588 const char* AscizDirective = TAI->getAscizDirective();
589 if (AscizDirective)
590 O << AscizDirective;
591 else
592 O << TAI->getAsciiDirective();
593 O << "\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000594 for (unsigned i = 0, N = String.size(); i < N; ++i) {
595 unsigned char C = String[i];
596 printStringChar(O, C);
597 }
Anton Korobeynikovfb269cf2007-03-06 19:25:02 +0000598 if (AscizDirective)
599 O << "\"";
600 else
601 O << "\\0\"";
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000602}
603
604
605//===----------------------------------------------------------------------===//
606
Chris Lattner25045bd2005-11-21 07:51:36 +0000607// EmitAlignment - Emit an alignment directive to the specified power of two.
Dale Johannesen19f54692007-04-23 19:58:54 +0000608// Use the maximum of the specified alignment and the alignment from the
609// specified GlobalValue (if any).
Chris Lattner25045bd2005-11-21 07:51:36 +0000610void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Dale Johannesen00d56b92007-04-23 23:33:31 +0000611 if (GV && GV->getAlignment())
612 NumBits = std::max(NumBits, Log2_32(GV->getAlignment()));
Chris Lattner2a21c6e2005-11-10 18:09:27 +0000613 if (NumBits == 0) return; // No need to emit alignment.
Jim Laskey563321a2006-09-06 18:34:40 +0000614 if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
615 O << TAI->getAlignDirective() << NumBits << "\n";
Chris Lattnerbfddc202004-08-17 19:14:29 +0000616}
617
Jim Laskeybda9b0e2007-02-21 22:47:38 +0000618
Chris Lattner25045bd2005-11-21 07:51:36 +0000619/// EmitZeros - Emit a block of zeros.
Chris Lattner7d057a32004-08-17 21:38:40 +0000620///
Chris Lattner25045bd2005-11-21 07:51:36 +0000621void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattner7d057a32004-08-17 21:38:40 +0000622 if (NumZeros) {
Jim Laskey563321a2006-09-06 18:34:40 +0000623 if (TAI->getZeroDirective()) {
624 O << TAI->getZeroDirective() << NumZeros;
625 if (TAI->getZeroDirectiveSuffix())
626 O << TAI->getZeroDirectiveSuffix();
Jeff Cohenc6a057b2006-05-02 03:46:13 +0000627 O << "\n";
628 } else {
Chris Lattner7d057a32004-08-17 21:38:40 +0000629 for (; NumZeros; --NumZeros)
Jim Laskey563321a2006-09-06 18:34:40 +0000630 O << TAI->getData8bitsDirective() << "0\n";
Chris Lattner7d057a32004-08-17 21:38:40 +0000631 }
632 }
633}
634
Chris Lattnera80ba712004-08-16 23:15:22 +0000635// Print out the specified constant, without a storage class. Only the
636// constants valid in constant expressions can occur here.
Chris Lattner25045bd2005-11-21 07:51:36 +0000637void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000638 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattnera80ba712004-08-16 23:15:22 +0000639 O << "0";
Zhou Sheng6b6b6ef2007-01-11 12:24:14 +0000640 else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Chris Lattnera875df32007-01-12 18:15:09 +0000641 O << CI->getZExtValue();
Reid Spencerb83eb642006-10-20 07:07:24 +0000642 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina855a5192005-04-02 12:21:51 +0000643 // This is a constant address for a global variable or function. Use the
644 // name of the variable or function as the address value, possibly
645 // decorating it with GlobalVarAddrPrefix/Suffix or
646 // FunctionAddrPrefix/Suffix (these all default to "" )
Jim Laskey563321a2006-09-06 18:34:40 +0000647 if (isa<Function>(GV)) {
648 O << TAI->getFunctionAddrPrefix()
649 << Mang->getValueName(GV)
650 << TAI->getFunctionAddrSuffix();
651 } else {
652 O << TAI->getGlobalVarAddrPrefix()
653 << Mang->getValueName(GV)
654 << TAI->getGlobalVarAddrSuffix();
655 }
Duraid Madina855a5192005-04-02 12:21:51 +0000656 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000657 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000658 unsigned Opcode = CE->getOpcode();
659 switch (Opcode) {
Chris Lattnera80ba712004-08-16 23:15:22 +0000660 case Instruction::GetElementPtr: {
661 // generate a symbolic expression for the byte address
662 const Constant *ptrVal = CE->getOperand(0);
Chris Lattner7f6b9d22007-02-10 20:31:59 +0000663 SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
664 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
665 idxVec.size())) {
Chris Lattner27e19212005-02-14 21:40:26 +0000666 if (Offset)
667 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000668 EmitConstantValueOnly(ptrVal);
Chris Lattner27e19212005-02-14 21:40:26 +0000669 if (Offset > 0)
670 O << ") + " << Offset;
671 else if (Offset < 0)
672 O << ") - " << -Offset;
Chris Lattnera80ba712004-08-16 23:15:22 +0000673 } else {
Chris Lattner25045bd2005-11-21 07:51:36 +0000674 EmitConstantValueOnly(ptrVal);
Chris Lattnera80ba712004-08-16 23:15:22 +0000675 }
676 break;
677 }
Reid Spencer3da59db2006-11-27 01:05:10 +0000678 case Instruction::Trunc:
679 case Instruction::ZExt:
680 case Instruction::SExt:
681 case Instruction::FPTrunc:
682 case Instruction::FPExt:
683 case Instruction::UIToFP:
684 case Instruction::SIToFP:
685 case Instruction::FPToUI:
686 case Instruction::FPToSI:
687 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
688 break;
Chris Lattnercb0a6812006-12-12 05:14:13 +0000689 case Instruction::BitCast:
690 return EmitConstantValueOnly(CE->getOperand(0));
691
Chris Lattnerddc94012006-12-12 05:18:19 +0000692 case Instruction::IntToPtr: {
693 // Handle casts to pointers by changing them into casts to the appropriate
694 // integer type. This promotes constant folding and simplifies this code.
695 Constant *Op = CE->getOperand(0);
696 Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
697 return EmitConstantValueOnly(Op);
698 }
699
700
701 case Instruction::PtrToInt: {
Chris Lattner4a6bd332006-07-29 01:57:19 +0000702 // Support only foldable casts to/from pointers that can be eliminated by
703 // changing the pointer to the appropriately sized integer type.
Chris Lattnera80ba712004-08-16 23:15:22 +0000704 Constant *Op = CE->getOperand(0);
Chris Lattnerddc94012006-12-12 05:18:19 +0000705 const Type *Ty = CE->getType();
Chris Lattnera80ba712004-08-16 23:15:22 +0000706
Chris Lattnerddc94012006-12-12 05:18:19 +0000707 // We can emit the pointer value into this slot if the slot is an
708 // integer slot greater or equal to the size of the pointer.
Chris Lattner42a75512007-01-15 02:27:26 +0000709 if (Ty->isInteger() &&
Reid Spencera54b7cb2007-01-12 07:05:14 +0000710 TD->getTypeSize(Ty) >= TD->getTypeSize(Op->getType()))
Chris Lattner4a6bd332006-07-29 01:57:19 +0000711 return EmitConstantValueOnly(Op);
Chris Lattner4a6bd332006-07-29 01:57:19 +0000712
713 assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattner25045bd2005-11-21 07:51:36 +0000714 EmitConstantValueOnly(Op);
Chris Lattnera80ba712004-08-16 23:15:22 +0000715 break;
716 }
717 case Instruction::Add:
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000718 case Instruction::Sub:
Chris Lattnera80ba712004-08-16 23:15:22 +0000719 O << "(";
Chris Lattner25045bd2005-11-21 07:51:36 +0000720 EmitConstantValueOnly(CE->getOperand(0));
Anton Korobeynikov13b7d3d2007-02-04 23:27:42 +0000721 O << (Opcode==Instruction::Add ? ") + (" : ") - (");
Chris Lattner25045bd2005-11-21 07:51:36 +0000722 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattnera80ba712004-08-16 23:15:22 +0000723 O << ")";
724 break;
725 default:
726 assert(0 && "Unsupported operator!");
727 }
728 } else {
729 assert(0 && "Unknown constant value!");
730 }
731}
Chris Lattner1b7e2352004-08-17 06:36:49 +0000732
Chris Lattner2980cef2005-11-10 18:06:33 +0000733/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner1b7e2352004-08-17 06:36:49 +0000734/// the predicate isString is true.
735///
Chris Lattner2980cef2005-11-10 18:06:33 +0000736static void printAsCString(std::ostream &O, const ConstantArray *CVA,
737 unsigned LastElt) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000738 assert(CVA->isString() && "Array is not string compatible!");
739
740 O << "\"";
Chris Lattner2980cef2005-11-10 18:06:33 +0000741 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukmanedf128a2005-04-21 22:36:52 +0000742 unsigned char C =
Reid Spencerb83eb642006-10-20 07:07:24 +0000743 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
Jim Laskeyf1cdea12007-01-25 15:12:02 +0000744 printStringChar(O, C);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000745 }
746 O << "\"";
747}
748
Jeff Cohenc884db42006-05-02 01:16:28 +0000749/// EmitString - Emit a zero-byte-terminated string constant.
750///
751void AsmPrinter::EmitString(const ConstantArray *CVA) const {
752 unsigned NumElts = CVA->getNumOperands();
Jim Laskey563321a2006-09-06 18:34:40 +0000753 if (TAI->getAscizDirective() && NumElts &&
Reid Spencerb83eb642006-10-20 07:07:24 +0000754 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
Jim Laskey563321a2006-09-06 18:34:40 +0000755 O << TAI->getAscizDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000756 printAsCString(O, CVA, NumElts-1);
757 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000758 O << TAI->getAsciiDirective();
Jeff Cohenc884db42006-05-02 01:16:28 +0000759 printAsCString(O, CVA, NumElts);
760 }
761 O << "\n";
762}
763
Chris Lattner25045bd2005-11-21 07:51:36 +0000764/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner1b7e2352004-08-17 06:36:49 +0000765///
Chris Lattner25045bd2005-11-21 07:51:36 +0000766void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Owen Andersona69571c2006-05-03 01:29:57 +0000767 const TargetData *TD = TM.getTargetData();
Chris Lattner1b7e2352004-08-17 06:36:49 +0000768
Chris Lattnerbd1d3822004-10-16 18:19:26 +0000769 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Owen Andersona69571c2006-05-03 01:29:57 +0000770 EmitZeros(TD->getTypeSize(CV->getType()));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000771 return;
772 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
773 if (CVA->isString()) {
Jeff Cohenc884db42006-05-02 01:16:28 +0000774 EmitString(CVA);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000775 } else { // Not a string. Print the values in successive locations
776 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattner25045bd2005-11-21 07:51:36 +0000777 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner1b7e2352004-08-17 06:36:49 +0000778 }
779 return;
780 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
781 // Print the fields in successive locations. Pad to align if needed!
Owen Andersona69571c2006-05-03 01:29:57 +0000782 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
Chris Lattnerdea18b62005-01-08 19:59:10 +0000783 uint64_t sizeSoFar = 0;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000784 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
785 const Constant* field = CVS->getOperand(i);
786
787 // Check if padding is needed and insert one or more 0s.
Owen Andersona69571c2006-05-03 01:29:57 +0000788 uint64_t fieldSize = TD->getTypeSize(field->getType());
Chris Lattnerb0c39a32007-02-10 19:59:22 +0000789 uint64_t padSize = ((i == e-1? cvsLayout->getSizeInBytes()
Chris Lattnerb1919e22007-02-10 19:55:17 +0000790 : cvsLayout->getElementOffset(i+1))
791 - cvsLayout->getElementOffset(i)) - fieldSize;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000792 sizeSoFar += fieldSize + padSize;
793
794 // Now print the actual field value
Chris Lattner25045bd2005-11-21 07:51:36 +0000795 EmitGlobalConstant(field);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000796
797 // Insert the field padding unless it's zero bytes...
Chris Lattner25045bd2005-11-21 07:51:36 +0000798 EmitZeros(padSize);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000799 }
Chris Lattnerb0c39a32007-02-10 19:59:22 +0000800 assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
Chris Lattner1b7e2352004-08-17 06:36:49 +0000801 "Layout of constant struct may be incorrect!");
802 return;
803 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
804 // FP Constants are printed as integer constants to avoid losing
805 // precision...
806 double Val = CFP->getValue();
807 if (CFP->getType() == Type::DoubleTy) {
Jim Laskey563321a2006-09-06 18:34:40 +0000808 if (TAI->getData64bitsDirective())
809 O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
810 << TAI->getCommentString() << " double value: " << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000811 else if (TD->isBigEndian()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000812 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
813 << "\t" << TAI->getCommentString()
814 << " double most significant word " << Val << "\n";
815 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
816 << "\t" << TAI->getCommentString()
817 << " double least significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000818 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000819 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
820 << "\t" << TAI->getCommentString()
821 << " double least significant word " << Val << "\n";
822 O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
823 << "\t" << TAI->getCommentString()
824 << " double most significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000825 }
826 return;
827 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000828 O << TAI->getData32bitsDirective() << FloatToBits(Val)
829 << "\t" << TAI->getCommentString() << " float " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000830 return;
831 }
Reid Spencer47857812006-12-31 05:55:36 +0000832 } else if (CV->getType() == Type::Int64Ty) {
Chris Lattner1b7e2352004-08-17 06:36:49 +0000833 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
Reid Spencerb83eb642006-10-20 07:07:24 +0000834 uint64_t Val = CI->getZExtValue();
Misha Brukmanedf128a2005-04-21 22:36:52 +0000835
Jim Laskey563321a2006-09-06 18:34:40 +0000836 if (TAI->getData64bitsDirective())
837 O << TAI->getData64bitsDirective() << Val << "\n";
Owen Andersona69571c2006-05-03 01:29:57 +0000838 else if (TD->isBigEndian()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000839 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
840 << "\t" << TAI->getCommentString()
841 << " Double-word most significant word " << Val << "\n";
842 O << TAI->getData32bitsDirective() << unsigned(Val)
843 << "\t" << TAI->getCommentString()
844 << " Double-word least significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000845 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000846 O << TAI->getData32bitsDirective() << unsigned(Val)
847 << "\t" << TAI->getCommentString()
848 << " Double-word least significant word " << Val << "\n";
849 O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
850 << "\t" << TAI->getCommentString()
851 << " Double-word most significant word " << Val << "\n";
Chris Lattner1b7e2352004-08-17 06:36:49 +0000852 }
853 return;
854 }
Reid Spencer9d6565a2007-02-15 02:26:10 +0000855 } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
856 const VectorType *PTy = CP->getType();
Nate Begeman8cfa57b2005-12-06 06:18:55 +0000857
858 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
859 EmitGlobalConstant(CP->getOperand(I));
860
861 return;
Chris Lattner1b7e2352004-08-17 06:36:49 +0000862 }
863
864 const Type *type = CV->getType();
Evan Chengd6594ae2006-09-12 21:00:35 +0000865 printDataDirective(type);
Chris Lattner25045bd2005-11-21 07:51:36 +0000866 EmitConstantValueOnly(CV);
Chris Lattner1b7e2352004-08-17 06:36:49 +0000867 O << "\n";
868}
Chris Lattner0264d1a2006-01-27 02:10:10 +0000869
Evan Chengd6594ae2006-09-12 21:00:35 +0000870void
871AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
872 // Target doesn't support this yet!
873 abort();
874}
875
Chris Lattner3ce9b672006-09-26 23:59:50 +0000876/// PrintSpecial - Print information related to the specified machine instr
877/// that is independent of the operand, and may be independent of the instr
878/// itself. This can be useful for portably encoding the comment character
879/// or other bits of target-specific knowledge into the asmstrings. The
880/// syntax used is ${:comment}. Targets can override this to add support
881/// for their own strange codes.
882void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
Chris Lattnerbae02cf2006-09-27 00:06:07 +0000883 if (!strcmp(Code, "private")) {
884 O << TAI->getPrivateGlobalPrefix();
885 } else if (!strcmp(Code, "comment")) {
Chris Lattner3ce9b672006-09-26 23:59:50 +0000886 O << TAI->getCommentString();
887 } else if (!strcmp(Code, "uid")) {
888 // Assign a unique ID to this machine instruction.
889 static const MachineInstr *LastMI = 0;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000890 static const Function *F = 0;
Chris Lattner3ce9b672006-09-26 23:59:50 +0000891 static unsigned Counter = 0U-1;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000892
893 // Comparing the address of MI isn't sufficient, because machineinstrs may
894 // be allocated to the same address across functions.
895 const Function *ThisF = MI->getParent()->getParent()->getFunction();
896
Chris Lattner3ce9b672006-09-26 23:59:50 +0000897 // If this is a new machine instruction, bump the counter.
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000898 if (LastMI != MI || F != ThisF) {
899 ++Counter;
900 LastMI = MI;
Chris Lattner4b092522007-02-06 01:56:31 +0000901 F = ThisF;
Chris Lattnerb6a24bf2007-02-05 21:23:52 +0000902 }
Chris Lattner3ce9b672006-09-26 23:59:50 +0000903 O << Counter;
904 } else {
Bill Wendlinge8156192006-12-07 01:30:32 +0000905 cerr << "Unknown special formatter '" << Code
906 << "' for machine instr: " << *MI;
Chris Lattner3ce9b672006-09-26 23:59:50 +0000907 exit(1);
908 }
909}
910
911
Chris Lattner0264d1a2006-01-27 02:10:10 +0000912/// printInlineAsm - This method formats and prints the specified machine
913/// instruction that is an inline asm.
914void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000915 unsigned NumOperands = MI->getNumOperands();
916
917 // Count the number of register definitions.
918 unsigned NumDefs = 0;
Chris Lattner67942f52006-09-05 20:02:51 +0000919 for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
920 ++NumDefs)
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000921 assert(NumDefs != NumOperands-1 && "No asm string?");
922
923 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
Chris Lattner66099132006-02-01 22:41:11 +0000924
925 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattnerf2b67cf2006-01-30 23:00:08 +0000926 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattner66099132006-02-01 22:41:11 +0000927
Chris Lattnerf26f5dd2006-07-28 00:17:20 +0000928 // If this asmstr is empty, don't bother printing the #APP/#NOAPP markers.
929 if (AsmStr[0] == 0) {
930 O << "\n"; // Tab already printed, avoid double indenting next instr.
931 return;
932 }
933
Jim Laskey563321a2006-09-06 18:34:40 +0000934 O << TAI->getInlineAsmStart() << "\n\t";
Chris Lattnerf26f5dd2006-07-28 00:17:20 +0000935
Bill Wendlingeb9a42c2007-01-16 03:42:04 +0000936 // The variant of the current asmprinter.
937 int AsmPrinterVariant = TAI->getAssemblerDialect();
938
Chris Lattner66099132006-02-01 22:41:11 +0000939 int CurVariant = -1; // The number of the {.|.|.} region we are in.
940 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner2cc2f662006-02-01 01:28:23 +0000941
Chris Lattner66099132006-02-01 22:41:11 +0000942 while (*LastEmitted) {
943 switch (*LastEmitted) {
944 default: {
945 // Not a special case, emit the string section literally.
946 const char *LiteralEnd = LastEmitted+1;
947 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattner1c059972006-05-05 21:47:05 +0000948 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattner66099132006-02-01 22:41:11 +0000949 ++LiteralEnd;
950 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
951 O.write(LastEmitted, LiteralEnd-LastEmitted);
952 LastEmitted = LiteralEnd;
953 break;
954 }
Chris Lattner1c059972006-05-05 21:47:05 +0000955 case '\n':
956 ++LastEmitted; // Consume newline character.
957 O << "\n\t"; // Indent code with newline.
958 break;
Chris Lattner66099132006-02-01 22:41:11 +0000959 case '$': {
960 ++LastEmitted; // Consume '$' character.
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000961 bool Done = true;
962
963 // Handle escapes.
964 switch (*LastEmitted) {
965 default: Done = false; break;
966 case '$': // $$ -> $
Chris Lattner66099132006-02-01 22:41:11 +0000967 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
968 O << '$';
969 ++LastEmitted; // Consume second '$' character.
970 break;
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000971 case '(': // $( -> same as GCC's { character.
972 ++LastEmitted; // Consume '(' character.
973 if (CurVariant != -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000974 cerr << "Nested variants found in inline asm string: '"
975 << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000976 exit(1);
977 }
978 CurVariant = 0; // We're in the first variant now.
979 break;
980 case '|':
981 ++LastEmitted; // consume '|' character.
982 if (CurVariant == -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000983 cerr << "Found '|' character outside of variant in inline asm "
984 << "string: '" << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000985 exit(1);
986 }
987 ++CurVariant; // We're in the next variant.
988 break;
989 case ')': // $) -> same as GCC's } char.
990 ++LastEmitted; // consume ')' character.
991 if (CurVariant == -1) {
Bill Wendlinge8156192006-12-07 01:30:32 +0000992 cerr << "Found '}' character outside of variant in inline asm "
993 << "string: '" << AsmStr << "'\n";
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000994 exit(1);
995 }
996 CurVariant = -1;
997 break;
Chris Lattner66099132006-02-01 22:41:11 +0000998 }
Chris Lattnerfaf1dae2006-10-03 23:27:09 +0000999 if (Done) break;
Chris Lattner66099132006-02-01 22:41:11 +00001000
1001 bool HasCurlyBraces = false;
1002 if (*LastEmitted == '{') { // ${variable}
1003 ++LastEmitted; // Consume '{' character.
1004 HasCurlyBraces = true;
1005 }
1006
1007 const char *IDStart = LastEmitted;
1008 char *IDEnd;
Chris Lattnerfad29122007-01-23 00:36:17 +00001009 errno = 0;
Chris Lattner66099132006-02-01 22:41:11 +00001010 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1011 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001012 cerr << "Bad $ operand number in inline asm string: '"
1013 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001014 exit(1);
1015 }
1016 LastEmitted = IDEnd;
1017
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001018 char Modifier[2] = { 0, 0 };
1019
Chris Lattner66099132006-02-01 22:41:11 +00001020 if (HasCurlyBraces) {
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001021 // If we have curly braces, check for a modifier character. This
1022 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1023 if (*LastEmitted == ':') {
1024 ++LastEmitted; // Consume ':' character.
1025 if (*LastEmitted == 0) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001026 cerr << "Bad ${:} expression in inline asm string: '"
1027 << AsmStr << "'\n";
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001028 exit(1);
1029 }
1030
1031 Modifier[0] = *LastEmitted;
1032 ++LastEmitted; // Consume modifier character.
1033 }
1034
Chris Lattner66099132006-02-01 22:41:11 +00001035 if (*LastEmitted != '}') {
Bill Wendlinge8156192006-12-07 01:30:32 +00001036 cerr << "Bad ${} expression in inline asm string: '"
1037 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001038 exit(1);
1039 }
1040 ++LastEmitted; // Consume '}' character.
1041 }
1042
1043 if ((unsigned)Val >= NumOperands-1) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001044 cerr << "Invalid $ operand number in inline asm string: '"
1045 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001046 exit(1);
1047 }
1048
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001049 // Okay, we finally have a value number. Ask the target to print this
Chris Lattner66099132006-02-01 22:41:11 +00001050 // operand!
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001051 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1052 unsigned OpNo = 1;
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001053
1054 bool Error = false;
1055
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001056 // Scan to find the machine operand number for the operand.
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001057 for (; Val; --Val) {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001058 if (OpNo >= MI->getNumOperands()) break;
Chris Lattnerdaf6bc62006-02-24 19:50:58 +00001059 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1060 OpNo += (OpFlags >> 3) + 1;
1061 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001062
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001063 if (OpNo >= MI->getNumOperands()) {
1064 Error = true;
Chris Lattnerdd260332006-02-24 20:21:58 +00001065 } else {
Chris Lattnerfd561cd2006-06-08 18:00:47 +00001066 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1067 ++OpNo; // Skip over the ID number.
1068
1069 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1070 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
1071 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1072 Modifier[0] ? Modifier : 0);
1073 } else {
1074 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1075 Modifier[0] ? Modifier : 0);
1076 }
Chris Lattnerdd260332006-02-24 20:21:58 +00001077 }
1078 if (Error) {
Bill Wendlinge8156192006-12-07 01:30:32 +00001079 cerr << "Invalid operand found in inline asm: '"
1080 << AsmStr << "'\n";
Chris Lattner66099132006-02-01 22:41:11 +00001081 MI->dump();
1082 exit(1);
1083 }
Chris Lattnerc3a9f8d2006-02-23 19:21:04 +00001084 }
Chris Lattner66099132006-02-01 22:41:11 +00001085 break;
1086 }
Chris Lattner66099132006-02-01 22:41:11 +00001087 }
1088 }
Jim Laskey563321a2006-09-06 18:34:40 +00001089 O << "\n\t" << TAI->getInlineAsmEnd() << "\n";
Chris Lattner66099132006-02-01 22:41:11 +00001090}
1091
Jim Laskey1ee29252007-01-26 14:34:52 +00001092/// printLabel - This method prints a local label used by debug and
1093/// exception handling tables.
1094void AsmPrinter::printLabel(const MachineInstr *MI) const {
Jim Laskeyb82313f2007-02-01 16:31:34 +00001095 O << "\n"
1096 << TAI->getPrivateGlobalPrefix()
Jim Laskeybacd3042007-02-21 22:48:45 +00001097 << "label"
Jim Laskey1ee29252007-01-26 14:34:52 +00001098 << MI->getOperand(0).getImmedValue()
1099 << ":\n";
1100}
1101
Chris Lattner66099132006-02-01 22:41:11 +00001102/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1103/// instruction, using the specified assembler variant. Targets should
1104/// overried this to format as appropriate.
1105bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnera36cb0a2006-02-06 22:17:23 +00001106 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattner66099132006-02-01 22:41:11 +00001107 // Target doesn't support this yet!
1108 return true;
Chris Lattner0264d1a2006-01-27 02:10:10 +00001109}
Chris Lattnerdd260332006-02-24 20:21:58 +00001110
1111bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1112 unsigned AsmVariant,
1113 const char *ExtraCode) {
1114 // Target doesn't support this yet!
1115 return true;
1116}
Nate Begeman37efe672006-04-22 18:53:45 +00001117
1118/// printBasicBlockLabel - This method prints the label for the specified
1119/// MachineBasicBlock
Nate Begemancdf38c42006-05-02 05:37:32 +00001120void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1121 bool printColon,
1122 bool printComment) const {
Jim Laskey563321a2006-09-06 18:34:40 +00001123 O << TAI->getPrivateGlobalPrefix() << "BB" << FunctionNumber << "_"
Nate Begeman9d51eeb2006-05-02 17:36:46 +00001124 << MBB->getNumber();
Nate Begemancdf38c42006-05-02 05:37:32 +00001125 if (printColon)
1126 O << ':';
Chris Lattner9c78ecb2006-10-05 21:40:14 +00001127 if (printComment && MBB->getBasicBlock())
Jim Laskey563321a2006-09-06 18:34:40 +00001128 O << '\t' << TAI->getCommentString() << MBB->getBasicBlock()->getName();
Nate Begeman37efe672006-04-22 18:53:45 +00001129}
Nate Begeman52a51e382006-08-12 21:29:52 +00001130
1131/// printSetLabel - This method prints a set label for the specified
1132/// MachineBasicBlock
1133void AsmPrinter::printSetLabel(unsigned uid,
1134 const MachineBasicBlock *MBB) const {
Jim Laskey563321a2006-09-06 18:34:40 +00001135 if (!TAI->getSetDirective())
Nate Begeman52a51e382006-08-12 21:29:52 +00001136 return;
1137
Jim Laskey563321a2006-09-06 18:34:40 +00001138 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1139 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Nate Begeman52a51e382006-08-12 21:29:52 +00001140 printBasicBlockLabel(MBB, false, false);
Jim Laskey563321a2006-09-06 18:34:40 +00001141 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Nate Begeman52a51e382006-08-12 21:29:52 +00001142 << '_' << uid << '\n';
1143}
Evan Chengd6594ae2006-09-12 21:00:35 +00001144
Evan Cheng41349c12006-11-01 09:23:08 +00001145void AsmPrinter::printSetLabel(unsigned uid, unsigned uid2,
1146 const MachineBasicBlock *MBB) const {
1147 if (!TAI->getSetDirective())
1148 return;
1149
1150 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1151 << getFunctionNumber() << '_' << uid << '_' << uid2
1152 << "_set_" << MBB->getNumber() << ',';
1153 printBasicBlockLabel(MBB, false, false);
1154 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1155 << '_' << uid << '_' << uid2 << '\n';
1156}
1157
Evan Chengd6594ae2006-09-12 21:00:35 +00001158/// printDataDirective - This method prints the asm directive for the
1159/// specified type.
1160void AsmPrinter::printDataDirective(const Type *type) {
1161 const TargetData *TD = TM.getTargetData();
1162 switch (type->getTypeID()) {
Reid Spencera54b7cb2007-01-12 07:05:14 +00001163 case Type::IntegerTyID: {
1164 unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1165 if (BitWidth <= 8)
1166 O << TAI->getData8bitsDirective();
1167 else if (BitWidth <= 16)
1168 O << TAI->getData16bitsDirective();
1169 else if (BitWidth <= 32)
1170 O << TAI->getData32bitsDirective();
1171 else if (BitWidth <= 64) {
1172 assert(TAI->getData64bitsDirective() &&
1173 "Target cannot handle 64-bit constant exprs!");
1174 O << TAI->getData64bitsDirective();
1175 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001176 break;
Reid Spencera54b7cb2007-01-12 07:05:14 +00001177 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001178 case Type::PointerTyID:
1179 if (TD->getPointerSize() == 8) {
1180 assert(TAI->getData64bitsDirective() &&
1181 "Target cannot handle 64-bit pointer exprs!");
1182 O << TAI->getData64bitsDirective();
Reid Spencera54b7cb2007-01-12 07:05:14 +00001183 } else {
1184 O << TAI->getData32bitsDirective();
Evan Chengd6594ae2006-09-12 21:00:35 +00001185 }
Evan Chengd6594ae2006-09-12 21:00:35 +00001186 break;
1187 case Type::FloatTyID: case Type::DoubleTyID:
1188 assert (0 && "Should have already output floating point constant.");
1189 default:
1190 assert (0 && "Can't handle printing this type of thing");
1191 break;
1192 }
1193}
Dale Johannesen4c3a5f82007-02-16 01:54:53 +00001194