1 //===-- jitcs_dumper.h ------------------------------------------*- C++ -*-===//
2 // Helper for printing information for debug purposes.
4 // Copyright (C) 2013-2014 Dirk Steinke.
5 // See copyright and license notice in COPYRIGHT or include/jitcs.h
7 // A lot of classes of JITCS accept an IDumper interface for writing
8 // information, which e.g. PrintFDumper implements. MachineDumper dumper
9 // provides target specific dumping support. Using it will pull in some big
10 // data tables into the application, so it should be avoided except for
12 //===----------------------------------------------------------------------===//
14 #ifndef _JITCS_DUMPER_H_
15 #define _JITCS_DUMPER_H_
17 #include "jitcs_adt_ref.h"
18 #include "jitcs_adt_refcounter.h"
19 #include "jitcs_base.h"
20 #include "jitcs_ids.h"
26 struct MemoryReference
;
27 struct VirtualRegister
;
34 IDumper(const IDumper
&) = delete;
35 IDumper
& operator =(const IDumper
&) = delete;
37 void write(const char*);
38 void writef(const char*, ...);
39 virtual void writev(const char*, va_list) = 0;
41 class PrintFDumper
: public IDumper
{
43 PrintFDumper() = default;
45 PrintFDumper(const PrintFDumper
&) = delete;
46 PrintFDumper
& operator =(const PrintFDumper
&) = delete;
48 /*[[override]]*/ virtual void writev(const char*, va_list);
50 class StringDumper
: public IDumper
{
52 StringDumper() = default;
54 StringDumper(const StringDumper
&) = delete;
55 StringDumper
& operator =(const StringDumper
&) = delete;
57 /*[[override]]*/ virtual void writev(const char*, va_list);
59 std::string
takeResult();
61 std::string _accumulator
;
64 class IMachineDumper
{
66 virtual void write(IDumper
&, Ref
<const Instruction
>) const;
67 virtual void write(IDumper
&, Ref
<const VirtualRegister
>) const;
69 virtual void write(IDumper
&, InsId
) const;
71 void write(IDumper
&, Ref
<const MemoryReference
>, bool vsib
) const;
74 class MachineDumper
: public IDumper
{
76 MachineDumper(IDumper
&, const IMachineInfo
&);
78 MachineDumper() = delete;
79 MachineDumper(const MachineDumper
&) = delete;
80 MachineDumper
& operator =(const MachineDumper
&) = delete;
83 void write(Ref
<const Instruction
>);
84 void write(Ref
<const VirtualRegister
>);
88 /*[[override]]*/ virtual void writev(const char*, va_list);
91 std::unique_ptr
<IMachineDumper
> _md
;
94 } // end namespace jitcs