1 //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===// 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 GNU format ARC assembly language. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "ARC.h" 15 #include "ARCMCInstLower.h" 16 #include "ARCSubtarget.h" 17 #include "ARCTargetMachine.h" 18 #include "MCTargetDesc/ARCInstPrinter.h" 19 #include "TargetInfo/ARCTargetInfo.h" 20 #include "llvm/CodeGen/AsmPrinter.h" 21 #include "llvm/CodeGen/MachineInstr.h" 22 #include "llvm/MC/MCAsmInfo.h" 23 #include "llvm/MC/MCInst.h" 24 #include "llvm/MC/MCStreamer.h" 25 #include "llvm/MC/TargetRegistry.h" 26 #include "llvm/Support/raw_ostream.h" 27 28 using namespace llvm; 29 30 #define DEBUG_TYPE "asm-printer" 31 32 namespace { 33 34 class ARCAsmPrinter : public AsmPrinter { 35 ARCMCInstLower MCInstLowering; 36 37 public: 38 static char ID; 39 40 explicit ARCAsmPrinter(TargetMachine &TM, 41 std::unique_ptr<MCStreamer> Streamer) 42 : AsmPrinter(TM, std::move(Streamer), ID), 43 MCInstLowering(&OutContext, *this) {} 44 45 StringRef getPassName() const override { return "ARC Assembly Printer"; } 46 void emitInstruction(const MachineInstr *MI) override; 47 48 bool runOnMachineFunction(MachineFunction &MF) override; 49 }; 50 51 } // end anonymous namespace 52 53 void ARCAsmPrinter::emitInstruction(const MachineInstr *MI) { 54 ARC_MC::verifyInstructionPredicates(MI->getOpcode(), 55 getSubtargetInfo().getFeatureBits()); 56 57 SmallString<128> Str; 58 raw_svector_ostream O(Str); 59 60 switch (MI->getOpcode()) { 61 case ARC::DBG_VALUE: 62 llvm_unreachable("Should be handled target independently"); 63 break; 64 } 65 66 MCInst TmpInst; 67 MCInstLowering.Lower(MI, TmpInst); 68 EmitToStreamer(*OutStreamer, TmpInst); 69 } 70 71 bool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) { 72 // Functions are 4-byte aligned. 73 MF.ensureAlignment(Align(4)); 74 return AsmPrinter::runOnMachineFunction(MF); 75 } 76 77 char ARCAsmPrinter::ID = 0; 78 79 INITIALIZE_PASS(ARCAsmPrinter, "arc-asm-printer", "ARC Assmebly Printer", false, 80 false) 81 82 // Force static initialization. 83 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter() { 84 RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget()); 85 } 86