1 //===-- BPFAsmPrinter.cpp - BPF LLVM assembly writer ----------------------===// 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 the BPF assembly language. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "BPF.h" 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/MachineModuleInfo.h" 22 #include "llvm/CodeGen/MachineFunctionPass.h" 23 #include "llvm/CodeGen/MachineConstantPool.h" 24 #include "llvm/CodeGen/MachineInstr.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" 31 using namespace llvm; 32 33 #define DEBUG_TYPE "asm-printer" 34 35 namespace { 36 class BPFAsmPrinter : public AsmPrinter { 37 public: BPFAsmPrinter(TargetMachine & TM,std::unique_ptr<MCStreamer> Streamer)38 explicit BPFAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer) 39 : AsmPrinter(TM, std::move(Streamer)) {} 40 getPassName() const41 const char *getPassName() const override { return "BPF Assembly Printer"; } 42 43 void EmitInstruction(const MachineInstr *MI) override; 44 }; 45 } 46 EmitInstruction(const MachineInstr * MI)47void BPFAsmPrinter::EmitInstruction(const MachineInstr *MI) { 48 49 BPFMCInstLower MCInstLowering(OutContext, *this); 50 51 MCInst TmpInst; 52 MCInstLowering.Lower(MI, TmpInst); 53 EmitToStreamer(*OutStreamer, TmpInst); 54 } 55 56 // Force static initialization. LLVMInitializeBPFAsmPrinter()57extern "C" void LLVMInitializeBPFAsmPrinter() { 58 RegisterAsmPrinter<BPFAsmPrinter> X(TheBPFleTarget); 59 RegisterAsmPrinter<BPFAsmPrinter> Y(TheBPFbeTarget); 60 RegisterAsmPrinter<BPFAsmPrinter> Z(TheBPFTarget); 61 } 62