OSDN Git Service

Merge LLVM upstream r119309 into honey
[android-x86/external-llvm.git] / lib / MC / MCObjectWriter.cpp
1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
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 #include "llvm/MC/MCObjectWriter.h"
11
12 using namespace llvm;
13
14 MCObjectWriter::~MCObjectWriter() {
15 }
16
17 /// Utility function to encode a SLEB128 value.
18 void MCObjectWriter::EncodeSLEB128(int64_t Value, raw_ostream &OS) {
19   bool More;
20   do {
21     uint8_t Byte = Value & 0x7f;
22     // NOTE: this assumes that this signed shift is an arithmetic right shift.
23     Value >>= 7;
24     More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
25               ((Value == -1) && ((Byte & 0x40) != 0))));
26     if (More)
27       Byte |= 0x80; // Mark this byte that that more bytes will follow.
28     OS << char(Byte);
29   } while (More);
30 }
31
32 /// Utility function to encode a ULEB128 value.
33 void MCObjectWriter::EncodeULEB128(uint64_t Value, raw_ostream &OS) {
34   do {
35     uint8_t Byte = Value & 0x7f;
36     Value >>= 7;
37     if (Value != 0)
38       Byte |= 0x80; // Mark this byte that that more bytes will follow.
39     OS << char(Byte);
40   } while (Value != 0);
41 }