Path: blob/main/contrib/llvm-project/llvm/lib/Target/ARC/ARCAsmPrinter.cpp
35294 views
//===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- 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// This file contains a printer that converts from our internal representation9// of machine-dependent LLVM code to GNU format ARC assembly language.10//11//===----------------------------------------------------------------------===//1213#include "ARC.h"14#include "ARCMCInstLower.h"15#include "ARCSubtarget.h"16#include "ARCTargetMachine.h"17#include "MCTargetDesc/ARCInstPrinter.h"18#include "TargetInfo/ARCTargetInfo.h"19#include "llvm/CodeGen/AsmPrinter.h"20#include "llvm/CodeGen/MachineInstr.h"21#include "llvm/MC/MCAsmInfo.h"22#include "llvm/MC/MCInst.h"23#include "llvm/MC/MCStreamer.h"24#include "llvm/MC/TargetRegistry.h"25#include "llvm/Support/raw_ostream.h"2627using namespace llvm;2829#define DEBUG_TYPE "asm-printer"3031namespace {3233class ARCAsmPrinter : public AsmPrinter {34ARCMCInstLower MCInstLowering;3536public:37explicit ARCAsmPrinter(TargetMachine &TM,38std::unique_ptr<MCStreamer> Streamer)39: AsmPrinter(TM, std::move(Streamer)),40MCInstLowering(&OutContext, *this) {}4142StringRef getPassName() const override { return "ARC Assembly Printer"; }43void emitInstruction(const MachineInstr *MI) override;4445bool runOnMachineFunction(MachineFunction &MF) override;46};4748} // end anonymous namespace4950void ARCAsmPrinter::emitInstruction(const MachineInstr *MI) {51ARC_MC::verifyInstructionPredicates(MI->getOpcode(),52getSubtargetInfo().getFeatureBits());5354SmallString<128> Str;55raw_svector_ostream O(Str);5657switch (MI->getOpcode()) {58case ARC::DBG_VALUE:59llvm_unreachable("Should be handled target independently");60break;61}6263MCInst TmpInst;64MCInstLowering.Lower(MI, TmpInst);65EmitToStreamer(*OutStreamer, TmpInst);66}6768bool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) {69// Functions are 4-byte aligned.70MF.ensureAlignment(Align(4));71return AsmPrinter::runOnMachineFunction(MF);72}7374// Force static initialization.75extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter() {76RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget());77}787980