blob: de00d23b3362d4732ee94b70053e71571cf52812 [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//===----------------------------------------------------------------------===//
Andrew Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
11/// This file implements the AssemblerFixup class, a very basic
12/// target-independent representation of a fixup or relocation.
13///
Jan Voungec270732015-01-12 17:00:22 -080014//===----------------------------------------------------------------------===//
15
16#include "IceFixups.h"
John Porto67f8de92015-06-25 10:14:17 -070017
Jan Voungec270732015-01-12 17:00:22 -080018#include "IceOperand.h"
19
20namespace Ice {
21
Jan Voungf644a4b2015-03-19 11:57:52 -070022const Constant *AssemblerFixup::NullSymbol = nullptr;
23
Jan Voungec270732015-01-12 17:00:22 -080024RelocOffsetT AssemblerFixup::offset() const {
Jan Voungf644a4b2015-03-19 11:57:52 -070025 if (isNullSymbol())
26 return 0;
Jan Voungec270732015-01-12 17:00:22 -080027 if (const auto CR = llvm::dyn_cast<ConstantRelocatable>(value_))
28 return CR->getOffset();
29 return 0;
30}
31
32IceString AssemblerFixup::symbol(const GlobalContext *Ctx) const {
33 std::string Buffer;
34 llvm::raw_string_ostream Str(Buffer);
35 const Constant *C = value_;
Jan Voungf644a4b2015-03-19 11:57:52 -070036 assert(!isNullSymbol());
Jan Voungec270732015-01-12 17:00:22 -080037 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 Stichnoth927f7cc2015-03-19 23:23:00 -070051void AssemblerFixup::emit(GlobalContext *Ctx, RelocOffsetT BaseOffset) const {
Jim Stichnoth20b71f52015-06-24 15:52:24 -070052 if (!BuildDefs::dump())
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070053 return;
Jan Voungec270732015-01-12 17:00:22 -080054 Ostream &Str = Ctx->getStrEmit();
Jim Stichnoth927f7cc2015-03-19 23:23:00 -070055 if (isNullSymbol())
56 Str << "__Sz_AbsoluteZero";
57 else
58 Str << symbol(Ctx);
59 RelocOffsetT Offset = offset() + BaseOffset;
Jan Voungec270732015-01-12 17:00:22 -080060 if (Offset)
61 Str << " + " << Offset;
62}
63
64} // end of namespace Ice