blob: 025b920ff7b4e0e2f90e0d645542d00f48cf4d32 [file] [log] [blame]
Pete Couperus2d1f6d62017-08-24 15:40:33 +00001//===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Pete Couperus2d1f6d62017-08-24 15:40:33 +00006//
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"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000015#include "ARCMCInstLower.h"
16#include "ARCSubtarget.h"
17#include "ARCTargetMachine.h"
Richard Trieudcf1ea02019-05-11 00:13:01 +000018#include "MCTargetDesc/ARCInstPrinter.h"
Richard Trieu7f9a0082019-05-14 22:06:04 +000019#include "TargetInfo/ARCTargetInfo.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000020#include "llvm/CodeGen/AsmPrinter.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000021#include "llvm/CodeGen/MachineInstr.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000022#include "llvm/MC/MCAsmInfo.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000023#include "llvm/MC/MCInst.h"
24#include "llvm/MC/MCStreamer.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000025#include "llvm/Support/TargetRegistry.h"
26#include "llvm/Support/raw_ostream.h"
Pete Couperus2d1f6d62017-08-24 15:40:33 +000027
28using namespace llvm;
29
30#define DEBUG_TYPE "asm-printer"
31
32namespace {
33
34class ARCAsmPrinter : public AsmPrinter {
35 ARCMCInstLower MCInstLowering;
Pete Couperus2d1f6d62017-08-24 15:40:33 +000036
37public:
38 explicit ARCAsmPrinter(TargetMachine &TM,
39 std::unique_ptr<MCStreamer> Streamer)
40 : AsmPrinter(TM, std::move(Streamer)),
41 MCInstLowering(&OutContext, *this) {}
42
43 StringRef getPassName() const override { return "ARC Assembly Printer"; }
Fangrui Songbcd24b22020-02-13 21:58:16 -080044 void emitInstruction(const MachineInstr *MI) override;
Matt Arsenaultbbd78512020-06-18 09:37:33 -040045
46 bool runOnMachineFunction(MachineFunction &MF) override;
Pete Couperus2d1f6d62017-08-24 15:40:33 +000047};
48
49} // end anonymous namespace
50
Fangrui Songbcd24b22020-02-13 21:58:16 -080051void ARCAsmPrinter::emitInstruction(const MachineInstr *MI) {
Pete Couperus2d1f6d62017-08-24 15:40:33 +000052 SmallString<128> Str;
53 raw_svector_ostream O(Str);
54
55 switch (MI->getOpcode()) {
56 case ARC::DBG_VALUE:
57 llvm_unreachable("Should be handled target independently");
58 break;
59 }
60
61 MCInst TmpInst;
62 MCInstLowering.Lower(MI, TmpInst);
63 EmitToStreamer(*OutStreamer, TmpInst);
64}
65
Matt Arsenaultbbd78512020-06-18 09:37:33 -040066bool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
67 // Functions are 4-byte aligned.
68 MF.ensureAlignment(Align(4));
Guillaume Chatelet597a9072020-06-22 14:56:27 +000069 return AsmPrinter::runOnMachineFunction(MF);
Matt Arsenaultbbd78512020-06-18 09:37:33 -040070}
71
Pete Couperus2d1f6d62017-08-24 15:40:33 +000072// Force static initialization.
Tom Stellard0dbcb362020-01-14 19:15:07 -080073extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter() {
Pete Couperus2d1f6d62017-08-24 15:40:33 +000074 RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget());
75}