Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/MCTargetDesc/M68kMCTargetDesc.cpp
35294 views
//===-- M68kMCTargetDesc.cpp - M68k Target Descriptions ---------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file provides M68k target specific descriptions.10///11//===----------------------------------------------------------------------===//1213#include "M68kMCTargetDesc.h"14#include "M68kInstPrinter.h"15#include "M68kMCAsmInfo.h"16#include "TargetInfo/M68kTargetInfo.h"1718#include "llvm/MC/MCELFStreamer.h"19#include "llvm/MC/MCInstPrinter.h"20#include "llvm/MC/MCInstrInfo.h"21#include "llvm/MC/MCRegisterInfo.h"22#include "llvm/MC/MCSubtargetInfo.h"23#include "llvm/MC/MCSymbol.h"24#include "llvm/MC/MachineLocation.h"25#include "llvm/MC/TargetRegistry.h"26#include "llvm/Support/CommandLine.h"27#include "llvm/Support/ErrorHandling.h"28#include "llvm/Support/FormattedStream.h"2930using namespace llvm;3132#define GET_INSTRINFO_MC_DESC33#define ENABLE_INSTR_PREDICATE_VERIFIER34#include "M68kGenInstrInfo.inc"3536#define GET_SUBTARGETINFO_MC_DESC37#include "M68kGenSubtargetInfo.inc"3839#define GET_REGINFO_MC_DESC40#include "M68kGenRegisterInfo.inc"4142// TODO Implement feature set parsing logics43static std::string ParseM68kTriple(const Triple &TT, StringRef CPU) {44return "";45}4647static MCInstrInfo *createM68kMCInstrInfo() {48MCInstrInfo *X = new MCInstrInfo();49InitM68kMCInstrInfo(X); // defined in M68kGenInstrInfo.inc50return X;51}5253static MCRegisterInfo *createM68kMCRegisterInfo(const Triple &TT) {54MCRegisterInfo *X = new MCRegisterInfo();55InitM68kMCRegisterInfo(X, llvm::M68k::A0, 0, 0, llvm::M68k::PC);56return X;57}5859static MCSubtargetInfo *createM68kMCSubtargetInfo(const Triple &TT,60StringRef CPU, StringRef FS) {61std::string ArchFS = ParseM68kTriple(TT, CPU);62if (!FS.empty()) {63if (!ArchFS.empty()) {64ArchFS = (ArchFS + "," + FS).str();65} else {66ArchFS = FS.str();67}68}69return createM68kMCSubtargetInfoImpl(TT, CPU, /*TuneCPU=*/CPU, ArchFS);70}7172static MCAsmInfo *createM68kMCAsmInfo(const MCRegisterInfo &MRI,73const Triple &TT,74const MCTargetOptions &TO) {75MCAsmInfo *MAI = new M68kELFMCAsmInfo(TT);7677// Initialize initial frame state.78// Calculate amount of bytes used for return address storing79int StackGrowth = -4;8081// Initial state of the frame pointer is SP+StackGrowth.82// TODO: Add tests for `cfi_*` directives83MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(84nullptr, MRI.getDwarfRegNum(llvm::M68k::SP, true), -StackGrowth);85MAI->addInitialFrameState(Inst);8687// Add return address to move list88Inst = MCCFIInstruction::createOffset(89nullptr, MRI.getDwarfRegNum(M68k::PC, true), StackGrowth);90MAI->addInitialFrameState(Inst);9192return MAI;93}9495static MCRelocationInfo *createM68kMCRelocationInfo(const Triple &TheTriple,96MCContext &Ctx) {97// Default to the stock relocation info.98return llvm::createMCRelocationInfo(TheTriple, Ctx);99}100101static MCInstPrinter *createM68kMCInstPrinter(const Triple &T,102unsigned SyntaxVariant,103const MCAsmInfo &MAI,104const MCInstrInfo &MII,105const MCRegisterInfo &MRI) {106return new M68kInstPrinter(MAI, MII, MRI);107}108109extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kTargetMC() {110Target &T = getTheM68kTarget();111112// Register the MC asm info.113RegisterMCAsmInfoFn X(T, createM68kMCAsmInfo);114115// Register the MC instruction info.116TargetRegistry::RegisterMCInstrInfo(T, createM68kMCInstrInfo);117118// Register the MC register info.119TargetRegistry::RegisterMCRegInfo(T, createM68kMCRegisterInfo);120121// Register the MC subtarget info.122TargetRegistry::RegisterMCSubtargetInfo(T, createM68kMCSubtargetInfo);123124// Register the code emitter.125TargetRegistry::RegisterMCCodeEmitter(T, createM68kMCCodeEmitter);126127// Register the MCInstPrinter.128TargetRegistry::RegisterMCInstPrinter(T, createM68kMCInstPrinter);129130// Register the MC relocation info.131TargetRegistry::RegisterMCRelocationInfo(T, createM68kMCRelocationInfo);132133// Register the asm backend.134TargetRegistry::RegisterMCAsmBackend(T, createM68kAsmBackend);135}136137138