98 lines · cpp
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-exception6//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 24using namespace llvm;25 26#define GET_INSTRINFO_MC_DESC27#define ENABLE_INSTR_PREDICATE_VERIFIER28#include "MSP430GenInstrInfo.inc"29 30#define GET_SUBTARGETINFO_MC_DESC31#include "MSP430GenSubtargetInfo.inc"32 33#define GET_REGINFO_MC_DESC34#include "MSP430GenRegisterInfo.inc"35 36static MCInstrInfo *createMSP430MCInstrInfo() {37 MCInstrInfo *X = new MCInstrInfo();38 InitMSP430MCInstrInfo(X);39 return X;40}41 42static MCRegisterInfo *createMSP430MCRegisterInfo(const Triple &TT) {43 MCRegisterInfo *X = new MCRegisterInfo();44 InitMSP430MCRegisterInfo(X, MSP430::PC);45 return X;46}47 48static 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 nullptr, MRI.getDwarfRegNum(MSP430::SP, true), -stackGrowth);59 MAI->addInitialFrameState(Inst);60 61 // Add return address to move list62 MCCFIInstruction Inst2 = MCCFIInstruction::createOffset(63 nullptr, MRI.getDwarfRegNum(MSP430::PC, true), stackGrowth);64 MAI->addInitialFrameState(Inst2);65 66 return MAI;67}68 69static MCSubtargetInfo *70createMSP430MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {71 return createMSP430MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);72}73 74static 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 84extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void85LLVMInitializeMSP430TargetMC() {86 Target &T = getTheMSP430Target();87 88 TargetRegistry::RegisterMCAsmInfo(T, createMSP430MCAsmInfo);89 TargetRegistry::RegisterMCInstrInfo(T, createMSP430MCInstrInfo);90 TargetRegistry::RegisterMCRegInfo(T, createMSP430MCRegisterInfo);91 TargetRegistry::RegisterMCSubtargetInfo(T, createMSP430MCSubtargetInfo);92 TargetRegistry::RegisterMCInstPrinter(T, createMSP430MCInstPrinter);93 TargetRegistry::RegisterMCCodeEmitter(T, createMSP430MCCodeEmitter);94 TargetRegistry::RegisterMCAsmBackend(T, createMSP430MCAsmBackend);95 TargetRegistry::RegisterObjectTargetStreamer(96 T, createMSP430ObjectTargetStreamer);97}98