Revert 122160 while I debug it.
[oota-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/MCExpr.h"
11 #include "llvm/MC/MCObjectWriter.h"
12 #include "llvm/MC/MCSymbol.h"
13
14 using namespace llvm;
15
16 MCObjectWriter::~MCObjectWriter() {
17 }
18
19 /// Utility function to encode a SLEB128 value.
20 void MCObjectWriter::EncodeSLEB128(int64_t Value, raw_ostream &OS) {
21   bool More;
22   do {
23     uint8_t Byte = Value & 0x7f;
24     // NOTE: this assumes that this signed shift is an arithmetic right shift.
25     Value >>= 7;
26     More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) ||
27               ((Value == -1) && ((Byte & 0x40) != 0))));
28     if (More)
29       Byte |= 0x80; // Mark this byte that that more bytes will follow.
30     OS << char(Byte);
31   } while (More);
32 }
33
34 /// Utility function to encode a ULEB128 value.
35 void MCObjectWriter::EncodeULEB128(uint64_t Value, raw_ostream &OS) {
36   do {
37     uint8_t Byte = Value & 0x7f;
38     Value >>= 7;
39     if (Value != 0)
40       Byte |= 0x80; // Mark this byte that that more bytes will follow.
41     OS << char(Byte);
42   } while (Value != 0);
43 }
44
45 bool
46 MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
47                                                    const MCSymbolRefExpr *A,
48                                                    const MCSymbolRefExpr *B,
49                                                    bool InSet) const {
50   // Modified symbol references cannot be resolved.
51   if (A->getKind() != MCSymbolRefExpr::VK_None ||
52       B->getKind() != MCSymbolRefExpr::VK_None)
53     return false;
54
55   const MCSymbol &SA = A->getSymbol();
56   const MCSymbol &SB = B->getSymbol();
57   if (SA.isUndefined() || SB.isUndefined())
58     return false;
59
60   // On ELF and COFF A - B is absolute if A and B are in the same section.
61   return &SA.getSection() == &SB.getSection();
62 }