xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/CSKY/MCTargetDesc/CSKYAsmBackend.cpp (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
1*e8d8bef9SDimitry Andric //===-- CSKYAsmBackend.cpp - CSKY Assembler Backend -----------------------===//
2*e8d8bef9SDimitry Andric //
3*e8d8bef9SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e8d8bef9SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*e8d8bef9SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e8d8bef9SDimitry Andric //
7*e8d8bef9SDimitry Andric //===----------------------------------------------------------------------===//
8*e8d8bef9SDimitry Andric 
9*e8d8bef9SDimitry Andric #include "CSKYAsmBackend.h"
10*e8d8bef9SDimitry Andric #include "MCTargetDesc/CSKYMCTargetDesc.h"
11*e8d8bef9SDimitry Andric #include "llvm/MC/MCAsmLayout.h"
12*e8d8bef9SDimitry Andric #include "llvm/MC/MCAssembler.h"
13*e8d8bef9SDimitry Andric #include "llvm/MC/MCContext.h"
14*e8d8bef9SDimitry Andric #include "llvm/MC/MCFixupKindInfo.h"
15*e8d8bef9SDimitry Andric #include "llvm/MC/MCObjectWriter.h"
16*e8d8bef9SDimitry Andric #include "llvm/Support/Debug.h"
17*e8d8bef9SDimitry Andric 
18*e8d8bef9SDimitry Andric #define DEBUG_TYPE "csky-asmbackend"
19*e8d8bef9SDimitry Andric 
20*e8d8bef9SDimitry Andric using namespace llvm;
21*e8d8bef9SDimitry Andric 
22*e8d8bef9SDimitry Andric std::unique_ptr<MCObjectTargetWriter>
23*e8d8bef9SDimitry Andric CSKYAsmBackend::createObjectTargetWriter() const {
24*e8d8bef9SDimitry Andric   return createCSKYELFObjectWriter();
25*e8d8bef9SDimitry Andric }
26*e8d8bef9SDimitry Andric 
27*e8d8bef9SDimitry Andric unsigned int CSKYAsmBackend::getNumFixupKinds() const { return 1; }
28*e8d8bef9SDimitry Andric 
29*e8d8bef9SDimitry Andric void CSKYAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
30*e8d8bef9SDimitry Andric                                 const MCValue &Target,
31*e8d8bef9SDimitry Andric                                 MutableArrayRef<char> Data, uint64_t Value,
32*e8d8bef9SDimitry Andric                                 bool IsResolved,
33*e8d8bef9SDimitry Andric                                 const MCSubtargetInfo *STI) const {
34*e8d8bef9SDimitry Andric   return;
35*e8d8bef9SDimitry Andric }
36*e8d8bef9SDimitry Andric 
37*e8d8bef9SDimitry Andric bool CSKYAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
38*e8d8bef9SDimitry Andric                                           const MCRelaxableFragment *DF,
39*e8d8bef9SDimitry Andric                                           const MCAsmLayout &Layout) const {
40*e8d8bef9SDimitry Andric   return false;
41*e8d8bef9SDimitry Andric }
42*e8d8bef9SDimitry Andric 
43*e8d8bef9SDimitry Andric void CSKYAsmBackend::relaxInstruction(MCInst &Inst,
44*e8d8bef9SDimitry Andric                                       const MCSubtargetInfo &STI) const {
45*e8d8bef9SDimitry Andric   llvm_unreachable("CSKYAsmBackend::relaxInstruction() unimplemented");
46*e8d8bef9SDimitry Andric }
47*e8d8bef9SDimitry Andric 
48*e8d8bef9SDimitry Andric bool CSKYAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count) const {
49*e8d8bef9SDimitry Andric   if (Count % 2)
50*e8d8bef9SDimitry Andric     return false;
51*e8d8bef9SDimitry Andric 
52*e8d8bef9SDimitry Andric   // MOV32 r0, r0
53*e8d8bef9SDimitry Andric   while (Count >= 4) {
54*e8d8bef9SDimitry Andric     OS.write("\xc4\x00\x48\x20", 4);
55*e8d8bef9SDimitry Andric     Count -= 4;
56*e8d8bef9SDimitry Andric   }
57*e8d8bef9SDimitry Andric   // MOV16 r0, r0
58*e8d8bef9SDimitry Andric   if (Count)
59*e8d8bef9SDimitry Andric     OS.write("\x6c\x03", 2);
60*e8d8bef9SDimitry Andric 
61*e8d8bef9SDimitry Andric   return true;
62*e8d8bef9SDimitry Andric }
63*e8d8bef9SDimitry Andric 
64*e8d8bef9SDimitry Andric MCAsmBackend *llvm::createCSKYAsmBackend(const Target &T,
65*e8d8bef9SDimitry Andric                                          const MCSubtargetInfo &STI,
66*e8d8bef9SDimitry Andric                                          const MCRegisterInfo &MRI,
67*e8d8bef9SDimitry Andric                                          const MCTargetOptions &Options) {
68*e8d8bef9SDimitry Andric   return new CSKYAsmBackend(STI, Options);
69*e8d8bef9SDimitry Andric }
70