Fixed some bugs.
[llvm/zpu.git] / lib / MC / MCObjectWriter.cpp
blob6cee76d0400ac7d35f1bc75b68d3d8efe5b0d9c4
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 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCObjectWriter.h"
12 using namespace llvm;
14 MCObjectWriter::~MCObjectWriter() {
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);
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);