Pete Couperus | 2d1f6d6 | 2017-08-24 15:40:33 +0000 | [diff] [blame^] | 1 | //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to GNU format ARC assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "ARC.h" |
| 16 | #include "ARCInstrInfo.h" |
| 17 | #include "ARCMCInstLower.h" |
| 18 | #include "ARCSubtarget.h" |
| 19 | #include "ARCTargetMachine.h" |
| 20 | #include "ARCTargetStreamer.h" |
| 21 | #include "InstPrinter/ARCInstPrinter.h" |
| 22 | #include "llvm/ADT/SmallString.h" |
| 23 | #include "llvm/ADT/StringExtras.h" |
| 24 | #include "llvm/CodeGen/AsmPrinter.h" |
| 25 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 26 | #include "llvm/CodeGen/MachineInstr.h" |
| 27 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 28 | #include "llvm/MC/MCAsmInfo.h" |
| 29 | #include "llvm/MC/MCExpr.h" |
| 30 | #include "llvm/MC/MCInst.h" |
| 31 | #include "llvm/MC/MCStreamer.h" |
| 32 | #include "llvm/MC/MCSymbolELF.h" |
| 33 | #include "llvm/Support/ErrorHandling.h" |
| 34 | #include "llvm/Support/TargetRegistry.h" |
| 35 | #include "llvm/Support/raw_ostream.h" |
| 36 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 37 | #include <algorithm> |
| 38 | |
| 39 | using namespace llvm; |
| 40 | |
| 41 | #define DEBUG_TYPE "asm-printer" |
| 42 | |
| 43 | namespace { |
| 44 | |
| 45 | class ARCAsmPrinter : public AsmPrinter { |
| 46 | ARCMCInstLower MCInstLowering; |
| 47 | ARCTargetStreamer &getTargetStreamer(); |
| 48 | |
| 49 | public: |
| 50 | explicit ARCAsmPrinter(TargetMachine &TM, |
| 51 | std::unique_ptr<MCStreamer> Streamer) |
| 52 | : AsmPrinter(TM, std::move(Streamer)), |
| 53 | MCInstLowering(&OutContext, *this) {} |
| 54 | |
| 55 | StringRef getPassName() const override { return "ARC Assembly Printer"; } |
| 56 | void EmitInstruction(const MachineInstr *MI) override; |
| 57 | }; |
| 58 | |
| 59 | } // end anonymous namespace |
| 60 | |
| 61 | ARCTargetStreamer &ARCAsmPrinter::getTargetStreamer() { |
| 62 | return static_cast<ARCTargetStreamer &>(*OutStreamer->getTargetStreamer()); |
| 63 | } |
| 64 | |
| 65 | void ARCAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
| 66 | SmallString<128> Str; |
| 67 | raw_svector_ostream O(Str); |
| 68 | |
| 69 | switch (MI->getOpcode()) { |
| 70 | case ARC::DBG_VALUE: |
| 71 | llvm_unreachable("Should be handled target independently"); |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | MCInst TmpInst; |
| 76 | MCInstLowering.Lower(MI, TmpInst); |
| 77 | EmitToStreamer(*OutStreamer, TmpInst); |
| 78 | } |
| 79 | |
| 80 | // Force static initialization. |
| 81 | extern "C" void LLVMInitializeARCAsmPrinter() { |
| 82 | RegisterAsmPrinter<ARCAsmPrinter> X(getTheARCTarget()); |
| 83 | } |