1
2
3
4
5
6 #ifndef CMAJOR_CMSXI_METADATA_INCLUDED
7 #define CMAJOR_CMSXI_METADATA_INCLUDED
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
11 #include <soulng/util/CodeFormatter.hpp>
12
13 namespace cmsxi {
14
15 using namespace soulng::util;
16
17 enum class MDItemKind : uint8_t
18 {
19 bool_= 0u, long_= 1u, string= 2u, structRef= 3u, struct_= 4u, basicBlockRef= 5u
20 };
21
22 const int64_t fileInfoNodeType = 0;
23 const int64_t funcInfoNodeType = 1;
24 const int64_t lineInfoNodeType = 2;
25 const int64_t beginTryNodeType = 3;
26 const int64_t endTryNodeType = 4;
27 const int64_t catchNodeType = 5;
28 const int64_t beginCleanupNodeType = 6;
29 const int64_t endCleanupNodeType = 7;
30
31 class MDItem
32 {
33 public:
34 MDItem(MDItemKind kind_);
35 virtual ~MDItem();
36 MDItemKind Kind() const { return kind; }
37 virtual void Write(CodeFormatter& formatter) = 0;
38 private:
39 MDItemKind kind;
40 };
41
42 class MDBool : public MDItem
43 {
44 public:
45 MDBool(bool value_);
46 void Write(CodeFormatter& formatter) override;
47 private:
48 bool value;
49 };
50
51 class MDLong : public MDItem
52 {
53 public:
54 MDLong(int64_t value_);
55 void Write(CodeFormatter& formatter) override;
56 private:
57 int64_t value;
58 };
59
60 class MDString : public MDItem
61 {
62 public:
63 MDString(const std::string& value_);
64 void Write(CodeFormatter& formatter) override;
65 private:
66 std::string value;
67 };
68
69 class MDStructRef : public MDItem
70 {
71 public:
72 MDStructRef(int id_);
73 void Write(CodeFormatter& formatter) override;
74 private:
75 int id;
76 };
77
78 class MDStruct : public MDItem
79 {
80 public:
81 MDStruct(int id_);
82 void Write(CodeFormatter& formatter) override;
83 void WriteDefinition(CodeFormatter& formatter);
84 void AddItem(const std::string& fieldName, MDItem* item);
85 int Id() const { return id; }
86 private:
87 int id;
88 std::vector<std::std::pair<std::string, MDItem*>>items;
89 };
90
91 class MDBasicBlockRef : public MDItem
92 {
93 public:
94 MDBasicBlockRef(void* bb_);
95 void Write(CodeFormatter& formatter) override;
96 private:
97 void* bb;
98 };
99
100 class Metadata
101 {
102 public:
103 Metadata();
104 Metadata(const Metadata&) = delete;
105 Metadata& operator=(const Metadata&) = delete;
106 MDBool* CreateMDBool(bool value);
107 MDLong* CreateMDLong(int64_t value);
108 MDString* CreateMDString(const std::string& value);
109 MDStructRef* CreateMDStructRef(int id);
110 MDStruct* CreateMDStruct();
111 MDBasicBlockRef* CreateMDBasicBlockRef(void* bb);
112 void Write(CodeFormatter& formatter);
113 private:
114 void AddItem(MDItem* item);
115 std::vector<std::std::unique_ptr<MDItem>>items;
116 std::vector<std::std::unique_ptr<MDStruct>>structs;
117 MDBool mdTrue;
118 MDBool mdFalse;
119 };
120
121 }
122
123 #endif // CMAJOR_CMSXI_METADATA_INCLUDED