blob: b6adf8450282032cc94fab514f43139f6f4939b5 [file] [log] [blame]
Jan Voungec270732015-01-12 17:00:22 -08001//===- 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"
16#include "IceOperand.h"
17
18namespace Ice {
19
Jan Voungf644a4b2015-03-19 11:57:52 -070020const Constant *AssemblerFixup::NullSymbol = nullptr;
21
Jan Voungec270732015-01-12 17:00:22 -080022RelocOffsetT AssemblerFixup::offset() const {
Jan Voungf644a4b2015-03-19 11:57:52 -070023 if (isNullSymbol())
24 return 0;
Jan Voungec270732015-01-12 17:00:22 -080025 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_))
26 return CR->getOffset();
27 return 0;
28}
29
30IceString AssemblerFixup::symbol(const GlobalContext *Ctx) const {
31 std::string Buffer;
32 llvm::raw_string_ostream Str(Buffer);
33 const Constant *C = value_;
Jan Voungf644a4b2015-03-19 11:57:52 -070034 assert(!isNullSymbol());
Jan Voungec270732015-01-12 17:00:22 -080035 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(C)) {
36 if (CR->getSuppressMangling())
37 Str << CR->getName();
38 else
39 Str << Ctx->mangleName(CR->getName());
40 } else {
41 // NOTE: currently only float/doubles are put into constant pools.
42 // In the future we may put integers as well.
43 assert(llvm::isa<ConstantFloat>(C) || llvm::isa<ConstantDouble>(C));
44 C->emitPoolLabel(Str);
45 }
46 return Str.str();
47}
48
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070049void AssemblerFixup::emit(GlobalContext *Ctx, RelocOffsetT BaseOffset) const {
50 if (!ALLOW_DUMP)
51 return;
Jan Voungec270732015-01-12 17:00:22 -080052 Ostream &Str = Ctx->getStrEmit();
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070053 if (isNullSymbol())
54 Str << "__Sz_AbsoluteZero";
55 else
56 Str << symbol(Ctx);
57 RelocOffsetT Offset = offset() + BaseOffset;
Jan Voungec270732015-01-12 17:00:22 -080058 if (Offset)
59 Str << " + " << Offset;
60}
61
62} // end of namespace Ice