LLVM  9.0.0svn
ARCAsmPrinter.cpp
Go to the documentation of this file.
1 //===- ARCAsmPrinter.cpp - ARC LLVM assembly writer -------------*- 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 // 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"
15 #include "ARCInstrInfo.h"
16 #include "ARCMCInstLower.h"
17 #include "ARCSubtarget.h"
18 #include "ARCTargetMachine.h"
19 #include "ARCTargetStreamer.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/StringExtras.h"
27 #include "llvm/MC/MCAsmInfo.h"
28 #include "llvm/MC/MCExpr.h"
29 #include "llvm/MC/MCInst.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbolELF.h"
36 #include <algorithm>
37 
38 using namespace llvm;
39 
40 #define DEBUG_TYPE "asm-printer"
41 
42 namespace {
43 
44 class ARCAsmPrinter : public AsmPrinter {
45  ARCMCInstLower MCInstLowering;
46  ARCTargetStreamer &getTargetStreamer();
47 
48 public:
49  explicit ARCAsmPrinter(TargetMachine &TM,
50  std::unique_ptr<MCStreamer> Streamer)
51  : AsmPrinter(TM, std::move(Streamer)),
52  MCInstLowering(&OutContext, *this) {}
53 
54  StringRef getPassName() const override { return "ARC Assembly Printer"; }
55  void EmitInstruction(const MachineInstr *MI) override;
56 };
57 
58 } // end anonymous namespace
59 
60 ARCTargetStreamer &ARCAsmPrinter::getTargetStreamer() {
61  return static_cast<ARCTargetStreamer &>(*OutStreamer->getTargetStreamer());
62 }
63 
64 void ARCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
65  SmallString<128> Str;
67 
68  switch (MI->getOpcode()) {
69  case ARC::DBG_VALUE:
70  llvm_unreachable("Should be handled target independently");
71  break;
72  }
73 
74  MCInst TmpInst;
75  MCInstLowering.Lower(MI, TmpInst);
76  EmitToStreamer(*OutStreamer, TmpInst);
77 }
78 
79 // Force static initialization.
80 extern "C" void LLVMInitializeARCAsmPrinter() {
82 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This class represents lattice values for constants.
Definition: AllocatorList.h:23
This class is used to lower an MachineInstr into an MCInst.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:509
Target & getTheARCTarget()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:408
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
This file contains the declaration of the ARCInstPrinter class, which is used to print ARC MCInst to ...
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void LLVMInitializeARCAsmPrinter()
Representation of each machine instruction.
Definition: MachineInstr.h:63
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:58
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48