blob: a28a1dcecbc878a81908a2503748a344c5966519 [file] [log] [blame]
Bill Wendlingbbee8c92009-05-15 00:11:17 +00001//===--- lib/CodeGen/DwarfPrinter.cpp - Dwarf Printer ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Emit general DWARF directives.
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000011//
Bill Wendlingbbee8c92009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
14#include "DwarfPrinter.h"
15#include "llvm/Module.h"
16#include "llvm/CodeGen/AsmPrinter.h"
17#include "llvm/CodeGen/MachineFrameInfo.h"
David Greene18938f92009-08-19 21:59:18 +000018#include "llvm/CodeGen/MachineFunction.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000019#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattner621c44d2009-08-22 20:48:53 +000020#include "llvm/MC/MCAsmInfo.h"
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000021#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
Chris Lattnerd705acf2010-01-22 22:38:16 +000023#include "llvm/MC/MCStreamer.h"
Chris Lattner41e330f2010-01-16 18:50:28 +000024#include "llvm/MC/MCSymbol.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000025#include "llvm/Target/TargetData.h"
26#include "llvm/Target/TargetFrameInfo.h"
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000027#include "llvm/Target/TargetLoweringObjectFile.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000028#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattnerf5377682009-08-24 03:52:50 +000029#include "llvm/Support/Dwarf.h"
30#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000031#include "llvm/ADT/SmallString.h"
Bill Wendlingbbee8c92009-05-15 00:11:17 +000032using namespace llvm;
33
Chris Lattnerb21f1042010-01-22 22:23:57 +000034DwarfPrinter::DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
35 const char *flavor)
Chris Lattnera5ef4d32009-08-22 21:43:10 +000036: O(OS), Asm(A), MAI(T), TD(Asm->TM.getTargetData()),
Bill Wendlingbbee8c92009-05-15 00:11:17 +000037 RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL),
38 SubprogramCount(0), Flavor(flavor), SetCounter(1) {}
39
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +000040
41/// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
42/// label with the specified stem and unique ID.
43MCSymbol *DwarfPrinter::getDWLabel(const char *Name, unsigned ID) const {
44 // FIXME: REMOVE this. However, there is stuff in EH that passes counters in
45 // here that can be zero.
46
47 //assert(ID && "Should use getTempLabel if no ID");
48 if (ID == 0) return getTempLabel(Name);
49 return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
50 + Twine(Name) + Twine(ID));
51}
52
53/// getTempLabel - Return the MCSymbol corresponding to the assembler temporary
54/// label with the specified name.
55MCSymbol *DwarfPrinter::getTempLabel(const char *Name) const {
56 return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
57 + Name);
58}
59
60
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000061/// SizeOfEncodedValue - Return the size of the encoding in bytes.
62unsigned DwarfPrinter::SizeOfEncodedValue(unsigned Encoding) const {
63 if (Encoding == dwarf::DW_EH_PE_omit)
64 return 0;
65
66 switch (Encoding & 0x07) {
67 case dwarf::DW_EH_PE_absptr:
68 return TD->getPointerSize();
69 case dwarf::DW_EH_PE_udata2:
70 return 2;
71 case dwarf::DW_EH_PE_udata4:
72 return 4;
73 case dwarf::DW_EH_PE_udata8:
74 return 8;
75 }
76
77 assert(0 && "Invalid encoded value.");
78 return 0;
79}
80
Chris Lattnerb21f1042010-01-22 22:23:57 +000081void DwarfPrinter::PrintRelDirective(bool Force32Bit, bool isInSection) const {
Chris Lattnera5ef4d32009-08-22 21:43:10 +000082 if (isInSection && MAI->getDwarfSectionOffsetDirective())
83 O << MAI->getDwarfSectionOffsetDirective();
Bill Wendlingbbee8c92009-05-15 00:11:17 +000084 else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t))
Chris Lattnera5ef4d32009-08-22 21:43:10 +000085 O << MAI->getData32bitsDirective();
Bill Wendlingbbee8c92009-05-15 00:11:17 +000086 else
Chris Lattnera5ef4d32009-08-22 21:43:10 +000087 O << MAI->getData64bitsDirective();
Bill Wendlingbbee8c92009-05-15 00:11:17 +000088}
89
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +000090void DwarfPrinter::PrintRelDirective(unsigned Encoding) const {
91 unsigned Size = SizeOfEncodedValue(Encoding);
92 assert((Size == 4 || Size == 8) && "Do not support other types or rels!");
93
94 O << (Size == 4 ?
95 MAI->getData32bitsDirective() : MAI->getData64bitsDirective());
96}
97
Chris Lattner05ae1d22010-01-22 23:47:11 +000098/// EOL - Print a newline character to asm stream. If a comment is present
99/// then it will be printed first. Comments should not contain '\n'.
100void DwarfPrinter::EOL(const Twine &Comment) const {
101 if (Asm->VerboseAsm && !Comment.isTriviallyEmpty()) {
102 Asm->O.PadToColumn(MAI->getCommentColumn());
103 Asm->O << Asm->MAI->getCommentString() << ' ' << Comment;
104 }
105 Asm->O << '\n';
106}
107
Chris Lattnerd705acf2010-01-22 22:38:16 +0000108static const char *DecodeDWARFEncoding(unsigned Encoding) {
109 switch (Encoding) {
110 case dwarf::DW_EH_PE_absptr: return "absptr";
111 case dwarf::DW_EH_PE_omit: return "omit";
112 case dwarf::DW_EH_PE_pcrel: return "pcrel";
113 case dwarf::DW_EH_PE_udata4: return "udata4";
114 case dwarf::DW_EH_PE_udata8: return "udata8";
115 case dwarf::DW_EH_PE_sdata4: return "sdata4";
116 case dwarf::DW_EH_PE_sdata8: return "sdata8";
117 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: return "pcrel udata4";
118 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: return "pcrel sdata4";
119 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: return "pcrel udata8";
120 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: return "pcrel sdata8";
121 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4:
122 return "indirect pcrel udata4";
123 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4:
124 return "indirect pcrel sdata4";
125 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8:
126 return "indirect pcrel udata8";
127 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8:
128 return "indirect pcrel sdata8";
129 }
130
131 return "<unknown encoding>";
132}
133
134/// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
135/// encoding. If verbose assembly output is enabled, we output comments
136/// describing the encoding. Desc is an optional string saying what the
137/// encoding is specifying (e.g. "LSDA").
138void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) {
139 if (Asm->VerboseAsm) {
140 if (Desc != 0)
141 Asm->OutStreamer.AddComment(Twine(Desc)+" Encoding = " +
142 Twine(DecodeDWARFEncoding(Val)));
143 else
144 Asm->OutStreamer.AddComment(Twine("Encoding = ") +
145 DecodeDWARFEncoding(Val));
146 }
147
148 Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/);
149}
150
Chris Lattnerab4cf952010-01-22 23:40:08 +0000151/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
152void DwarfPrinter::EmitCFAByte(unsigned Val) {
153 if (Asm->VerboseAsm) {
154 if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset+64)
155 Asm->OutStreamer.AddComment("DW_CFA_offset + Reg (" +
156 Twine(Val-dwarf::DW_CFA_offset) + ")");
157 else
158 Asm->OutStreamer.AddComment(dwarf::CallFrameString(Val));
159 }
160 Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/);
161}
162
Chris Lattnerbcc79432010-01-22 23:18:42 +0000163/// EmitSLEB128 - emit the specified signed leb128 value.
164void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const {
165 if (Asm->VerboseAsm && Desc)
166 Asm->OutStreamer.AddComment(Desc);
167
168 if (MAI->hasLEB128()) {
169 O << "\t.sleb128\t" << Value;
170 Asm->OutStreamer.AddBlankLine();
171 return;
172 }
173
174 // If we don't have .sleb128, emit as .bytes.
Chris Lattner20f334f2010-01-22 22:56:55 +0000175 int Sign = Value >> (8 * sizeof(Value) - 1);
176 bool IsMore;
177
178 do {
179 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
180 Value >>= 7;
181 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
182 if (IsMore) Byte |= 0x80;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000183 Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
Chris Lattner20f334f2010-01-22 22:56:55 +0000184 } while (IsMore);
185}
186
Chris Lattnerbcc79432010-01-22 23:18:42 +0000187/// EmitULEB128 - emit the specified signed leb128 value.
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000188void DwarfPrinter::EmitULEB128(unsigned Value, const char *Desc,
189 unsigned PadTo) const {
Chris Lattner20f334f2010-01-22 22:56:55 +0000190 if (Asm->VerboseAsm && Desc)
191 Asm->OutStreamer.AddComment(Desc);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000192
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000193 if (MAI->hasLEB128() && PadTo == 0) {
Chris Lattnerbcc79432010-01-22 23:18:42 +0000194 O << "\t.uleb128\t" << Value;
Chris Lattner20f334f2010-01-22 22:56:55 +0000195 Asm->OutStreamer.AddBlankLine();
Chris Lattnerbcc79432010-01-22 23:18:42 +0000196 return;
Chris Lattner20f334f2010-01-22 22:56:55 +0000197 }
Chris Lattnerbcc79432010-01-22 23:18:42 +0000198
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000199 // If we don't have .uleb128 or we want to emit padding, emit as .bytes.
Chris Lattnerbcc79432010-01-22 23:18:42 +0000200 do {
201 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
202 Value >>= 7;
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000203 if (Value || PadTo != 0) Byte |= 0x80;
Chris Lattnerbcc79432010-01-22 23:18:42 +0000204 Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
205 } while (Value);
Bill Wendlinga7888ea2010-02-24 23:34:35 +0000206
Bill Wendlinge1973f22010-02-25 00:24:52 +0000207 if (PadTo) {
208 if (PadTo > 1)
209 Asm->OutStreamer.EmitFill(PadTo - 1, 0x80/*fillval*/, 0/*addrspace*/);
210 Asm->OutStreamer.EmitFill(1, 0/*fillval*/, 0/*addrspace*/);
211 }
Chris Lattner20f334f2010-01-22 22:56:55 +0000212}
213
214
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000215/// PrintLabelName - Print label name in form used by Dwarf writer.
216///
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000217void DwarfPrinter::PrintLabelName(const MCSymbol *Label) const {
218 // FIXME: REMOVE.
219 O << Label->getName();
220}
221
Chris Lattnerb21f1042010-01-22 22:23:57 +0000222void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number) const {
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000223 // FIXME: REMOVE.
Jim Grosbach90cc01b2009-09-01 16:43:35 +0000224 O << MAI->getPrivateGlobalPrefix() << Tag;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000225 if (Number) O << Number;
226}
Chris Lattnerb21f1042010-01-22 22:23:57 +0000227void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number,
228 const char *Suffix) const {
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000229 // FIXME: REMOVE.
Jim Grosbach90cc01b2009-09-01 16:43:35 +0000230 O << MAI->getPrivateGlobalPrefix() << Tag;
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000231 if (Number) O << Number;
232 O << Suffix;
233}
234
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000235/// EmitReference - Emit a reference to a label.
236///
Chris Lattnerb21f1042010-01-22 22:23:57 +0000237void DwarfPrinter::EmitReference(const char *Tag, unsigned Number,
238 bool IsPCRelative, bool Force32Bit) const {
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000239 PrintRelDirective(Force32Bit);
240 PrintLabelName(Tag, Number);
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000241 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000242}
Chris Lattnerb21f1042010-01-22 22:23:57 +0000243void DwarfPrinter::EmitReference(const std::string &Name, bool IsPCRelative,
244 bool Force32Bit) const {
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000245 PrintRelDirective(Force32Bit);
246 O << Name;
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000247 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000248}
249
Chris Lattnerb21f1042010-01-22 22:23:57 +0000250void DwarfPrinter::EmitReference(const MCSymbol *Sym, bool IsPCRelative,
251 bool Force32Bit) const {
Chris Lattner41e330f2010-01-16 18:50:28 +0000252 PrintRelDirective(Force32Bit);
Chris Lattnerce409842010-01-17 21:43:43 +0000253 O << *Sym;
Chris Lattner41e330f2010-01-16 18:50:28 +0000254 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
255}
256
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +0000257void DwarfPrinter::EmitReference(const char *Tag, unsigned Number,
258 unsigned Encoding) const {
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000259 // FIXME: REMOVE.
260 EmitReference(getDWLabel(Tag, Number), Encoding);
Anton Korobeynikovd779bcb2010-02-15 22:35:59 +0000261}
262
263void DwarfPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const {
264 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
265
266 PrintRelDirective(Encoding);
267 O << *TLOF.getSymbolForDwarfReference(Sym, Asm->MMI, Encoding);;
268}
269
270void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const {
271 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
272
273 PrintRelDirective(Encoding);
274 O << *TLOF.getSymbolForDwarfGlobalReference(GV, Asm->Mang,
275 Asm->MMI, Encoding);;
276}
277
Chris Lattner1fd01822010-01-26 20:20:43 +0000278/// EmitDifference - Emit the difference between two labels. If this assembler
279/// supports .set, we emit a .set of a temporary and then use it in the .word.
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000280void DwarfPrinter::EmitDifference(const MCSymbol *TagHi, const MCSymbol *TagLo,
281 bool IsSmall) {
282 if (MAI->hasSetDirective()) {
283 // FIXME: switch to OutStreamer.EmitAssignment.
284 O << "\t.set\t";
285 PrintLabelName("set", SetCounter, Flavor);
286 O << ",";
287 PrintLabelName(TagHi);
288 O << "-";
289 PrintLabelName(TagLo);
290 O << "\n";
291
292 PrintRelDirective(IsSmall);
293 PrintLabelName("set", SetCounter, Flavor);
294 ++SetCounter;
295 } else {
296 PrintRelDirective(IsSmall);
297 PrintLabelName(TagHi);
298 O << "-";
299 PrintLabelName(TagLo);
300 }
301}
302
303/// EmitDifference - Emit the difference between two labels. If this assembler
304/// supports .set, we emit a .set of a temporary and then use it in the .word.
Chris Lattnerb21f1042010-01-22 22:23:57 +0000305void DwarfPrinter::EmitDifference(const char *TagHi, unsigned NumberHi,
306 const char *TagLo, unsigned NumberLo,
307 bool IsSmall) {
Chris Lattner5e969572010-01-26 20:40:54 +0000308 if (MAI->hasSetDirective()) {
Chris Lattnerca419032010-01-26 21:53:08 +0000309 // FIXME: switch to OutStreamer.EmitAssignment.
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000310 O << "\t.set\t";
311 PrintLabelName("set", SetCounter, Flavor);
312 O << ",";
313 PrintLabelName(TagHi, NumberHi);
314 O << "-";
315 PrintLabelName(TagLo, NumberLo);
316 O << "\n";
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000317
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000318 PrintRelDirective(IsSmall);
319 PrintLabelName("set", SetCounter, Flavor);
320 ++SetCounter;
321 } else {
322 PrintRelDirective(IsSmall);
323 PrintLabelName(TagHi, NumberHi);
324 O << "-";
325 PrintLabelName(TagLo, NumberLo);
326 }
327}
328
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000329void DwarfPrinter::EmitSectionOffset(const MCSymbol *Label,
330 const MCSymbol *Section,
Chris Lattnerb21f1042010-01-22 22:23:57 +0000331 bool IsSmall, bool isEH,
332 bool useSet) {
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000333 bool printAbsolute = false;
334 if (isEH)
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000335 printAbsolute = MAI->isAbsoluteEHSectionOffsets();
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000336 else
Chris Lattnera5ef4d32009-08-22 21:43:10 +0000337 printAbsolute = MAI->isAbsoluteDebugSectionOffsets();
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000338
Chris Lattner5e969572010-01-26 20:40:54 +0000339 if (MAI->hasSetDirective() && useSet) {
Chris Lattnerca419032010-01-26 21:53:08 +0000340 // FIXME: switch to OutStreamer.EmitAssignment.
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000341 O << "\t.set\t";
342 PrintLabelName("set", SetCounter, Flavor);
343 O << ",";
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000344 PrintLabelName(Label);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000345
346 if (!printAbsolute) {
347 O << "-";
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000348 PrintLabelName(Section);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000349 }
350
351 O << "\n";
352 PrintRelDirective(IsSmall);
353 PrintLabelName("set", SetCounter, Flavor);
354 ++SetCounter;
355 } else {
356 PrintRelDirective(IsSmall, true);
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000357 PrintLabelName(Label);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000358
359 if (!printAbsolute) {
360 O << "-";
Chris Lattnerbe4c2fc2010-03-08 22:23:36 +0000361 PrintLabelName(Section);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000362 }
363 }
364}
365
366/// EmitFrameMoves - Emit frame instructions to describe the layout of the
367/// frame.
Chris Lattnerb21f1042010-01-22 22:23:57 +0000368void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
369 const std::vector<MachineMove> &Moves,
370 bool isEH) {
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000371 int stackGrowth =
372 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
373 TargetFrameInfo::StackGrowsUp ?
374 TD->getPointerSize() : -TD->getPointerSize();
375 bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
376
377 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
378 const MachineMove &Move = Moves[i];
379 unsigned LabelID = Move.getLabelID();
380
381 if (LabelID) {
382 LabelID = MMI->MappedLabel(LabelID);
383
384 // Throw out move if the label is invalid.
385 if (!LabelID) continue;
386 }
387
388 const MachineLocation &Dst = Move.getDestination();
389 const MachineLocation &Src = Move.getSource();
390
391 // Advance row if new location.
392 if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000393 EmitCFAByte(dwarf::DW_CFA_advance_loc4);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000394 EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
Chris Lattnerad653482010-01-22 22:09:00 +0000395 Asm->O << '\n';
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000396
397 BaseLabelID = LabelID;
398 BaseLabel = "label";
399 IsLocal = true;
400 }
401
402 // If advancing cfa.
403 if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
404 if (!Src.isReg()) {
405 if (Src.getReg() == MachineLocation::VirtualFP) {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000406 EmitCFAByte(dwarf::DW_CFA_def_cfa_offset);
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000407 } else {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000408 EmitCFAByte(dwarf::DW_CFA_def_cfa);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000409 EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000410 }
411
412 int Offset = -Src.getOffset();
Chris Lattnerbcc79432010-01-22 23:18:42 +0000413 EmitULEB128(Offset, "Offset");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000414 } else {
Edwin Törökbd448e32009-07-14 16:55:14 +0000415 llvm_unreachable("Machine move not supported yet.");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000416 }
417 } else if (Src.isReg() &&
418 Src.getReg() == MachineLocation::VirtualFP) {
419 if (Dst.isReg()) {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000420 EmitCFAByte(dwarf::DW_CFA_def_cfa_register);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000421 EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000422 } else {
Edwin Törökbd448e32009-07-14 16:55:14 +0000423 llvm_unreachable("Machine move not supported yet.");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000424 }
425 } else {
426 unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH);
427 int Offset = Dst.getOffset() / stackGrowth;
428
429 if (Offset < 0) {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000430 EmitCFAByte(dwarf::DW_CFA_offset_extended_sf);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000431 EmitULEB128(Reg, "Reg");
Chris Lattner20f334f2010-01-22 22:56:55 +0000432 EmitSLEB128(Offset, "Offset");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000433 } else if (Reg < 64) {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000434 EmitCFAByte(dwarf::DW_CFA_offset + Reg);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000435 EmitULEB128(Offset, "Offset");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000436 } else {
Chris Lattnerab4cf952010-01-22 23:40:08 +0000437 EmitCFAByte(dwarf::DW_CFA_offset_extended);
Chris Lattnerbcc79432010-01-22 23:18:42 +0000438 EmitULEB128(Reg, "Reg");
439 EmitULEB128(Offset, "Offset");
Bill Wendlingbbee8c92009-05-15 00:11:17 +0000440 }
441 }
442 }
443}