1 //===-- VEAsmPrinter.cpp - VE LLVM assembly writer ------------------------===// 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 contains a printer that converts from our internal representation 10 // of machine-dependent LLVM code to GAS-format VE assembly language. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "InstPrinter/VEInstPrinter.h" 15 #include "MCTargetDesc/VETargetStreamer.h" 16 #include "VE.h" 17 #include "VEInstrInfo.h" 18 #include "VETargetMachine.h" 19 #include "llvm/CodeGen/AsmPrinter.h" 20 #include "llvm/CodeGen/MachineInstr.h" 21 #include "llvm/CodeGen/MachineModuleInfoImpls.h" 22 #include "llvm/CodeGen/MachineRegisterInfo.h" 23 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" 24 #include "llvm/IR/Mangler.h" 25 #include "llvm/MC/MCAsmInfo.h" 26 #include "llvm/MC/MCContext.h" 27 #include "llvm/MC/MCInst.h" 28 #include "llvm/MC/MCInstBuilder.h" 29 #include "llvm/MC/MCStreamer.h" 30 #include "llvm/MC/MCSymbol.h" 31 #include "llvm/Support/TargetRegistry.h" 32 #include "llvm/Support/raw_ostream.h" 33 using namespace llvm; 34 35 #define DEBUG_TYPE "ve-asmprinter" 36 37 namespace { 38 class VEAsmPrinter : public AsmPrinter { 39 VETargetStreamer &getTargetStreamer() { 40 return static_cast<VETargetStreamer &>(*OutStreamer->getTargetStreamer()); 41 } 42 43 public: 44 explicit VEAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer) 45 : AsmPrinter(TM, std::move(Streamer)) {} 46 47 StringRef getPassName() const override { return "VE Assembly Printer"; } 48 49 void EmitInstruction(const MachineInstr *MI) override; 50 51 static const char *getRegisterName(unsigned RegNo) { 52 return VEInstPrinter::getRegisterName(RegNo); 53 } 54 }; 55 } // end of anonymous namespace 56 57 void VEAsmPrinter::EmitInstruction(const MachineInstr *MI) { 58 59 switch (MI->getOpcode()) { 60 default: 61 break; 62 case TargetOpcode::DBG_VALUE: 63 // FIXME: Debug Value. 64 return; 65 } 66 MachineBasicBlock::const_instr_iterator I = MI->getIterator(); 67 MachineBasicBlock::const_instr_iterator E = MI->getParent()->instr_end(); 68 do { 69 MCInst TmpInst; 70 LowerVEMachineInstrToMCInst(&*I, TmpInst, *this); 71 EmitToStreamer(*OutStreamer, TmpInst); 72 } while ((++I != E) && I->isInsideBundle()); // Delay slot check. 73 } 74 75 // Force static initialization. 76 extern "C" void LLVMInitializeVEAsmPrinter() { 77 RegisterAsmPrinter<VEAsmPrinter> X(getTheVETarget()); 78 } 79