blob: 81b92e41458d7eaf8f186cadc75e2db33480b2fe [file] [log] [blame]
Eric Christopher6fbb7bb2014-03-07 22:43:09 +00001//===-- 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
23namespace llvm {
24class 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
32class APByteStreamer : public ByteStreamer {
33private:
34 AsmPrinter ≈
35
36public:
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
52class 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