libFirm
typerep.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19 
24 #ifndef FIRM_TYPEREP_H
25 #define FIRM_TYPEREP_H
26 
27 #include <stdlib.h>
28 #include "firm_types.h"
29 
30 #include "begin.h"
31 
92 typedef enum {
116 } ir_visibility;
117 
121 typedef enum ir_linkage {
122  IR_LINKAGE_DEFAULT = 0,
136  IR_LINKAGE_WEAK = 1 << 1,
167 } ir_linkage;
169 
170 
174 
178 FIRM_API void set_entity_visibility(ir_entity *entity, ir_visibility visibility);
179 
189 
195 FIRM_API int entity_has_definition(const ir_entity *entity);
196 
206 FIRM_API ir_entity *new_entity(ir_type *owner, ident *name, ir_type *tp);
207 
217 FIRM_API ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *tp,
218  dbg_info *db);
219 
224 FIRM_API ir_entity *new_parameter_entity(ir_type *owner, size_t pos,
225  ir_type *type);
226 
231  ir_type *type, dbg_info *dbgi);
232 
239 FIRM_API int check_entity(const ir_entity *ent);
240 
250 
260 
267 FIRM_API void free_entity(ir_entity *ent);
268 
270 FIRM_API const char *get_entity_name(const ir_entity *ent);
271 
274 
276 FIRM_API void set_entity_ident(ir_entity *ent, ident *id);
277 
285 
287 FIRM_API void set_entity_ld_ident(ir_entity *ent, ident *ld_ident);
288 
290 FIRM_API const char *get_entity_ld_name(const ir_entity *ent);
291 
293 FIRM_API int entity_has_ld_ident(const ir_entity *entity);
294 
297 
303 FIRM_API void set_entity_owner(ir_entity *ent, ir_type *owner);
304 
307 
309 FIRM_API void set_entity_type(ir_entity *ent, ir_type *tp);
310 
313 
315 FIRM_API void set_entity_linkage(ir_entity *entity, ir_linkage linkage);
317 FIRM_API void add_entity_linkage(ir_entity *entity, ir_linkage linkage);
319 FIRM_API void remove_entity_linkage(ir_entity *entity, ir_linkage linkage);
320 
326 
332 
335 
337 FIRM_API unsigned get_entity_alignment(const ir_entity *entity);
338 
343 FIRM_API void set_entity_alignment(ir_entity *entity, unsigned alignment);
344 
350 
356 
358 FIRM_API const char *get_align_name(ir_align a);
359 
362 FIRM_API int get_entity_offset(const ir_entity *ent);
363 
365 FIRM_API void set_entity_offset(ir_entity *ent, int offset);
366 
369 FIRM_API unsigned char get_entity_offset_bits_remainder(const ir_entity *ent);
370 
373  unsigned char offset);
374 
376 FIRM_API void *get_entity_link(const ir_entity *ent);
377 
379 FIRM_API void set_entity_link(ir_entity *ent, void *l);
380 
386 
388 #define IR_VTABLE_NUM_NOT_SET ((unsigned)(-1))
389 
391 FIRM_API unsigned get_entity_vtable_number(const ir_entity *ent);
392 
394 FIRM_API void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number);
395 
400 
403 
406 
410 typedef enum {
413  ir_usage_write = 1 << 1,
414  ir_usage_read = 1 << 2,
422 
425 
428 
435 
443 
452 #define IR_VA_START_PARAMETER_NUMBER ((size_t)-1)
453 
458 FIRM_API int is_parameter_entity(const ir_entity *entity);
459 
463 FIRM_API size_t get_entity_parameter_number(const ir_entity *entity);
464 
468 FIRM_API void set_entity_parameter_number(ir_entity *entity, size_t n);
469 
478 
488 
494 
500 typedef enum ir_initializer_kind_t {
510 
513 
516 
521 
527 
530 
533 
536 
539 
542 
545  size_t index,
546  ir_initializer_t *value);
547 
550  const ir_initializer_t *initializer, size_t index);
551 
555 FIRM_API void set_entity_initializer(ir_entity *entity, ir_initializer_t *initializer);
556 
558 FIRM_API int has_entity_initializer(const ir_entity *entity);
559 
562 
564 FIRM_API void add_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
567 FIRM_API size_t get_entity_n_overwrites(const ir_entity *ent);
571  ir_entity *overwritten);
573 FIRM_API ir_entity *get_entity_overwrites(const ir_entity *ent, size_t pos);
575 FIRM_API void set_entity_overwrites(ir_entity *ent, size_t pos,
576  ir_entity *overwritten);
578 FIRM_API void remove_entity_overwrites(ir_entity *ent, ir_entity *overwritten);
579 
585  ir_entity *overwrites);
587 FIRM_API ir_entity *get_entity_overwrittenby(const ir_entity *ent, size_t pos);
589 FIRM_API void set_entity_overwrittenby(ir_entity *ent, size_t pos,
590  ir_entity *overwrites);
593  ir_entity *overwrites);
594 
603 FIRM_API int is_entity(const void *thing);
604 
610 FIRM_API int is_atomic_entity(const ir_entity *ent);
613 FIRM_API int is_compound_entity(const ir_entity *ent);
615 FIRM_API int is_method_entity(const ir_entity *ent);
616 
621 FIRM_API long get_entity_nr(const ir_entity *ent);
622 
626 
630 
634 
637 FIRM_API int entity_visited(const ir_entity *ent);
638 
641 FIRM_API int entity_not_visited(const ir_entity *ent);
642 
651 
655 
659 
663 
699 
702 FIRM_API int is_unknown_entity(const ir_entity *entity);
703 
705 typedef enum {
706  allocation_automatic,
707  allocation_parameter,
708  allocation_dynamic,
709  allocation_static
710 } ir_allocation;
715 
717 typedef enum {
718  peculiarity_existent,
719  peculiarity_description,
720  peculiarity_inherited
726 
728 FIRM_API int is_entity_final(const ir_entity *ent);
730 FIRM_API void set_entity_final(ir_entity *ent, int final);
731 
736 
740 typedef enum ptr_access_kind {
749 
750 
789 typedef enum {
790  tpo_uninitialized = 0, /* not a type opcode */
802  tpo_last = tpo_unknown /* not a type opcode */
803 } tp_opcode;
804 
813 typedef struct tp_op tp_op;
814 
815 
822 FIRM_API const char *get_tpop_name(const tp_op *op);
823 
831 
840 FIRM_API int is_SubClass_of(ir_type *low, ir_type *high);
841 
848 FIRM_API int is_SubClass_ptr_of(ir_type *low, ir_type *high);
849 
856 #define is_SuperClass_of(high, low) is_SubClass_of(low, high)
857 
864 #define is_SuperClass_ptr_of(low, high) is_SubClass_ptr_of(high, low)
865 
870 
877  ir_entity* static_ent);
878 
884  const ir_type *clss);
885 
894  const ir_type *clss);
895 
911 
912 
913 /* ----------------------------------------------------------------------- */
914 /* The transitive closure of the subclass/superclass and */
915 /* overwrites/overwrittenby relation. */
916 /* */
917 /* A walk over the ir (O(#types+#entities)) computes the transitive */
918 /* closure. Adding a new type/entity or changing the basic relations in */
919 /* some other way invalidates the transitive closure, i.e., it is not */
920 /* updated by the basic functions. */
921 /* */
922 /* The transitive edges are held in a set, not in an array as the */
923 /* underlying relation. */
924 /* */
925 /* Do the sets contain the node itself? I assume NOT! */
926 /* ----------------------------------------------------------------------- */
927 
931 typedef enum {
937 
947 
954 
957 
970 FIRM_API int is_class_trans_subtype(const ir_type *tp, const ir_type *subtp);
971 
979 
987 
996 
997 
1022 typedef enum {
1027  ir_class_casts_state_max
1029 
1032  ir_class_cast_state state);
1039 
1045 FIRM_API int check_type(const ir_type *tp);
1046 
1057 FIRM_API int tr_verify(void);
1058 
1065 FIRM_API void free_type(ir_type *tp);
1066 
1068 FIRM_API const tp_op *get_type_tpop(const ir_type *tp);
1072 FIRM_API const char *get_type_tpop_name(const ir_type *tp);
1075 
1085 FIRM_API void ir_print_type(char *buffer, size_t buffer_size,
1086  const ir_type *tp);
1087 
1089 typedef enum {
1101 } ir_type_state;
1102 
1105 
1108 
1114 FIRM_API void set_type_state(ir_type *tp, ir_type_state state);
1115 
1121 
1126 FIRM_API void set_type_mode(ir_type *tp, ir_mode* m);
1127 
1129 FIRM_API unsigned get_type_size_bytes(const ir_type *tp);
1130 
1136 FIRM_API void set_type_size_bytes(ir_type *tp, unsigned size);
1137 
1140 
1151 FIRM_API void set_type_alignment_bytes(ir_type *tp, unsigned align);
1152 
1164 FIRM_API int type_visited(const ir_type *tp);
1167 FIRM_API int type_not_visited(const ir_type *tp);
1168 
1170 FIRM_API void *get_type_link(const ir_type *tp);
1172 FIRM_API void set_type_link(ir_type *tp, void *l);
1173 
1183 
1191 
1198 
1207 FIRM_API int is_type(const void *thing);
1208 
1214 FIRM_API long get_type_nr(const ir_type *tp);
1215 
1251 FIRM_API int equal_type(ir_type *typ1, ir_type *typ2);
1252 
1288 FIRM_API int smaller_type(ir_type *st, ir_type *lt);
1289 
1340 
1343 
1345 FIRM_API ident *get_class_ident(const ir_type *clss);
1346 
1348 FIRM_API const char *get_class_name(const ir_type *clss);
1349 
1351 FIRM_API size_t get_class_n_members(const ir_type *clss);
1352 
1354 FIRM_API ir_entity *get_class_member(const ir_type *clss, size_t pos);
1355 
1360 #define INVALID_MEMBER_INDEX ((size_t)-1)
1361 
1363 FIRM_API size_t get_class_member_index(const ir_type *clss, ir_entity *mem);
1364 
1368 
1373 FIRM_API void add_class_subtype(ir_type *clss, ir_type *subtype);
1374 
1376 FIRM_API size_t get_class_n_subtypes(const ir_type *clss);
1377 
1379 FIRM_API ir_type *get_class_subtype(ir_type *clss, size_t pos);
1380 
1385 FIRM_API size_t get_class_subtype_index(ir_type *clss, const ir_type *subclass);
1386 
1391 FIRM_API void set_class_subtype(ir_type *clss, ir_type *subtype, size_t pos);
1392 
1394 FIRM_API void remove_class_subtype(ir_type *clss, ir_type *subtype);
1395 
1400 FIRM_API void add_class_supertype(ir_type *clss, ir_type *supertype);
1401 
1403 FIRM_API size_t get_class_n_supertypes(const ir_type *clss);
1404 
1409 FIRM_API size_t get_class_supertype_index(ir_type *clss, ir_type *super_clss);
1410 
1412 FIRM_API ir_type *get_class_supertype(ir_type *clss, size_t pos);
1413 
1418 FIRM_API void set_class_supertype(ir_type *clss, ir_type *supertype, size_t pos);
1419 
1421 FIRM_API void remove_class_supertype(ir_type *clss, ir_type *supertype);
1422 
1425 
1427 FIRM_API void set_class_type_info(ir_type *clss, ir_entity *ent);
1428 
1430 FIRM_API unsigned get_class_vtable_size(const ir_type *clss);
1431 
1433 FIRM_API void set_class_vtable_size(ir_type *clss, unsigned size);
1434 
1436 FIRM_API int is_class_final(const ir_type *clss);
1437 
1439 FIRM_API void set_class_final(ir_type *clss, int flag);
1440 
1442 FIRM_API int is_class_interface(const ir_type *clss);
1443 
1445 FIRM_API void set_class_interface(ir_type *clss, int flag);
1446 
1448 FIRM_API int is_class_abstract(const ir_type *clss);
1449 
1451 FIRM_API void set_class_abstract(ir_type *clss, int flag);
1452 
1454 FIRM_API int is_Class_type(const ir_type *clss);
1455 
1466 FIRM_API const tp_op *get_tpop_class(void);
1467 
1492 
1494 FIRM_API ident *get_struct_ident(const ir_type *strct);
1495 
1497 FIRM_API const char *get_struct_name(const ir_type *strct);
1498 
1500 FIRM_API size_t get_struct_n_members(const ir_type *strct);
1501 
1503 FIRM_API ir_entity *get_struct_member(const ir_type *strct, size_t pos);
1504 
1506 FIRM_API size_t get_struct_member_index(const ir_type *strct, ir_entity *member);
1507 
1509 FIRM_API int is_Struct_type(const ir_type *strct);
1510 
1522 FIRM_API const tp_op *get_tpop_struct(void);
1523 
1542 
1545 
1546 
1548 FIRM_API ident *get_union_ident(const ir_type *uni);
1549 
1551 FIRM_API const char *get_union_name(const ir_type *uni);
1552 
1554 FIRM_API size_t get_union_n_members(const ir_type *uni);
1555 
1557 FIRM_API ir_entity *get_union_member(const ir_type *uni, size_t pos);
1558 
1560 FIRM_API size_t get_union_member_index(const ir_type *uni, ir_entity *member);
1561 
1563 FIRM_API int is_Union_type(const ir_type *uni);
1564 
1574 FIRM_API const tp_op *get_tpop_union(void);
1575 
1617 FIRM_API ir_type *new_type_method(size_t n_param, size_t n_res);
1618 
1628 FIRM_API ir_type *new_d_type_method(size_t n_param, size_t n_res,
1629  type_dbg_info *db);
1630 
1632 FIRM_API size_t get_method_n_params(const ir_type *method);
1633 
1635 FIRM_API ir_type *get_method_param_type(const ir_type *method, size_t pos);
1639 FIRM_API void set_method_param_type(ir_type *method, size_t pos, ir_type *tp);
1641 FIRM_API size_t get_method_n_ress(const ir_type *method);
1643 FIRM_API ir_type *get_method_res_type(const ir_type *method, size_t pos);
1645 FIRM_API void set_method_res_type(ir_type *method, size_t pos, ir_type *tp);
1646 
1652 typedef enum ir_variadicity {
1655 } ir_variadicity;
1656 
1658 FIRM_API const char *get_variadicity_name(ir_variadicity vari);
1659 
1662 
1665 
1668 
1671  mtp_additional_properties property_mask);
1672 
1676 
1681 typedef enum {
1682  cc_reg_param = 0x01000000,
1684  cc_last_on_top = 0x02000000,
1689  cc_callee_clear_stk = 0x04000000,
1691  cc_this_call = 0x08000000,
1693  cc_compound_ret = 0x10000000,
1694  cc_frame_on_caller_stk = 0x20000000,
1696  cc_fpreg_param = 0x40000000,
1697  cc_bits = (0xFF << 24)
1699 
1701 #define cc_cdecl_set (0)
1702 
1703 #define cc_stdcall_set cc_callee_clear_stk
1704 
1705 #define cc_fastcall_set (cc_reg_param|cc_callee_clear_stk)
1706 
1710 #define IS_CDECL(cc_mask) (((cc_mask) & cc_bits) == cc_cdecl_set)
1711 
1715 #define IS_STDCALL(cc_mask) (((cc_mask) & cc_bits) == cc_stdcall_set)
1716 
1720 #define IS_FASTCALL(cc_mask) (((cc_mask) & cc_bits) == cc_fastcall_set)
1721 
1725 #define SET_CDECL(cc_mask) (((cc_mask) & ~cc_bits) | cc_cdecl_set)
1726 
1730 #define SET_STDCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_stdcall_set)
1731 
1735 #define SET_FASTCALL(cc_mask) (((cc_mask) & ~cc_bits) | cc_fastcall_set)
1736 
1738 FIRM_API unsigned get_method_calling_convention(const ir_type *method);
1739 
1741 FIRM_API void set_method_calling_convention(ir_type *method, unsigned cc_mask);
1742 
1744 FIRM_API unsigned get_method_n_regparams(ir_type *method);
1745 
1747 FIRM_API void set_method_n_regparams(ir_type *method, unsigned n_regs);
1748 
1750 FIRM_API int is_Method_type(const ir_type *method);
1751 
1761 FIRM_API const tp_op *get_tpop_method(void);
1762 
1788 FIRM_API ir_type *new_type_array(size_t n_dims, ir_type *element_type);
1789 
1798 FIRM_API ir_type *new_d_type_array(size_t n_dims, ir_type *element_type,
1799  type_dbg_info* db);
1800 
1801 
1803 FIRM_API size_t get_array_n_dimensions(const ir_type *array);
1804 
1809 FIRM_API void set_array_bounds_int(ir_type *array, size_t dimension,
1810  int lower_bound, int upper_bound);
1815 FIRM_API void set_array_bounds(ir_type *array, size_t dimension,
1816  ir_node *lower_bound, ir_node *upper_bound);
1818 FIRM_API void set_array_lower_bound(ir_type *array, size_t dimension,
1819  ir_node *lower_bound);
1820 
1823 FIRM_API void set_array_lower_bound_int(ir_type *array, size_t dimension,
1824  int lower_bound);
1825 
1827 FIRM_API void set_array_upper_bound(ir_type *array, size_t dimension,
1828  ir_node *upper_bound);
1829 
1832 FIRM_API void set_array_upper_bound_int(ir_type *array, size_t dimension,
1833  int upper_bound);
1834 
1836 FIRM_API int has_array_lower_bound(const ir_type *array, size_t dimension);
1838 FIRM_API ir_node *get_array_lower_bound(const ir_type *array, size_t dimension);
1840 FIRM_API long get_array_lower_bound_int(const ir_type *array, size_t dimension);
1842 FIRM_API int has_array_upper_bound(const ir_type *array, size_t dimension);
1844 FIRM_API ir_node *get_array_upper_bound(const ir_type *array, size_t dimension);
1846 FIRM_API long get_array_upper_bound_int(const ir_type *array, size_t dimension);
1847 
1849 FIRM_API void set_array_order(ir_type *array, size_t dimension, size_t order);
1850 
1852 FIRM_API size_t get_array_order(const ir_type *array, size_t dimension);
1853 
1855 FIRM_API size_t find_array_dimension(const ir_type *array, size_t order);
1856 
1859 
1862 
1865 
1868 
1874 FIRM_API void set_array_variable_size(ir_type *array, int variable_size_flag);
1875 
1880 FIRM_API int is_array_variable_size(const ir_type *array);
1881 
1883 FIRM_API int is_Array_type(const ir_type *array);
1884 
1895 FIRM_API const tp_op *get_tpop_array(void);
1896 
1914 FIRM_API ir_type *new_type_enumeration(ident *name, size_t n_enums);
1915 
1917 FIRM_API ir_type *new_d_type_enumeration(ident *name, size_t n_enums,
1918  type_dbg_info *db);
1919 
1920 
1922 FIRM_API ident *get_enumeration_ident(const ir_type *enumeration);
1923 
1925 FIRM_API const char *get_enumeration_name(const ir_type *enumeration);
1926 
1928 FIRM_API void set_enumeration_const(ir_type *enumeration, size_t pos,
1929  ident *nameid, ir_tarval *con);
1930 
1932 FIRM_API size_t get_enumeration_n_enums(const ir_type *enumeration);
1933 
1936  size_t pos);
1937 
1940 
1942 FIRM_API void set_enumeration_value(ir_enum_const *enum_cnst, ir_tarval *con);
1943 
1946 
1948 FIRM_API void set_enumeration_nameid(ir_enum_const *enum_cnst, ident *id);
1949 
1952 
1954 FIRM_API const char *get_enumeration_const_name(const ir_enum_const *enum_cnst);
1955 
1957 FIRM_API int is_Enumeration_type(const ir_type *enumeration);
1958 
1970 FIRM_API const tp_op *get_tpop_enumeration(void);
1971 
1984 
1987 
1988 
1991 
1994 
1996 FIRM_API int is_Pointer_type(const ir_type *pointer);
1997 
2002 
2012 FIRM_API const tp_op *get_tpop_pointer(void);
2013 
2026 
2029 
2031 FIRM_API int is_Primitive_type(const ir_type *primitive);
2032 
2035 
2037 FIRM_API void set_primitive_base_type(ir_type *tp, ir_type *base_tp);
2038 
2049 FIRM_API const tp_op *get_tpop_primitive(void);
2050 
2074 FIRM_API int is_none_type(const ir_type *type);
2085 FIRM_API const tp_op *get_tpop_none(void);
2096 FIRM_API int is_code_type(const ir_type *tp);
2102 FIRM_API const tp_op *get_tpop_code_type(void);
2126 FIRM_API int is_unknown_type(const ir_type *type);
2137 FIRM_API const tp_op *get_tpop_unknown(void);
2145 FIRM_API int is_atomic_type(const ir_type *tp);
2146 
2157 
2159 FIRM_API const char *get_compound_name(const ir_type *tp);
2160 
2172 FIRM_API size_t get_compound_n_members(const ir_type *tp);
2173 
2182 FIRM_API ir_entity *get_compound_member(const ir_type *tp, size_t pos);
2183 
2185 FIRM_API size_t get_compound_member_index(const ir_type *tp, ir_entity *member);
2186 
2188 FIRM_API void remove_compound_member(ir_type *compound, ir_entity *entity);
2189 
2197 FIRM_API void set_compound_variable_size(ir_type *compound, int variable_size);
2198 
2202 FIRM_API int is_compound_variable_size(const ir_type *compound);
2203 
2208 
2216 FIRM_API int is_compound_type(const ir_type *tp);
2217 
2230 
2234 FIRM_API int is_frame_type(const ir_type *tp);
2235 
2242 
2255 FIRM_API ir_entity *frame_alloc_area(ir_type *frame_type, int size,
2256  unsigned alignment, int at_start);
2257 
2270 typedef int (compare_types_func_t)(const void *tp1, const void *tp2);
2271 
2273 typedef union {
2276 } type_or_ent;
2277 
2283 typedef void type_walk_func(type_or_ent tore, void *env);
2284 
2290 typedef void class_walk_func(ir_type *clss, void *env);
2291 
2296 FIRM_API void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
2297 
2304  type_walk_func *post, void *env);
2305 
2316  void *env);
2317 
2331  void *env);
2332 
2340  void *env);
2341 
2348 typedef void entity_walk_func(ir_entity *ent, void *env);
2349 
2358  void *env);
2359 
2367 
2372 
2377 #include "end.h"
2378 
2379 #endif