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