Eric Christopher | 6fbb7bb | 2014-03-07 22:43:09 +0000 | [diff] [blame^] | 1 | //===-- llvm/CodeGen/ByteStreamer.h - ByteStreamer class --------*- 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 class that can take bytes that would normally be |
| 11 | // streamed via the AsmPrinter. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CODEGEN_BYTESTREAMER_H |
| 16 | #define LLVM_CODEGEN_BYTESTREAMER_H |
| 17 | |
| 18 | #include "llvm/ADT/ArrayRef.h" |
| 19 | #include "llvm/CodeGen/AsmPrinter.h" |
| 20 | #include "llvm/MC/MCStreamer.h" |
| 21 | #include "DIEHash.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | class ByteStreamer { |
| 25 | public: |
| 26 | // For now we're just handling the calls we need for dwarf emission/hashing. |
| 27 | virtual void EmitInt8(uint8_t Byte, const Twine &Comment = "") = 0; |
| 28 | virtual void EmitSLEB128(uint64_t DWord, const Twine &Comment = "") = 0; |
| 29 | virtual void EmitULEB128(uint64_t DWord, const Twine &Comment = "") = 0; |
| 30 | }; |
| 31 | |
| 32 | class APByteStreamer : public ByteStreamer { |
| 33 | private: |
| 34 | AsmPrinter ≈ |
| 35 | |
| 36 | public: |
| 37 | APByteStreamer(AsmPrinter &Asm) : AP(Asm) {} |
| 38 | void EmitInt8(uint8_t Byte, const Twine &Comment) { |
| 39 | AP.OutStreamer.AddComment(Comment); |
| 40 | AP.EmitInt8(Byte); |
| 41 | } |
| 42 | void EmitSLEB128(uint64_t DWord, const Twine &Comment) { |
| 43 | AP.OutStreamer.AddComment(Comment); |
| 44 | AP.EmitSLEB128(DWord); |
| 45 | } |
| 46 | void EmitULEB128(uint64_t DWord, const Twine &Comment) { |
| 47 | AP.OutStreamer.AddComment(Comment); |
| 48 | AP.EmitULEB128(DWord); |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | class HashingByteStreamer : public ByteStreamer { |
| 53 | private: |
| 54 | DIEHash &Hash; |
| 55 | public: |
| 56 | HashingByteStreamer(DIEHash &H) : Hash(H) {} |
| 57 | void EmitInt8(uint8_t Byte, const Twine &Comment) { |
| 58 | Hash.update(Byte); |
| 59 | } |
| 60 | void EmitSLEB128(uint64_t DWord, const Twine &Comment) { |
| 61 | Hash.addSLEB128(DWord); |
| 62 | } |
| 63 | void EmitULEB128(uint64_t DWord, const Twine &Comment) { |
| 64 | Hash.addULEB128(DWord); |
| 65 | } |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | #endif |