LLVM  6.0.0svn
ARCAsmPrinter.cpp
Go to the documentation of this file.
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"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/MC/MCAsmInfo.h"
30 #include "llvm/MC/MCExpr.h"
31 #include "llvm/MC/MCInst.h"
32 #include "llvm/MC/MCStreamer.h"
33 #include "llvm/MC/MCSymbolELF.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;
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() {
83 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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:489
Target & getTheARCTarget()
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:291
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:159
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:77
#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:60
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:57
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49