1 //===-- M68kMCTargetDesc.cpp - M68k Target Descriptions ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// This file provides M68k target specific descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "M68kMCTargetDesc.h"
15 #include "M68kInstPrinter.h"
16 #include "M68kMCAsmInfo.h"
17 #include "TargetInfo/M68kTargetInfo.h"
19 #include "llvm/MC/MCELFStreamer.h"
20 #include "llvm/MC/MCInstPrinter.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/MC/MachineLocation.h"
26 #include "llvm/MC/TargetRegistry.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/Support/FormattedStream.h"
33 #define GET_INSTRINFO_MC_DESC
34 #include "M68kGenInstrInfo.inc"
36 #define GET_SUBTARGETINFO_MC_DESC
37 #include "M68kGenSubtargetInfo.inc"
39 #define GET_REGINFO_MC_DESC
40 #include "M68kGenRegisterInfo.inc"
42 // TODO Implement feature set parsing logics
43 static std::string
ParseM68kTriple(const Triple
&TT
, StringRef CPU
) {
47 static MCInstrInfo
*createM68kMCInstrInfo() {
48 MCInstrInfo
*X
= new MCInstrInfo();
49 InitM68kMCInstrInfo(X
); // defined in M68kGenInstrInfo.inc
53 static MCRegisterInfo
*createM68kMCRegisterInfo(const Triple
&TT
) {
54 MCRegisterInfo
*X
= new MCRegisterInfo();
55 InitM68kMCRegisterInfo(X
, llvm::M68k::A0
, 0, 0, llvm::M68k::PC
);
59 static MCSubtargetInfo
*createM68kMCSubtargetInfo(const Triple
&TT
,
60 StringRef CPU
, StringRef FS
) {
61 std::string ArchFS
= ParseM68kTriple(TT
, CPU
);
63 if (!ArchFS
.empty()) {
64 ArchFS
= (ArchFS
+ "," + FS
).str();
69 return createM68kMCSubtargetInfoImpl(TT
, CPU
, /*TuneCPU=*/CPU
, ArchFS
);
72 static MCAsmInfo
*createM68kMCAsmInfo(const MCRegisterInfo
&MRI
,
74 const MCTargetOptions
&TO
) {
75 MCAsmInfo
*MAI
= new M68kELFMCAsmInfo(TT
);
77 // Initialize initial frame state.
78 // Calculate amount of bytes used for return address storing
81 // Initial state of the frame pointer is SP+StackGrowth.
82 // TODO: Add tests for `cfi_*` directives
83 MCCFIInstruction Inst
= MCCFIInstruction::cfiDefCfa(
84 nullptr, MRI
.getDwarfRegNum(llvm::M68k::SP
, true), -StackGrowth
);
85 MAI
->addInitialFrameState(Inst
);
87 // Add return address to move list
88 Inst
= MCCFIInstruction::createOffset(
89 nullptr, MRI
.getDwarfRegNum(M68k::PC
, true), StackGrowth
);
90 MAI
->addInitialFrameState(Inst
);
95 static MCRelocationInfo
*createM68kMCRelocationInfo(const Triple
&TheTriple
,
97 // Default to the stock relocation info.
98 return llvm::createMCRelocationInfo(TheTriple
, Ctx
);
101 static MCInstPrinter
*createM68kMCInstPrinter(const Triple
&T
,
102 unsigned SyntaxVariant
,
103 const MCAsmInfo
&MAI
,
104 const MCInstrInfo
&MII
,
105 const MCRegisterInfo
&MRI
) {
106 return new M68kInstPrinter(MAI
, MII
, MRI
);
109 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeM68kTargetMC() {
110 Target
&T
= getTheM68kTarget();
112 // Register the MC asm info.
113 RegisterMCAsmInfoFn
X(T
, createM68kMCAsmInfo
);
115 // Register the MC instruction info.
116 TargetRegistry::RegisterMCInstrInfo(T
, createM68kMCInstrInfo
);
118 // Register the MC register info.
119 TargetRegistry::RegisterMCRegInfo(T
, createM68kMCRegisterInfo
);
121 // Register the MC subtarget info.
122 TargetRegistry::RegisterMCSubtargetInfo(T
, createM68kMCSubtargetInfo
);
124 // Register the code emitter.
125 TargetRegistry::RegisterMCCodeEmitter(T
, createM68kMCCodeEmitter
);
127 // Register the MCInstPrinter.
128 TargetRegistry::RegisterMCInstPrinter(T
, createM68kMCInstPrinter
);
130 // Register the MC relocation info.
131 TargetRegistry::RegisterMCRelocationInfo(T
, createM68kMCRelocationInfo
);
133 // Register the asm backend.
134 TargetRegistry::RegisterMCAsmBackend(T
, createM68kAsmBackend
);