1 //===----- M68kAsmPrinter.cpp - M68k LLVM Assembly Printer -----*- 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 /// \file
10 /// This file contains a printer that converts from our internal representation
11 /// of machine-dependent LLVM code to GAS-format M68k assembly language.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 // TODO Conform to Motorola ASM syntax
16 
17 #include "M68kAsmPrinter.h"
18 
19 #include "M68k.h"
20 #include "M68kMachineFunction.h"
21 #include "TargetInfo/M68kTargetInfo.h"
22 
23 #include "llvm/Support/TargetRegistry.h"
24 
25 using namespace llvm;
26 
27 #define DEBUG_TYPE "m68k-asm-printer"
28 
29 bool M68kAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
30   MMFI = MF.getInfo<M68kMachineFunctionInfo>();
31   MCInstLowering = std::make_unique<M68kMCInstLower>(MF, *this);
32   AsmPrinter::runOnMachineFunction(MF);
33   return true;
34 }
35 
36 void M68kAsmPrinter::emitInstruction(const MachineInstr *MI) {
37   switch (MI->getOpcode()) {
38   default: {
39     if (MI->isPseudo()) {
40       LLVM_DEBUG(dbgs() << "Pseudo opcode(" << MI->getOpcode()
41                         << ") found in EmitInstruction()\n");
42       llvm_unreachable("Cannot proceed");
43     }
44     break;
45   }
46   case M68k::TAILJMPj:
47   case M68k::TAILJMPq:
48     // Lower these as normal, but add some comments.
49     OutStreamer->AddComment("TAILCALL");
50     break;
51   }
52 
53   MCInst TmpInst0;
54   MCInstLowering->Lower(MI, TmpInst0);
55   OutStreamer->emitInstruction(TmpInst0, getSubtargetInfo());
56 }
57 
58 void M68kAsmPrinter::emitFunctionBodyStart() {}
59 
60 void M68kAsmPrinter::emitFunctionBodyEnd() {}
61 
62 void M68kAsmPrinter::emitStartOfAsmFile(Module &M) {
63   OutStreamer->emitSyntaxDirective();
64 }
65 
66 void M68kAsmPrinter::emitEndOfAsmFile(Module &M) {}
67 
68 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeM68kAsmPrinter() {
69   RegisterAsmPrinter<M68kAsmPrinter> X(getTheM68kTarget());
70 }
71