1 //===-- CSKYAsmPrinter.cpp - CSKY 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 the CSKY assembly language.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "CSKYAsmPrinter.h"
14 #include "CSKY.h"
15 #include "CSKYTargetMachine.h"
16 #include "MCTargetDesc/CSKYInstPrinter.h"
17 #include "MCTargetDesc/CSKYMCExpr.h"
18 #include "TargetInfo/CSKYTargetInfo.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/CodeGen/MachineConstantPool.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCInstBuilder.h"
26 #include "llvm/MC/MCStreamer.h"
27 #include "llvm/MC/TargetRegistry.h"
28 
29 using namespace llvm;
30 
31 #define DEBUG_TYPE "csky-asm-printer"
32 
33 CSKYAsmPrinter::CSKYAsmPrinter(llvm::TargetMachine &TM,
34                                std::unique_ptr<llvm::MCStreamer> Streamer)
35     : AsmPrinter(TM, std::move(Streamer)), MCInstLowering(OutContext, *this) {}
36 
37 bool CSKYAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
38   Subtarget = &MF.getSubtarget<CSKYSubtarget>();
39   return AsmPrinter::runOnMachineFunction(MF);
40 }
41 
42 // Simple pseudo-instructions have their lowering (with expansion to real
43 // instructions) auto-generated.
44 #include "CSKYGenMCPseudoLowering.inc"
45 
46 void CSKYAsmPrinter::emitInstruction(const MachineInstr *MI) {
47   // Do any auto-generated pseudo lowerings.
48   if (emitPseudoExpansionLowering(*OutStreamer, MI))
49     return;
50 
51   MCInst TmpInst;
52   MCInstLowering.Lower(MI, TmpInst);
53   EmitToStreamer(*OutStreamer, TmpInst);
54 }
55 
56 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYAsmPrinter() {
57   RegisterAsmPrinter<CSKYAsmPrinter> X(getTheCSKYTarget());
58 }
59