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