LLVM API Documentation

ByteStreamer.h
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/ByteStreamer.h - ByteStreamer class --------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains a class that can take bytes that would normally be
00011 // streamed via the AsmPrinter.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
00016 #define LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
00017 
00018 #include "llvm/ADT/ArrayRef.h"
00019 #include "llvm/CodeGen/AsmPrinter.h"
00020 #include "llvm/MC/MCStreamer.h"
00021 #include "DIEHash.h"
00022 
00023 namespace llvm {
00024 class ByteStreamer {
00025  public:
00026   virtual ~ByteStreamer() {}
00027 
00028   // For now we're just handling the calls we need for dwarf emission/hashing.
00029   virtual void EmitInt8(uint8_t Byte, const Twine &Comment = "") = 0;
00030   virtual void EmitSLEB128(uint64_t DWord, const Twine &Comment = "") = 0;
00031   virtual void EmitULEB128(uint64_t DWord, const Twine &Comment = "") = 0;
00032 };
00033 
00034 class APByteStreamer : public ByteStreamer {
00035 private:
00036   AsmPrinter ≈
00037 
00038 public:
00039   APByteStreamer(AsmPrinter &Asm) : AP(Asm) {}
00040   void EmitInt8(uint8_t Byte, const Twine &Comment) override {
00041     AP.OutStreamer.AddComment(Comment);
00042     AP.EmitInt8(Byte);
00043   }
00044   void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
00045     AP.OutStreamer.AddComment(Comment);
00046     AP.EmitSLEB128(DWord);
00047   }
00048   void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
00049     AP.OutStreamer.AddComment(Comment);
00050     AP.EmitULEB128(DWord);
00051   }
00052 };
00053 
00054 class HashingByteStreamer : public ByteStreamer {
00055  private:
00056   DIEHash &Hash;
00057  public:
00058  HashingByteStreamer(DIEHash &H) : Hash(H) {}
00059   void EmitInt8(uint8_t Byte, const Twine &Comment) override {
00060     Hash.update(Byte);
00061   }
00062   void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
00063     Hash.addSLEB128(DWord);
00064   }
00065   void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
00066     Hash.addULEB128(DWord);
00067   }
00068 };
00069 }
00070 
00071 #endif