10b57cec5SDimitry Andric //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file contains a printer that converts from our internal representation 100b57cec5SDimitry Andric // of machine-dependent LLVM code to GNU format ARC assembly language. 110b57cec5SDimitry Andric // 120b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #include "ARC.h" 150b57cec5SDimitry Andric #include "ARCMCInstLower.h" 160b57cec5SDimitry Andric #include "ARCSubtarget.h" 170b57cec5SDimitry Andric #include "ARCTargetMachine.h" 180b57cec5SDimitry Andric #include "MCTargetDesc/ARCInstPrinter.h" 190b57cec5SDimitry Andric #include "TargetInfo/ARCTargetInfo.h" 200b57cec5SDimitry Andric #include "llvm/CodeGen/AsmPrinter.h" 210b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstr.h" 220b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 230b57cec5SDimitry Andric #include "llvm/MC/MCInst.h" 240b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h" 25349cc55cSDimitry Andric #include "llvm/MC/TargetRegistry.h" 260b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h" 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric using namespace llvm; 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric #define DEBUG_TYPE "asm-printer" 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric namespace { 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric class ARCAsmPrinter : public AsmPrinter { 350b57cec5SDimitry Andric ARCMCInstLower MCInstLowering; 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric public: ARCAsmPrinter(TargetMachine & TM,std::unique_ptr<MCStreamer> Streamer)380b57cec5SDimitry Andric explicit ARCAsmPrinter(TargetMachine &TM, 390b57cec5SDimitry Andric std::unique_ptr<MCStreamer> Streamer) 400b57cec5SDimitry Andric : AsmPrinter(TM, std::move(Streamer)), 410b57cec5SDimitry Andric MCInstLowering(&OutContext, *this) {} 420b57cec5SDimitry Andric getPassName() const430b57cec5SDimitry Andric StringRef getPassName() const override { return "ARC Assembly Printer"; } 445ffd83dbSDimitry Andric void emitInstruction(const MachineInstr *MI) override; 455ffd83dbSDimitry Andric 465ffd83dbSDimitry Andric bool runOnMachineFunction(MachineFunction &MF) override; 470b57cec5SDimitry Andric }; 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric } // end anonymous namespace 500b57cec5SDimitry Andric emitInstruction(const MachineInstr * MI)515ffd83dbSDimitry Andricvoid ARCAsmPrinter::emitInstruction(const MachineInstr *MI) { 52*753f127fSDimitry Andric ARC_MC::verifyInstructionPredicates(MI->getOpcode(), 53*753f127fSDimitry Andric getSubtargetInfo().getFeatureBits()); 54*753f127fSDimitry Andric 550b57cec5SDimitry Andric SmallString<128> Str; 560b57cec5SDimitry Andric raw_svector_ostream O(Str); 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric switch (MI->getOpcode()) { 590b57cec5SDimitry Andric case ARC::DBG_VALUE: 600b57cec5SDimitry Andric llvm_unreachable("Should be handled target independently"); 610b57cec5SDimitry Andric break; 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric 640b57cec5SDimitry Andric MCInst TmpInst; 650b57cec5SDimitry Andric MCInstLowering.Lower(MI, TmpInst); 660b57cec5SDimitry Andric EmitToStreamer(*OutStreamer, TmpInst); 670b57cec5SDimitry Andric } 680b57cec5SDimitry Andric runOnMachineFunction(MachineFunction & MF)695ffd83dbSDimitry Andricbool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) { 705ffd83dbSDimitry Andric // Functions are 4-byte aligned. 715ffd83dbSDimitry Andric MF.ensureAlignment(Align(4)); 725ffd83dbSDimitry Andric return AsmPrinter::runOnMachineFunction(MF); 735ffd83dbSDimitry Andric } 745ffd83dbSDimitry Andric 750b57cec5SDimitry Andric // Force static initialization. LLVMInitializeARCAsmPrinter()76480093f4SDimitry Andricextern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter() { 770b57cec5SDimitry Andric RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget()); 780b57cec5SDimitry Andric } 79