xref: /aosp_15_r20/external/stg/stg.proto (revision 9e3b08ae94a55201065475453d799e8b1378bea6)
1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2// -*- mode: protobuffer -*-
3//
4// Copyright 2022-2024 Google LLC
5//
6// Licensed under the Apache License v2.0 with LLVM Exceptions (the
7// "License"); you may not use this file except in compliance with the
8// License.  You may obtain a copy of the License at
9//
10//     https://llvm.org/LICENSE.txt
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18// Author: Siddharth Nayyar
19//
20// Protobuf definitions representing the graph and nodes defined in graph.h.
21//
22// The protobuf representations approximately mirror the internal STG
23// representataion. Keeping the representations as close as possible helps keep
24// the serialisation and deserialisation logic simple. Nevertheless, there are
25// some differences between the two representation, which are as follows:
26//
27// * The protobuf graph has repeated fields for each node type rather than a
28//   repeated field of one offs of all node types.
29// * The external ids are 32-bit integers. We use fixed32 type to represent the
30//   ids which is better than using a variable integer type in terms of both
31//   space and time. The ids are generated using 32-bit hashes of local
32//   information of nodes.
33// * All enumerations have a default UNKNOWN value to avoid defaulting to
34//   concrete enumeration values when those values are missing.
35// * Self ids of nodes have been made a part of the node itself (as the first
36//   member) for all node types. This is to improve succinctness of textual
37//   representation of the protobuf.
38// * The binary protobuf definitions have no stability guarantee and exist
39//   solely to support the associated textual format.
40
41syntax = "proto3";
42
43package stg.proto;
44
45// deprecated
46message Void {
47  fixed32 id = 1;
48}
49
50// deprecated
51message Variadic {
52  fixed32 id = 1;
53}
54
55message Special {
56  enum Kind {
57    KIND_UNSPECIFIED = 0;
58    VOID = 1;
59    VARIADIC = 2;
60    NULLPTR = 3;
61  }
62
63  fixed32 id = 1;
64  Kind kind = 2;
65}
66
67message PointerReference {
68  enum Kind {
69    KIND_UNSPECIFIED = 0;
70    POINTER = 1;
71    LVALUE_REFERENCE = 2;
72    RVALUE_REFERENCE = 3;
73  }
74
75  fixed32 id = 1;
76  Kind kind = 2;
77  fixed32 pointee_type_id = 3;
78}
79
80message PointerToMember {
81  fixed32 id = 1;
82  fixed32 containing_type_id = 2;
83  fixed32 pointee_type_id = 3;
84}
85
86message Typedef {
87  fixed32 id = 1;
88  string name = 2;
89  fixed32 referred_type_id = 3;
90}
91
92message Qualified {
93  enum Qualifier {
94    QUALIFIER_UNSPECIFIED = 0;
95    CONST = 1;
96    VOLATILE = 2;
97    RESTRICT = 3;
98    ATOMIC = 4;
99  }
100
101  fixed32 id = 1;
102  Qualifier qualifier = 2;
103  fixed32 qualified_type_id = 3;
104}
105
106message Primitive {
107  enum Encoding {
108    ENCODING_UNSPECIFIED = 0;
109    NONE = 1;
110    BOOLEAN = 2;
111    SIGNED_INTEGER = 3;
112    UNSIGNED_INTEGER = 4;
113    SIGNED_CHARACTER = 5;
114    UNSIGNED_CHARACTER = 6;
115    REAL_NUMBER = 7;
116    COMPLEX_NUMBER = 8;
117    UTF = 9;
118  }
119
120  fixed32 id = 1;
121  string name = 2;
122  optional Encoding encoding = 3;
123  uint32 bytesize = 4;
124}
125
126message Array {
127  fixed32 id = 1;
128  uint64 number_of_elements = 2;
129  fixed32 element_type_id = 3;
130}
131
132message BaseClass {
133  enum Inheritance {
134    INHERITANCE_UNSPECIFIED = 0;
135    NON_VIRTUAL = 1;
136    VIRTUAL = 2;
137  }
138
139  fixed32 id = 1;
140  fixed32 type_id = 2;
141  uint64 offset = 3;
142  Inheritance inheritance = 4;
143}
144
145message Method {
146  fixed32 id = 1;
147  string mangled_name = 2;
148  string name = 3;
149  uint64 vtable_offset = 4;
150  fixed32 type_id = 5;
151}
152
153message Member {
154  fixed32 id = 1;
155  string name = 2;
156  fixed32 type_id = 3;
157  uint64 offset = 4;
158  uint64 bitsize = 5;
159}
160
161message VariantMember {
162  fixed32 id = 1;
163  string name = 2;
164  optional int64 discriminant_value = 3;
165  fixed32 type_id = 4;
166}
167
168message StructUnion {
169  enum Kind {
170    KIND_UNSPECIFIED = 0;
171    STRUCT = 1;
172    UNION = 2;
173  }
174
175  message Definition {
176    uint64 bytesize = 1;
177    repeated fixed32 base_class_id = 2;
178    repeated fixed32 method_id = 3;
179    repeated fixed32 member_id = 4;
180  }
181
182  fixed32 id = 1;
183  Kind kind = 2;
184  string name = 3;
185  optional Definition definition = 4;
186}
187
188message Enumeration {
189  message Enumerator {
190    string name = 1;
191    int64 value = 2;
192  }
193
194  message Definition {
195    fixed32 underlying_type_id = 1;
196    repeated Enumerator enumerator = 2;
197  }
198
199  fixed32 id = 1;
200  string name = 2;
201  optional Definition definition = 3;
202}
203
204message Variant {
205  fixed32 id = 1;
206  string name = 2;
207  uint64 bytesize = 3;
208  optional fixed32 discriminant = 4;
209  repeated fixed32 member_id = 5;
210}
211
212message Function {
213  fixed32 id = 1;
214  fixed32 return_type_id = 2;
215  repeated fixed32 parameter_id = 3;
216}
217
218message ElfSymbol {
219  message VersionInfo {
220    bool is_default = 1;
221    string name = 2;
222  }
223
224  enum SymbolType {
225    SYMBOL_TYPE_UNSPECIFIED = 0;
226    NOTYPE = 1;
227    OBJECT = 2;
228    FUNCTION = 3;
229    COMMON = 4;
230    TLS = 5;
231    GNU_IFUNC = 6;
232  }
233
234  enum Binding {
235    GLOBAL = 0;  // Default while reading, omitted while writing.
236    LOCAL = 1;
237    WEAK = 2;
238    GNU_UNIQUE = 3;
239  }
240
241  enum Visibility {
242    DEFAULT = 0;  // Default while reading, omitted while writing.
243    PROTECTED = 1;
244    HIDDEN = 2;
245    INTERNAL = 3;
246  }
247
248  fixed32 id = 1;
249  string name = 2;
250  optional VersionInfo version_info = 3;
251  bool is_defined = 4;
252  SymbolType symbol_type = 5;
253  Binding binding = 6;
254  Visibility visibility = 7;
255  optional fixed32 crc = 8;
256  optional string namespace = 9;
257  optional fixed32 type_id = 10;
258  optional string full_name = 11;
259}
260
261message Symbols {
262  fixed32 id = 1;
263  map<string, fixed32> symbol = 2;
264}
265
266message Interface {
267  fixed32 id = 1;
268  repeated fixed32 symbol_id = 2;
269  repeated fixed32 type_id = 3;
270}
271
272message STG {
273  uint32 version = 1;
274  fixed32 root_id = 2;
275  repeated Void void = 3;
276  repeated Variadic variadic = 4;
277  repeated Special special = 5;
278  repeated PointerReference pointer_reference = 6;
279  repeated PointerToMember pointer_to_member = 7;
280  repeated Typedef typedef = 8;
281  repeated Qualified qualified = 9;
282  repeated Primitive primitive = 10;
283  repeated Array array = 11;
284  repeated BaseClass base_class = 12;
285  repeated Method method = 13;
286  repeated Member member = 14;
287  repeated VariantMember variant_member = 15;
288  repeated StructUnion struct_union = 16;
289  repeated Enumeration enumeration = 17;
290  repeated Variant variant = 18;
291  repeated Function function = 19;
292  repeated ElfSymbol elf_symbol = 20;
293  repeated Symbols symbols = 21;
294  repeated Interface interface = 22;
295}
296