Daniel Dunbar | 2df4ceb | 2010-03-19 10:43:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===// |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 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 | |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame^] | 10 | #include "llvm/MC/MCExpr.h" |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCObjectWriter.h" |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame^] | 12 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 13 | |
| 14 | using namespace llvm; |
| 15 | |
| 16 | MCObjectWriter::~MCObjectWriter() { |
| 17 | } |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 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 | } |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame^] | 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 | } |