LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SystemZMCAsmBackend.cpp
Go to the documentation of this file.
1 //===-- SystemZMCAsmBackend.cpp - SystemZ assembler backend ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 #include "llvm/MC/MCAsmBackend.h"
15 #include "llvm/MC/MCInst.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 
18 using namespace llvm;
19 
20 // Value is a fully-resolved relocation value: Symbol + Addend [- Pivot].
21 // Return the bits that should be installed in a relocation field for
22 // fixup kind Kind.
23 static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value) {
24  if (Kind < FirstTargetFixupKind)
25  return Value;
26 
27  switch (unsigned(Kind)) {
32  return (int64_t)Value / 2;
33  }
34 
35  llvm_unreachable("Unknown fixup kind!");
36 }
37 
38 namespace {
39 class SystemZMCAsmBackend : public MCAsmBackend {
40  uint8_t OSABI;
41 public:
42  SystemZMCAsmBackend(uint8_t osABI)
43  : OSABI(osABI) {}
44 
45  // Override MCAsmBackend
46  virtual unsigned getNumFixupKinds() const LLVM_OVERRIDE {
48  }
49  virtual const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const
51  virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
52  uint64_t Value) const LLVM_OVERRIDE;
53  virtual bool mayNeedRelaxation(const MCInst &Inst) const LLVM_OVERRIDE {
54  return false;
55  }
56  virtual bool fixupNeedsRelaxation(const MCFixup &Fixup,
57  uint64_t Value,
58  const MCRelaxableFragment *Fragment,
59  const MCAsmLayout &Layout) const
61  return false;
62  }
63  virtual void relaxInstruction(const MCInst &Inst,
64  MCInst &Res) const LLVM_OVERRIDE {
65  llvm_unreachable("SystemZ does do not have assembler relaxation");
66  }
67  virtual bool writeNopData(uint64_t Count,
68  MCObjectWriter *OW) const LLVM_OVERRIDE;
69  virtual MCObjectWriter *createObjectWriter(raw_ostream &OS) const
71  return createSystemZObjectWriter(OS, OSABI);
72  }
73  virtual bool doesSectionRequireSymbols(const MCSection &Section) const
75  return false;
76  }
77 };
78 } // end anonymous namespace
79 
80 const MCFixupKindInfo &
81 SystemZMCAsmBackend::getFixupKindInfo(MCFixupKind Kind) const {
82  const static MCFixupKindInfo Infos[SystemZ::NumTargetFixupKinds] = {
83  { "FK_390_PC16DBL", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
84  { "FK_390_PC32DBL", 0, 32, MCFixupKindInfo::FKF_IsPCRel },
85  { "FK_390_PLT16DBL", 0, 16, MCFixupKindInfo::FKF_IsPCRel },
86  { "FK_390_PLT32DBL", 0, 32, MCFixupKindInfo::FKF_IsPCRel }
87  };
88 
89  if (Kind < FirstTargetFixupKind)
90  return MCAsmBackend::getFixupKindInfo(Kind);
91 
92  assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
93  "Invalid kind!");
94  return Infos[Kind - FirstTargetFixupKind];
95 }
96 
97 void SystemZMCAsmBackend::applyFixup(const MCFixup &Fixup, char *Data,
98  unsigned DataSize, uint64_t Value) const {
99  MCFixupKind Kind = Fixup.getKind();
100  unsigned Offset = Fixup.getOffset();
101  unsigned Size = (getFixupKindInfo(Kind).TargetSize + 7) / 8;
102 
103  assert(Offset + Size <= DataSize && "Invalid fixup offset!");
104 
105  // Big-endian insertion of Size bytes.
106  Value = extractBitsForFixup(Kind, Value);
107  unsigned ShiftValue = (Size * 8) - 8;
108  for (unsigned I = 0; I != Size; ++I) {
109  Data[Offset + I] |= uint8_t(Value >> ShiftValue);
110  ShiftValue -= 8;
111  }
112 }
113 
114 bool SystemZMCAsmBackend::writeNopData(uint64_t Count,
115  MCObjectWriter *OW) const {
116  for (uint64_t I = 0; I != Count; ++I)
117  OW->Write8(7);
118  return true;
119 }
120 
122  const MCRegisterInfo &MRI,
123  StringRef TT, StringRef CPU) {
124  uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS());
125  return new SystemZMCAsmBackend(OSABI);
126 }
MCAsmBackend * createSystemZMCAsmBackend(const Target &T, const MCRegisterInfo &MRI, StringRef TT, StringRef CPU)
#define llvm_unreachable(msg)
MCObjectWriter * createSystemZObjectWriter(raw_ostream &OS, uint8_t OSABI)
uint32_t getOffset() const
Definition: MCFixup.h:90
void Write8(uint8_t Value)
MCFixupKind
MCFixupKind - Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:22
MCFixupKind getKind() const
Definition: MCFixup.h:88
static uint64_t extractBitsForFixup(MCFixupKind Kind, uint64_t Value)
#define I(x, y, z)
Definition: MD5.cpp:54
MCFixupKindInfo - Target independent information on a fixup kind.
LLVM Value Representation.
Definition: Value.h:66
MCAsmBackend - Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:34
const MCRegisterInfo & MRI
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
getFixupKindInfo - Get information on a fixup kind.
#define LLVM_OVERRIDE
Definition: Compiler.h:155