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