blob: 930191094a5751bf8f6aeb4aff46494c4827bff9 [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"
John Porto67f8de92015-06-25 10:14:17 -070016
Jan Voungec270732015-01-12 17:00:22 -080017#include "IceOperand.h"
18
19namespace Ice {
20
Jan Voungf644a4b2015-03-19 11:57:52 -070021const Constant *AssemblerFixup::NullSymbol = nullptr;
22
Jan Voungec270732015-01-12 17:00:22 -080023RelocOffsetT AssemblerFixup::offset() const {
Jan Voungf644a4b2015-03-19 11:57:52 -070024 if (isNullSymbol())
25 return 0;
Jan Voungec270732015-01-12 17:00:22 -080026 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_))
27 return CR->getOffset();
28 return 0;
29}
30
31IceString AssemblerFixup::symbol(const GlobalContext *Ctx) const {
32 std::string Buffer;
33 llvm::raw_string_ostream Str(Buffer);
34 const Constant *C = value_;
Jan Voungf644a4b2015-03-19 11:57:52 -070035 assert(!isNullSymbol());
Jan Voungec270732015-01-12 17:00:22 -080036 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 Stichnoth927f7cc2015-03-19 23:23:00 -070050void AssemblerFixup::emit(GlobalContext *Ctx, RelocOffsetT BaseOffset) const {
Jim Stichnoth20b71f52015-06-24 15:52:24 -070051 if (!BuildDefs::dump())
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070052 return;
Jan Voungec270732015-01-12 17:00:22 -080053 Ostream &Str = Ctx->getStrEmit();
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070054 if (isNullSymbol())
55 Str << "__Sz_AbsoluteZero";
56 else
57 Str << symbol(Ctx);
58 RelocOffsetT Offset = offset() + BaseOffset;
Jan Voungec270732015-01-12 17:00:22 -080059 if (Offset)
60 Str << " + " << Offset;
61}
62
63} // end of namespace Ice