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 | fea753b | 2010-12-24 21:22:02 +0000 | [diff] [blame^] | 10 | #include "llvm/MC/MCAssembler.h" |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCExpr.h" |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 12 | #include "llvm/MC/MCObjectWriter.h" |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCSymbol.h" |
Daniel Dunbar | 53b2338 | 2010-03-19 09:28:59 +0000 | [diff] [blame] | 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | MCObjectWriter::~MCObjectWriter() { |
| 18 | } |
Kevin Enderby | c095793 | 2010-09-30 16:52:03 +0000 | [diff] [blame] | 19 | |
| 20 | /// Utility function to encode a SLEB128 value. |
| 21 | void MCObjectWriter::EncodeSLEB128(int64_t Value, raw_ostream &OS) { |
| 22 | bool More; |
| 23 | do { |
| 24 | uint8_t Byte = Value & 0x7f; |
| 25 | // NOTE: this assumes that this signed shift is an arithmetic right shift. |
| 26 | Value >>= 7; |
| 27 | More = !((((Value == 0 ) && ((Byte & 0x40) == 0)) || |
| 28 | ((Value == -1) && ((Byte & 0x40) != 0)))); |
| 29 | if (More) |
| 30 | Byte |= 0x80; // Mark this byte that that more bytes will follow. |
| 31 | OS << char(Byte); |
| 32 | } while (More); |
| 33 | } |
| 34 | |
| 35 | /// Utility function to encode a ULEB128 value. |
| 36 | void MCObjectWriter::EncodeULEB128(uint64_t Value, raw_ostream &OS) { |
| 37 | do { |
| 38 | uint8_t Byte = Value & 0x7f; |
| 39 | Value >>= 7; |
| 40 | if (Value != 0) |
| 41 | Byte |= 0x80; // Mark this byte that that more bytes will follow. |
| 42 | OS << char(Byte); |
| 43 | } while (Value != 0); |
| 44 | } |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 45 | |
| 46 | bool |
| 47 | MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, |
| 48 | const MCSymbolRefExpr *A, |
| 49 | const MCSymbolRefExpr *B, |
| 50 | bool InSet) const { |
| 51 | // Modified symbol references cannot be resolved. |
| 52 | if (A->getKind() != MCSymbolRefExpr::VK_None || |
| 53 | B->getKind() != MCSymbolRefExpr::VK_None) |
| 54 | return false; |
| 55 | |
| 56 | const MCSymbol &SA = A->getSymbol(); |
| 57 | const MCSymbol &SB = B->getSymbol(); |
Rafael Espindola | fea753b | 2010-12-24 21:22:02 +0000 | [diff] [blame^] | 58 | if (SA.AliasedSymbol().isUndefined() || SB.AliasedSymbol().isUndefined()) |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 59 | return false; |
| 60 | |
Rafael Espindola | fea753b | 2010-12-24 21:22:02 +0000 | [diff] [blame^] | 61 | const MCSymbolData &DataA = Asm.getSymbolData(SA); |
| 62 | const MCSymbolData &DataB = Asm.getSymbolData(SB); |
| 63 | |
| 64 | return IsSymbolRefDifferenceFullyResolvedImpl(Asm, DataA, |
| 65 | *DataB.getFragment(), |
| 66 | InSet, |
| 67 | false); |
Rafael Espindola | 3132780 | 2010-12-18 06:27:54 +0000 | [diff] [blame] | 68 | } |