1 //===-- BPFAsmPrinter.cpp - BPF LLVM assembly writer ----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to the BPF assembly language.
13 //===----------------------------------------------------------------------===//
16 #include "BPFInstrInfo.h"
17 #include "BPFMCInstLower.h"
18 #include "BPFTargetMachine.h"
19 #include "InstPrinter/BPFInstPrinter.h"
20 #include "llvm/CodeGen/AsmPrinter.h"
21 #include "llvm/CodeGen/MachineConstantPool.h"
22 #include "llvm/CodeGen/MachineFunctionPass.h"
23 #include "llvm/CodeGen/MachineInstr.h"
24 #include "llvm/CodeGen/MachineModuleInfo.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCInst.h"
27 #include "llvm/MC/MCStreamer.h"
28 #include "llvm/MC/MCSymbol.h"
29 #include "llvm/Support/TargetRegistry.h"
30 #include "llvm/Support/raw_ostream.h"
33 #define DEBUG_TYPE "asm-printer"
36 class BPFAsmPrinter : public AsmPrinter {
38 explicit BPFAsmPrinter(TargetMachine &TM,
39 std::unique_ptr<MCStreamer> Streamer)
40 : AsmPrinter(TM, std::move(Streamer)) {}
42 StringRef getPassName() const override { return "BPF Assembly Printer"; }
44 void EmitInstruction(const MachineInstr *MI) override;
48 void BPFAsmPrinter::EmitInstruction(const MachineInstr *MI) {
50 BPFMCInstLower MCInstLowering(OutContext, *this);
53 MCInstLowering.Lower(MI, TmpInst);
54 EmitToStreamer(*OutStreamer, TmpInst);
57 // Force static initialization.
58 extern "C" void LLVMInitializeBPFAsmPrinter() {
59 RegisterAsmPrinter<BPFAsmPrinter> X(getTheBPFleTarget());
60 RegisterAsmPrinter<BPFAsmPrinter> Y(getTheBPFbeTarget());
61 RegisterAsmPrinter<BPFAsmPrinter> Z(getTheBPFTarget());