Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 1 | //===- subzero/src/IceFixups.cpp - Implementation of Assembler Fixups -----===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the AssemblerFixup class, a very basic |
| 11 | // target-independent representation of a fixup or relocation. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "IceFixups.h" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 16 | |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 17 | #include "IceOperand.h" |
| 18 | |
| 19 | namespace Ice { |
| 20 | |
Jan Voung | f644a4b | 2015-03-19 11:57:52 -0700 | [diff] [blame] | 21 | const Constant *AssemblerFixup::NullSymbol = nullptr; |
| 22 | |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 23 | RelocOffsetT AssemblerFixup::offset() const { |
Jan Voung | f644a4b | 2015-03-19 11:57:52 -0700 | [diff] [blame] | 24 | if (isNullSymbol()) |
| 25 | return 0; |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 26 | if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_)) |
| 27 | return CR->getOffset(); |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | IceString AssemblerFixup::symbol(const GlobalContext *Ctx) const { |
| 32 | std::string Buffer; |
| 33 | llvm::raw_string_ostream Str(Buffer); |
| 34 | const Constant *C = value_; |
Jan Voung | f644a4b | 2015-03-19 11:57:52 -0700 | [diff] [blame] | 35 | assert(!isNullSymbol()); |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 36 | if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(C)) { |
| 37 | if (CR->getSuppressMangling()) |
| 38 | Str << CR->getName(); |
| 39 | else |
| 40 | Str << Ctx->mangleName(CR->getName()); |
| 41 | } else { |
| 42 | // NOTE: currently only float/doubles are put into constant pools. |
| 43 | // In the future we may put integers as well. |
| 44 | assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C)); |
| 45 | C->emitPoolLabel(Str); |
| 46 | } |
| 47 | return Str.str(); |
| 48 | } |
| 49 | |
Jim Stichnoth | 927f7cc | 2015-03-19 23:23:00 -0700 | [diff] [blame] | 50 | void AssemblerFixup::emit(GlobalContext *Ctx, RelocOffsetT BaseOffset) const { |
Jim Stichnoth | 20b71f5 | 2015-06-24 15:52:24 -0700 | [diff] [blame] | 51 | if (!BuildDefs::dump()) |
Jim Stichnoth | 927f7cc | 2015-03-19 23:23:00 -0700 | [diff] [blame] | 52 | return; |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 53 | Ostream &Str = Ctx->getStrEmit(); |
Jim Stichnoth | 927f7cc | 2015-03-19 23:23:00 -0700 | [diff] [blame] | 54 | if (isNullSymbol()) |
| 55 | Str << "__Sz_AbsoluteZero"; |
| 56 | else |
| 57 | Str << symbol(Ctx); |
| 58 | RelocOffsetT Offset = offset() + BaseOffset; |
Jan Voung | ec27073 | 2015-01-12 17:00:22 -0800 | [diff] [blame] | 59 | if (Offset) |
| 60 | Str << " + " << Offset; |
| 61 | } |
| 62 | |
| 63 | } // end of namespace Ice |