AsmPrinterDwarf.cpp revision 26be1c167a76e02cc0f37a9a81115b9ad05c0fc6
1//===-- AsmPrinterDwarf.cpp - AsmPrinter Dwarf Support --------------------===//
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// This file implements the Dwarf emissions parts of AsmPrinter.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "asm-printer"
15#include "llvm/CodeGen/AsmPrinter.h"
16#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCStreamer.h"
18#include "llvm/ADT/Twine.h"
19using namespace llvm;
20
21/// EmitSLEB128 - emit the specified signed leb128 value.
22void AsmPrinter::EmitSLEB128(int Value, const char *Desc) const {
23  if (isVerbose() && Desc)
24    OutStreamer.AddComment(Desc);
25
26  if (MAI->hasLEB128()) {
27    // FIXME: MCize.
28    OutStreamer.EmitRawText("\t.sleb128\t" + Twine(Value));
29    return;
30  }
31
32  // If we don't have .sleb128, emit as .bytes.
33  int Sign = Value >> (8 * sizeof(Value) - 1);
34  bool IsMore;
35
36  do {
37    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
38    Value >>= 7;
39    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
40    if (IsMore) Byte |= 0x80;
41    OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
42  } while (IsMore);
43}
44
45/// EmitULEB128 - emit the specified signed leb128 value.
46void AsmPrinter::EmitULEB128(unsigned Value, const char *Desc,
47                             unsigned PadTo) const {
48  if (isVerbose() && Desc)
49    OutStreamer.AddComment(Desc);
50
51  if (MAI->hasLEB128() && PadTo == 0) {
52    // FIXME: MCize.
53    OutStreamer.EmitRawText("\t.uleb128\t" + Twine(Value));
54    return;
55  }
56
57  // If we don't have .uleb128 or we want to emit padding, emit as .bytes.
58  do {
59    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
60    Value >>= 7;
61    if (Value || PadTo != 0) Byte |= 0x80;
62    OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
63  } while (Value);
64
65  if (PadTo) {
66    if (PadTo > 1)
67      OutStreamer.EmitFill(PadTo - 1, 0x80/*fillval*/, 0/*addrspace*/);
68    OutStreamer.EmitFill(1, 0/*fillval*/, 0/*addrspace*/);
69  }
70}
71
72