1 | //===-- MSP430MCTargetDesc.cpp - MSP430 Target Descriptions ---------------===// |
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 | // This file provides MSP430 specific target descriptions. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "MSP430MCTargetDesc.h" |
14 | #include "MSP430InstPrinter.h" |
15 | #include "MSP430MCAsmInfo.h" |
16 | #include "TargetInfo/MSP430TargetInfo.h" |
17 | #include "llvm/MC/MCDwarf.h" |
18 | #include "llvm/MC/MCInstrInfo.h" |
19 | #include "llvm/MC/MCRegisterInfo.h" |
20 | #include "llvm/MC/MCSubtargetInfo.h" |
21 | #include "llvm/MC/TargetRegistry.h" |
22 | #include "llvm/Support/Compiler.h" |
23 | |
24 | using namespace llvm; |
25 | |
26 | #define GET_INSTRINFO_MC_DESC |
27 | #define ENABLE_INSTR_PREDICATE_VERIFIER |
28 | #include "MSP430GenInstrInfo.inc" |
29 | |
30 | #define GET_SUBTARGETINFO_MC_DESC |
31 | #include "MSP430GenSubtargetInfo.inc" |
32 | |
33 | #define GET_REGINFO_MC_DESC |
34 | #include "MSP430GenRegisterInfo.inc" |
35 | |
36 | static MCInstrInfo *createMSP430MCInstrInfo() { |
37 | MCInstrInfo *X = new MCInstrInfo(); |
38 | InitMSP430MCInstrInfo(II: X); |
39 | return X; |
40 | } |
41 | |
42 | static MCRegisterInfo *createMSP430MCRegisterInfo(const Triple &TT) { |
43 | MCRegisterInfo *X = new MCRegisterInfo(); |
44 | InitMSP430MCRegisterInfo(RI: X, RA: MSP430::PC); |
45 | return X; |
46 | } |
47 | |
48 | static MCAsmInfo *createMSP430MCAsmInfo(const MCRegisterInfo &MRI, |
49 | const Triple &TT, |
50 | const MCTargetOptions &Options) { |
51 | MCAsmInfo *MAI = new MSP430MCAsmInfo(TT); |
52 | |
53 | // Initialize initial frame state. |
54 | int stackGrowth = -2; |
55 | |
56 | // Initial state of the frame pointer is sp+ptr_size. |
57 | MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa( |
58 | L: nullptr, Register: MRI.getDwarfRegNum(RegNum: MSP430::SP, isEH: true), Offset: -stackGrowth); |
59 | MAI->addInitialFrameState(Inst); |
60 | |
61 | // Add return address to move list |
62 | MCCFIInstruction Inst2 = MCCFIInstruction::createOffset( |
63 | L: nullptr, Register: MRI.getDwarfRegNum(RegNum: MSP430::PC, isEH: true), Offset: stackGrowth); |
64 | MAI->addInitialFrameState(Inst: Inst2); |
65 | |
66 | return MAI; |
67 | } |
68 | |
69 | static MCSubtargetInfo * |
70 | createMSP430MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) { |
71 | return createMSP430MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS); |
72 | } |
73 | |
74 | static MCInstPrinter *createMSP430MCInstPrinter(const Triple &T, |
75 | unsigned SyntaxVariant, |
76 | const MCAsmInfo &MAI, |
77 | const MCInstrInfo &MII, |
78 | const MCRegisterInfo &MRI) { |
79 | if (SyntaxVariant == 0) |
80 | return new MSP430InstPrinter(MAI, MII, MRI); |
81 | return nullptr; |
82 | } |
83 | |
84 | extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void |
85 | LLVMInitializeMSP430TargetMC() { |
86 | Target &T = getTheMSP430Target(); |
87 | |
88 | TargetRegistry::RegisterMCAsmInfo(T, Fn: createMSP430MCAsmInfo); |
89 | TargetRegistry::RegisterMCInstrInfo(T, Fn: createMSP430MCInstrInfo); |
90 | TargetRegistry::RegisterMCRegInfo(T, Fn: createMSP430MCRegisterInfo); |
91 | TargetRegistry::RegisterMCSubtargetInfo(T, Fn: createMSP430MCSubtargetInfo); |
92 | TargetRegistry::RegisterMCInstPrinter(T, Fn: createMSP430MCInstPrinter); |
93 | TargetRegistry::RegisterMCCodeEmitter(T, Fn: createMSP430MCCodeEmitter); |
94 | TargetRegistry::RegisterMCAsmBackend(T, Fn: createMSP430MCAsmBackend); |
95 | TargetRegistry::RegisterObjectTargetStreamer( |
96 | T, Fn: createMSP430ObjectTargetStreamer); |
97 | } |
98 | |