1 //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains a printer that converts from our internal representation
10 // of machine-dependent LLVM code to GNU format ARC assembly language.
12 //===----------------------------------------------------------------------===//
15 #include "ARCInstrInfo.h"
16 #include "ARCMCInstLower.h"
17 #include "ARCSubtarget.h"
18 #include "ARCTargetMachine.h"
19 #include "ARCTargetStreamer.h"
20 #include "InstPrinter/ARCInstPrinter.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/CodeGen/AsmPrinter.h"
24 #include "llvm/CodeGen/MachineFunctionPass.h"
25 #include "llvm/CodeGen/MachineInstr.h"
26 #include "llvm/CodeGen/MachineModuleInfo.h"
27 #include "llvm/MC/MCAsmInfo.h"
28 #include "llvm/MC/MCExpr.h"
29 #include "llvm/MC/MCInst.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbolELF.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/TargetRegistry.h"
34 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetLoweringObjectFile.h"
40 #define DEBUG_TYPE "asm-printer"
44 class ARCAsmPrinter
: public AsmPrinter
{
45 ARCMCInstLower MCInstLowering
;
46 ARCTargetStreamer
&getTargetStreamer();
49 explicit ARCAsmPrinter(TargetMachine
&TM
,
50 std::unique_ptr
<MCStreamer
> Streamer
)
51 : AsmPrinter(TM
, std::move(Streamer
)),
52 MCInstLowering(&OutContext
, *this) {}
54 StringRef
getPassName() const override
{ return "ARC Assembly Printer"; }
55 void EmitInstruction(const MachineInstr
*MI
) override
;
58 } // end anonymous namespace
60 ARCTargetStreamer
&ARCAsmPrinter::getTargetStreamer() {
61 return static_cast<ARCTargetStreamer
&>(*OutStreamer
->getTargetStreamer());
64 void ARCAsmPrinter::EmitInstruction(const MachineInstr
*MI
) {
66 raw_svector_ostream
O(Str
);
68 switch (MI
->getOpcode()) {
70 llvm_unreachable("Should be handled target independently");
75 MCInstLowering
.Lower(MI
, TmpInst
);
76 EmitToStreamer(*OutStreamer
, TmpInst
);
79 // Force static initialization.
80 extern "C" void LLVMInitializeARCAsmPrinter() {
81 RegisterAsmPrinter
<ARCAsmPrinter
> X(getTheARCTarget());