Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 1 | //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 6 | // |
| 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 Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 15 | #include "ARCMCInstLower.h" |
| 16 | #include "ARCSubtarget.h" |
| 17 | #include "ARCTargetMachine.h" |
Richard Trieu | dcf1ea0 | 2019-05-11 00:13:01 +0000 | [diff] [blame] | 18 | #include "MCTargetDesc/ARCInstPrinter.h" |
Richard Trieu | 7f9a008 | 2019-05-14 22:06:04 +0000 | [diff] [blame] | 19 | #include "TargetInfo/ARCTargetInfo.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/AsmPrinter.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineInstr.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCAsmInfo.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCInst.h" |
| 24 | #include "llvm/MC/MCStreamer.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 25 | #include "llvm/Support/TargetRegistry.h" |
| 26 | #include "llvm/Support/raw_ostream.h" |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace llvm; |
| 29 | |
| 30 | #define DEBUG_TYPE "asm-printer" |
| 31 | |
| 32 | namespace { |
| 33 | |
| 34 | class ARCAsmPrinter : public AsmPrinter { |
| 35 | ARCMCInstLower MCInstLowering; |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 36 | |
| 37 | public: |
| 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 Song | bcd24b2 | 2020-02-13 21:58:16 -0800 | [diff] [blame] | 44 | void emitInstruction(const MachineInstr *MI) override; |
Matt Arsenault | bbd7851 | 2020-06-18 09:37:33 -0400 | [diff] [blame] | 45 | |
| 46 | bool runOnMachineFunction(MachineFunction &MF) override; |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | } // end anonymous namespace |
| 50 | |
Fangrui Song | bcd24b2 | 2020-02-13 21:58:16 -0800 | [diff] [blame] | 51 | void ARCAsmPrinter::emitInstruction(const MachineInstr *MI) { |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 52 | 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 Arsenault | bbd7851 | 2020-06-18 09:37:33 -0400 | [diff] [blame] | 66 | bool ARCAsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 67 | // Functions are 4-byte aligned. |
| 68 | MF.ensureAlignment(Align(4)); |
Guillaume Chatelet | 597a907 | 2020-06-22 14:56:27 +0000 | [diff] [blame] | 69 | return AsmPrinter::runOnMachineFunction(MF); |
Matt Arsenault | bbd7851 | 2020-06-18 09:37:33 -0400 | [diff] [blame] | 70 | } |
| 71 | |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 72 | // Force static initialization. |
Tom Stellard | 0dbcb36 | 2020-01-14 19:15:07 -0800 | [diff] [blame] | 73 | extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARCAsmPrinter() { |
Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame] | 74 | RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget()); |
| 75 | } |