blob: 6cee76d0400ac7d35f1bc75b68d3d8efe5b0d9c4 [file] [log] [blame]
Daniel Dunbar2df4ceb2010-03-19 10:43:15 +00001//===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
Daniel Dunbar53b23382010-03-19 09:28:59 +00002//
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
12using namespace llvm;
13
14MCObjectWriter::~MCObjectWriter() {
15}
Kevin Enderbyc0957932010-09-30 16:52:03 +000016
17/// Utility function to encode a SLEB128 value.
18void 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.
33void 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}