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