blob: 42be1149e97384ccba4264db876d01698b337699 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
16#define LLVM_LIB_CODEGEN_ASMPRINTER_BYTESTREAMER_H
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000017
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "DIEHash.h"
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000019#include "llvm/ADT/ArrayRef.h"
20#include "llvm/CodeGen/AsmPrinter.h"
21#include "llvm/MC/MCStreamer.h"
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000022
23namespace llvm {
24class ByteStreamer {
25 public:
Eric Christopher1d6d1c82014-03-07 22:53:36 +000026 virtual ~ByteStreamer() {}
27
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000028 // 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
34class APByteStreamer : public ByteStreamer {
35private:
36 AsmPrinter ≈
37
38public:
39 APByteStreamer(AsmPrinter &Asm) : AP(Asm) {}
Craig Topper7b883b32014-03-08 06:31:39 +000040 void EmitInt8(uint8_t Byte, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000041 AP.OutStreamer.AddComment(Comment);
42 AP.EmitInt8(Byte);
43 }
Craig Topper7b883b32014-03-08 06:31:39 +000044 void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000045 AP.OutStreamer.AddComment(Comment);
46 AP.EmitSLEB128(DWord);
47 }
Craig Topper7b883b32014-03-08 06:31:39 +000048 void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000049 AP.OutStreamer.AddComment(Comment);
50 AP.EmitULEB128(DWord);
51 }
52};
53
54class HashingByteStreamer : public ByteStreamer {
55 private:
56 DIEHash &Hash;
57 public:
58 HashingByteStreamer(DIEHash &H) : Hash(H) {}
Craig Topper7b883b32014-03-08 06:31:39 +000059 void EmitInt8(uint8_t Byte, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000060 Hash.update(Byte);
61 }
Craig Topper7b883b32014-03-08 06:31:39 +000062 void EmitSLEB128(uint64_t DWord, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000063 Hash.addSLEB128(DWord);
64 }
Craig Topper7b883b32014-03-08 06:31:39 +000065 void EmitULEB128(uint64_t DWord, const Twine &Comment) override {
Eric Christopher6fbb7bb2014-03-07 22:43:09 +000066 Hash.addULEB128(DWord);
67 }
68};
69}
70
71#endif