re PR go/78789 (Error: no such instruction: `aesenc %xmm0,%xmm2' when compiling libgo...
[gcc.git] / libgo / runtime / go-type.h
1 /* go-type.h -- basic information for a Go type.
2
3 Copyright 2009 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
6
7 #ifndef LIBGO_GO_TYPE_H
8 #define LIBGO_GO_TYPE_H
9
10 #include <stddef.h>
11 #include <stdint.h>
12
13 #include "array.h"
14
15 struct String;
16
17 /* Many of the types in this file must match the data structures
18 generated by the compiler, and must also match the Go types which
19 appear in go/runtime/type.go and go/reflect/type.go. */
20
21 /* Type kinds. These are used to get the type descriptor to use for
22 the type itself, when using unsafe.Typeof or unsafe.Reflect. The
23 values here must match the values generated by the compiler (the
24 RUNTIME_TYPE_KIND_xxx values in gcc/go/types.h). These are macros
25 rather than an enum to make it easy to change values in the future
26 and hard to get confused about it.
27
28 These correspond to the kind values used by the gc compiler. */
29
30 #define GO_BOOL 1
31 #define GO_INT 2
32 #define GO_INT8 3
33 #define GO_INT16 4
34 #define GO_INT32 5
35 #define GO_INT64 6
36 #define GO_UINT 7
37 #define GO_UINT8 8
38 #define GO_UINT16 9
39 #define GO_UINT32 10
40 #define GO_UINT64 11
41 #define GO_UINTPTR 12
42 #define GO_FLOAT32 13
43 #define GO_FLOAT64 14
44 #define GO_COMPLEX64 15
45 #define GO_COMPLEX128 16
46 #define GO_ARRAY 17
47 #define GO_CHAN 18
48 #define GO_FUNC 19
49 #define GO_INTERFACE 20
50 #define GO_MAP 21
51 #define GO_PTR 22
52 #define GO_SLICE 23
53 #define GO_STRING 24
54 #define GO_STRUCT 25
55 #define GO_UNSAFE_POINTER 26
56
57 #define GO_DIRECT_IFACE (1 << 5)
58 #define GO_GC_PROG (1 << 6)
59 #define GO_NO_POINTERS (1 << 7)
60
61 #define GO_CODE_MASK 0x1f
62
63 /* For each Go type the compiler constructs one of these structures.
64 This is used for type reflection, interfaces, maps, and reference
65 counting. */
66
67 struct __go_type_descriptor
68 {
69 /* The type code for this type, one of the type kind values above.
70 This is used by unsafe.Reflect and unsafe.Typeof to determine the
71 type descriptor to return for this type itself. It is also used
72 by reflect.toType when mapping to a reflect Type structure. */
73 unsigned char __code;
74
75 /* The alignment in bytes of a variable with this type. */
76 unsigned char __align;
77
78 /* The alignment in bytes of a struct field with this type. */
79 unsigned char __field_align;
80
81 /* The size in bytes of a value of this type. Note that all types
82 in Go have a fixed size. */
83 uintptr_t __size;
84
85 /* The type's hash code. */
86 uint32_t __hash;
87
88 /* This function takes a pointer to a value of this type, and the
89 size of this type, and returns a hash code. We pass the size
90 explicitly becaues it means that we can share a single instance
91 of this function for various different types. */
92 const FuncVal *__hashfn;
93
94 /* This function takes two pointers to values of this type, and the
95 size of this type, and returns whether the values are equal. */
96 const FuncVal *__equalfn;
97
98 /* The garbage collection data. */
99 const uintptr *__gc;
100
101 /* A string describing this type. This is only used for
102 debugging. */
103 const struct String *__reflection;
104
105 /* A pointer to fields which are only used for some types. */
106 const struct __go_uncommon_type *__uncommon;
107
108 /* The descriptor for the type which is a pointer to this type.
109 This may be NULL. */
110 const struct __go_type_descriptor *__pointer_to_this;
111 };
112
113 /* The information we store for each method of a type. */
114
115 struct __go_method
116 {
117 /* The name of the method. */
118 const struct String *__name;
119
120 /* This is NULL for an exported method, or the name of the package
121 where it lives. */
122 const struct String *__pkg_path;
123
124 /* The type of the method, without the receiver. This will be a
125 function type. */
126 const struct __go_type_descriptor *__mtype;
127
128 /* The type of the method, with the receiver. This will be a
129 function type. */
130 const struct __go_type_descriptor *__type;
131
132 /* A pointer to the code which implements the method. This is
133 really a function pointer. */
134 const void *__function;
135 };
136
137 /* Additional information that we keep for named types and for types
138 with methods. */
139
140 struct __go_uncommon_type
141 {
142 /* The name of the type. */
143 const struct String *__name;
144
145 /* The type's package. This is NULL for builtin types. */
146 const struct String *__pkg_path;
147
148 /* The type's methods. This is an array of struct __go_method. */
149 struct __go_open_array __methods;
150 };
151
152 /* The type descriptor for a fixed array type. */
153
154 struct __go_array_type
155 {
156 /* Starts like all type descriptors. */
157 struct __go_type_descriptor __common;
158
159 /* The element type. */
160 struct __go_type_descriptor *__element_type;
161
162 /* The type of a slice of the same element type. */
163 struct __go_type_descriptor *__slice_type;
164
165 /* The length of the array. */
166 uintptr_t __len;
167 };
168
169 /* The type descriptor for a slice. */
170
171 struct __go_slice_type
172 {
173 /* Starts like all other type descriptors. */
174 struct __go_type_descriptor __common;
175
176 /* The element type. */
177 struct __go_type_descriptor *__element_type;
178 };
179
180 /* The direction of a channel. */
181 #define CHANNEL_RECV_DIR 1
182 #define CHANNEL_SEND_DIR 2
183 #define CHANNEL_BOTH_DIR (CHANNEL_RECV_DIR | CHANNEL_SEND_DIR)
184
185 /* The type descriptor for a channel. */
186
187 struct __go_channel_type
188 {
189 /* Starts like all other type descriptors. */
190 struct __go_type_descriptor __common;
191
192 /* The element type. */
193 const struct __go_type_descriptor *__element_type;
194
195 /* The direction. */
196 uintptr_t __dir;
197 };
198
199 /* The type descriptor for a function. */
200
201 struct __go_func_type
202 {
203 /* Starts like all other type descriptors. */
204 struct __go_type_descriptor __common;
205
206 /* Whether this is a varargs function. If this is true, there will
207 be at least one parameter. For "..." the last parameter type is
208 "interface{}". For "... T" the last parameter type is "[]T". */
209 _Bool __dotdotdot;
210
211 /* The input parameter types. This is an array of pointers to
212 struct __go_type_descriptor. */
213 struct __go_open_array __in;
214
215 /* The output parameter types. This is an array of pointers to
216 struct __go_type_descriptor. */
217 struct __go_open_array __out;
218 };
219
220 /* A method on an interface type. */
221
222 struct __go_interface_method
223 {
224 /* The name of the method. */
225 const struct String *__name;
226
227 /* This is NULL for an exported method, or the name of the package
228 where it lives. */
229 const struct String *__pkg_path;
230
231 /* The real type of the method. */
232 struct __go_type_descriptor *__type;
233 };
234
235 /* An interface type. */
236
237 struct __go_interface_type
238 {
239 /* Starts like all other type descriptors. */
240 struct __go_type_descriptor __common;
241
242 /* Array of __go_interface_method . The methods are sorted in the
243 same order that they appear in the definition of the
244 interface. */
245 struct __go_open_array __methods;
246 };
247
248 /* A map type. */
249
250 struct __go_map_type
251 {
252 /* Starts like all other type descriptors. */
253 struct __go_type_descriptor __common;
254
255 /* The map key type. */
256 const struct __go_type_descriptor *__key_type;
257
258 /* The map value type. */
259 const struct __go_type_descriptor *__val_type;
260
261 /* The map bucket type. */
262 const struct __go_type_descriptor *__bucket_type;
263
264 /* The map header type. */
265 const struct __go_type_descriptor *__hmap_type;
266
267 /* The size of the key slot. */
268 uint8_t __key_size;
269
270 /* Whether to store a pointer to key rather than the key itself. */
271 uint8_t __indirect_key;
272
273 /* The size of the value slot. */
274 uint8_t __value_size;
275
276 /* Whether to store a pointer to value rather than the value itself. */
277 uint8_t __indirect_value;
278
279 /* The size of a bucket. */
280 uint16_t __bucket_size;
281
282 /* Whether the key type is reflexive--whether k==k for all keys. */
283 _Bool __reflexive_key;
284
285 /* Whether we should update the key when overwriting an entry. */
286 _Bool __need_key_update;
287 };
288
289 /* A pointer type. */
290
291 struct __go_ptr_type
292 {
293 /* Starts like all other type descriptors. */
294 struct __go_type_descriptor __common;
295
296 /* The type to which this points. */
297 const struct __go_type_descriptor *__element_type;
298 };
299
300 /* A field in a structure. */
301
302 struct __go_struct_field
303 {
304 /* The name of the field--NULL for an anonymous field. */
305 const struct String *__name;
306
307 /* This is NULL for an exported method, or the name of the package
308 where it lives. */
309 const struct String *__pkg_path;
310
311 /* The type of the field. */
312 const struct __go_type_descriptor *__type;
313
314 /* The field tag, or NULL. */
315 const struct String *__tag;
316
317 /* The offset of the field in the struct. */
318 uintptr_t __offset;
319 };
320
321 /* A struct type. */
322
323 struct __go_struct_type
324 {
325 /* Starts like all other type descriptors. */
326 struct __go_type_descriptor __common;
327
328 /* An array of struct __go_struct_field. */
329 struct __go_open_array __fields;
330 };
331
332 /* Whether a type descriptor is a pointer. */
333
334 static inline _Bool
335 __go_is_pointer_type (const struct __go_type_descriptor *td)
336 {
337 return ((td->__code & GO_CODE_MASK) == GO_PTR
338 || (td->__code & GO_CODE_MASK) == GO_UNSAFE_POINTER);
339 }
340
341 /* Call a type hash function, given the __hashfn value. */
342
343 static inline uintptr_t
344 __go_call_hashfn (const FuncVal *hashfn, const void *p, uintptr_t seed,
345 uintptr_t size)
346 {
347 uintptr_t (*h) (const void *, uintptr_t, uintptr_t) = (void *) hashfn->fn;
348 return __builtin_call_with_static_chain (h (p, seed, size), hashfn);
349 }
350
351 /* Call a type equality function, given the __equalfn value. */
352
353 static inline _Bool
354 __go_call_equalfn (const FuncVal *equalfn, const void *p1, const void *p2,
355 uintptr_t size)
356 {
357 _Bool (*e) (const void *, const void *, uintptr_t) = (void *) equalfn->fn;
358 return __builtin_call_with_static_chain (e (p1, p2, size), equalfn);
359 }
360
361 extern _Bool
362 __go_type_descriptors_equal(const struct __go_type_descriptor*,
363 const struct __go_type_descriptor*);
364
365 extern const FuncVal __go_type_hash_identity_descriptor;
366 extern _Bool __go_type_equal_identity (const void *, const void *, uintptr_t);
367 extern const FuncVal __go_type_equal_identity_descriptor;
368 extern uintptr_t __go_type_hash_string (const void *, uintptr_t, uintptr_t);
369 extern const FuncVal __go_type_hash_string_descriptor;
370 extern _Bool __go_type_equal_string (const void *, const void *, uintptr_t);
371 extern const FuncVal __go_type_equal_string_descriptor;
372 extern uintptr_t __go_type_hash_float (const void *, uintptr_t, uintptr_t);
373 extern const FuncVal __go_type_hash_float_descriptor;
374 extern _Bool __go_type_equal_float (const void *, const void *, uintptr_t);
375 extern const FuncVal __go_type_equal_float_descriptor;
376 extern uintptr_t __go_type_hash_complex (const void *, uintptr_t, uintptr_t);
377 extern const FuncVal __go_type_hash_complex_descriptor;
378 extern _Bool __go_type_equal_complex (const void *, const void *, uintptr_t);
379 extern const FuncVal __go_type_equal_complex_descriptor;
380 extern uintptr_t __go_type_hash_interface (const void *, uintptr_t, uintptr_t);
381 extern const FuncVal __go_type_hash_interface_descriptor;
382 extern _Bool __go_type_equal_interface (const void *, const void *, uintptr_t);
383 extern const FuncVal __go_type_equal_interface_descriptor;
384
385 #endif /* !defined(LIBGO_GO_TYPE_H) */