Adding copyright notices to most files. Also add readme file, and some
[jitcs.git] / include / jitcs_dumper.h
blobc8a9d26e48521c1a4c108d6f824eb24ea198d5f6
1 //===-- jitcs_dumper.h ------------------------------------------*- C++ -*-===//
2 // Helper for printing information for debug purposes.
3 //
4 // Copyright (C) 2013-2014 Dirk Steinke.
5 // See copyright and license notice in COPYRIGHT or include/jitcs.h
6 //
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
11 // debug purposes.
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"
21 #include <memory>
22 #include <stdarg.h>
24 namespace jitcs {
25 struct Instruction;
26 struct MemoryReference;
27 struct VirtualRegister;
28 class IMachineInfo;
30 class IDumper {
31 protected:
32 IDumper() = default;
33 private:
34 IDumper(const IDumper&) = delete;
35 IDumper& operator =(const IDumper&) = delete;
36 public:
37 void write(const char*);
38 void writef(const char*, ...);
39 virtual void writev(const char*, va_list) = 0;
41 class PrintFDumper : public IDumper {
42 public:
43 PrintFDumper() = default;
44 private:
45 PrintFDumper(const PrintFDumper&) = delete;
46 PrintFDumper& operator =(const PrintFDumper&) = delete;
47 public:
48 /*[[override]]*/ virtual void writev(const char*, va_list);
50 class StringDumper : public IDumper {
51 public:
52 StringDumper() = default;
53 private:
54 StringDumper(const StringDumper&) = delete;
55 StringDumper& operator =(const StringDumper&) = delete;
56 public:
57 /*[[override]]*/ virtual void writev(const char*, va_list);
58 public:
59 std::string takeResult();
60 private:
61 std::string _accumulator;
64 class IMachineDumper {
65 public:
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 {
75 public:
76 MachineDumper(IDumper&, const IMachineInfo&);
77 private:
78 MachineDumper() = delete;
79 MachineDumper(const MachineDumper&) = delete;
80 MachineDumper& operator =(const MachineDumper&) = delete;
81 public:
82 using IDumper::write;
83 void write(Ref<const Instruction>);
84 void write(Ref<const VirtualRegister>);
86 void write(InsId);
88 /*[[override]]*/ virtual void writev(const char*, va_list);
89 private:
90 IDumper& _out;
91 std::unique_ptr<IMachineDumper> _md;
94 } // end namespace jitcs
96 #endif
97 // _JITCS_DUMPER_H_