Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
14a2aefb
Commit
14a2aefb
authored
Sep 07, 2015
by
Matthias Braun
Browse files
tpop: Cleanup
parent
0319eace
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/libfirm/typerep.h
View file @
14a2aefb
...
...
@@ -1107,7 +1107,8 @@ FIRM_API ir_entity *get_class_member(const ir_type *clss, size_t pos);
#define INVALID_MEMBER_INDEX ((size_t)-1)
/** Returns index of mem in clss, INVALID_MEMBER_INDEX if not contained. */
FIRM_API
size_t
get_class_member_index
(
const
ir_type
*
clss
,
ir_entity
*
mem
);
FIRM_API
size_t
get_class_member_index
(
ir_type
const
*
clss
,
ir_entity
const
*
mem
);
/** Adds subtype as subtype to clss.
*
...
...
@@ -1216,7 +1217,8 @@ FIRM_API size_t get_struct_n_members(const ir_type *strct);
FIRM_API
ir_entity
*
get_struct_member
(
const
ir_type
*
strct
,
size_t
pos
);
/** Returns index of member in strct, -1 if not contained. */
FIRM_API
size_t
get_struct_member_index
(
const
ir_type
*
strct
,
ir_entity
*
member
);
FIRM_API
size_t
get_struct_member_index
(
ir_type
const
*
strct
,
ir_entity
const
*
member
);
/** Returns true if a type is a struct type. */
FIRM_API
int
is_Struct_type
(
const
ir_type
*
strct
);
...
...
@@ -1266,7 +1268,8 @@ FIRM_API size_t get_union_n_members(const ir_type *uni);
FIRM_API
ir_entity
*
get_union_member
(
const
ir_type
*
uni
,
size_t
pos
);
/** Returns index of member in uni, -1 if not contained. */
FIRM_API
size_t
get_union_member_index
(
const
ir_type
*
uni
,
ir_entity
*
member
);
FIRM_API
size_t
get_union_member_index
(
ir_type
const
*
uni
,
ir_entity
const
*
member
);
/** Returns true if a type is a union type. */
FIRM_API
int
is_Union_type
(
const
ir_type
*
uni
);
...
...
@@ -1671,7 +1674,8 @@ FIRM_API size_t get_compound_n_members(const ir_type *tp);
FIRM_API
ir_entity
*
get_compound_member
(
const
ir_type
*
tp
,
size_t
pos
);
/** Returns index of member in tp, -1 if not contained. */
FIRM_API
size_t
get_compound_member_index
(
const
ir_type
*
tp
,
ir_entity
*
member
);
FIRM_API
size_t
get_compound_member_index
(
ir_type
const
*
tp
,
ir_entity
const
*
member
);
/** Remove a member from a compound type. */
FIRM_API
void
remove_compound_member
(
ir_type
*
compound
,
ir_entity
*
entity
);
...
...
ir/tr/tpop.c
View file @
14a2aefb
...
...
@@ -13,15 +13,15 @@
#include
"tpop_t.h"
#include
"type_t.h"
const
tp_op
*
type_class
;
const
tp_op
*
get_tpop_class
(
void
)
{
return
type_class
;
}
const
tp_op
*
type_struct
;
const
tp_op
*
get_tpop_struct
(
void
)
{
return
type_struct
;
}
const
tp_op
*
type_method
;
const
tp_op
*
get_tpop_method
(
void
)
{
return
type_method
;
}
const
tp_op
*
type_union
;
const
tp_op
*
get_tpop_union
(
void
)
{
return
type_union
;
}
const
tp_op
*
type_array
;
const
tp_op
*
get_tpop_array
(
void
)
{
return
type_array
;
}
const
tp_op
*
type_pointer
;
const
tp_op
*
get_tpop_pointer
(
void
)
{
return
type_pointer
;
}
const
tp_op
*
type_primitive
;
const
tp_op
*
get_tpop_primitive
(
void
)
{
return
type_primitive
;
}
const
tp_op
*
tpop_code
;
const
tp_op
*
get_tpop_code_type
(
void
)
{
return
tpop_code
;
}
const
tp_op
*
tpop_unknown
;
const
tp_op
*
get_tpop_unknown
(
void
)
{
return
tpop_unknown
;
}
const
tp_op
*
type_class
;
const
tp_op
*
get_tpop_class
(
void
)
{
return
type_class
;
}
const
tp_op
*
type_struct
;
const
tp_op
*
get_tpop_struct
(
void
)
{
return
type_struct
;
}
const
tp_op
*
type_method
;
const
tp_op
*
get_tpop_method
(
void
)
{
return
type_method
;
}
const
tp_op
*
type_union
;
const
tp_op
*
get_tpop_union
(
void
)
{
return
type_union
;
}
const
tp_op
*
type_array
;
const
tp_op
*
get_tpop_array
(
void
)
{
return
type_array
;
}
const
tp_op
*
type_pointer
;
const
tp_op
*
get_tpop_pointer
(
void
)
{
return
type_pointer
;
}
const
tp_op
*
type_primitive
;
const
tp_op
*
get_tpop_primitive
(
void
)
{
return
type_primitive
;
}
const
tp_op
*
tpop_code
;
const
tp_op
*
get_tpop_code_type
(
void
)
{
return
tpop_code
;
}
const
tp_op
*
tpop_unknown
;
const
tp_op
*
get_tpop_unknown
(
void
)
{
return
tpop_unknown
;
}
const
tp_op
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
unsigned
flags
,
size_t
attr_size
,
const
tp_op_ops
*
ops
)
...
...
@@ -37,96 +37,56 @@ const tp_op *new_tpop(tp_opcode code, ident *name, unsigned flags,
void
free_tpop
(
const
tp_op
*
tpop
)
{
free
((
void
*
)
tpop
);
free
((
void
*
)
tpop
);
}
static
const
tp_op_ops
/** tpop operations for class types */
class_ops
=
{
free_class_attrs
,
free_class_entities
,
NULL
,
set_class_mode
,
set_default_size
,
get_class_n_members
,
get_class_member
,
get_class_member_index
.
free_attrs
=
free_class_attrs
,
.
free_entities
=
free_class_entities
,
.
set_type_mode
=
set_class_mode
,
.
set_type_size
=
set_default_size
,
.
get_n_members
=
get_class_n_members
,
.
get_member
=
get_class_member
,
.
get_member_index
=
get_class_member_index
},
/** tpop operations for struct types */
struct_ops
=
{
free_struct_attrs
,
free_struct_entities
,
NULL
,
set_struct_mode
,
set_default_size
,
get_struct_n_members
,
get_struct_member
,
get_struct_member_index
.
free_attrs
=
free_struct_attrs
,
.
free_entities
=
free_struct_entities
,
.
set_type_mode
=
set_struct_mode
,
.
set_type_size
=
set_default_size
,
.
get_n_members
=
get_struct_n_members
,
.
get_member
=
get_struct_member
,
.
get_member_index
=
get_struct_member_index
},
/** tpop operations for method types */
method_ops
=
{
free_method_attrs
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
.
free_attrs
=
free_method_attrs
,
},
/** tpop operations for union types */
union_ops
=
{
free_union_attrs
,
free_union_entities
,
NULL
,
NULL
,
set_default_size
,
get_union_n_members
,
get_union_member
,
get_union_member_index
.
free_attrs
=
free_union_attrs
,
.
free_entities
=
free_union_entities
,
.
set_type_size
=
set_default_size
,
.
get_n_members
=
get_union_n_members
,
.
get_member
=
get_union_member
,
.
get_member_index
=
get_union_member_index
},
/** tpop operations for array types */
array_ops
=
{
NULL
,
NULL
,
NULL
,
NULL
,
set_default_size
,
NULL
,
NULL
,
NULL
.
set_type_size
=
set_default_size
,
},
/** tpop operations for pointer types */
pointer_ops
=
{
NULL
,
NULL
,
NULL
,
set_pointer_mode
,
NULL
,
NULL
,
NULL
,
NULL
.
set_type_mode
=
set_pointer_mode
,
},
primitive_ops
=
{
NULL
,
NULL
,
NULL
,
NULL
,
set_default_size
,
NULL
,
NULL
,
NULL
.
set_type_size
=
set_default_size
,
},
/** tpop operations for primitive types */
null_ops
=
{
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
}
;
...
...
@@ -145,15 +105,15 @@ void init_tpop(void)
void
finish_tpop
(
void
)
{
free_tpop
(
type_class
);
type_class
=
NULL
;
free_tpop
(
type_struct
);
type_struct
=
NULL
;
free_tpop
(
type_method
);
type_method
=
NULL
;
free_tpop
(
type_union
);
type_union
=
NULL
;
free_tpop
(
type_array
);
type_array
=
NULL
;
free_tpop
(
type_pointer
);
type_pointer
=
NULL
;
free_tpop
(
type_primitive
);
type_primitive
=
NULL
;
free_tpop
(
tpop_code
);
tpop_code
=
NULL
;
free_tpop
(
tpop_unknown
);
tpop_unknown
=
NULL
;
free_tpop
(
type_class
);
type_class
=
NULL
;
free_tpop
(
type_struct
);
type_struct
=
NULL
;
free_tpop
(
type_method
);
type_method
=
NULL
;
free_tpop
(
type_union
);
type_union
=
NULL
;
free_tpop
(
type_array
);
type_array
=
NULL
;
free_tpop
(
type_pointer
);
type_pointer
=
NULL
;
free_tpop
(
type_primitive
);
type_primitive
=
NULL
;
free_tpop
(
tpop_code
);
tpop_code
=
NULL
;
free_tpop
(
tpop_unknown
);
tpop_unknown
=
NULL
;
}
const
char
*
get_tpop_name
(
const
tp_op
*
op
)
...
...
ir/tr/tpop_t.h
View file @
14a2aefb
...
...
@@ -20,44 +20,24 @@
#define get_tpop_code(op) _get_tpop_code(op)
#define get_tpop_ident(op) _get_tpop_ident(op)
/** A function called to free attributes of a type. */
typedef
void
(
*
free_attrs_func
)(
ir_type
*
tp
);
/** A function called to free owned entities of a type. */
typedef
void
(
*
free_entities_func
)(
ir_type
*
tp
);
/** A function called to free all automatic allocated entities of a type. */
typedef
void
(
*
free_auto_entities_func
)(
ir_type
*
tp
);
/** A function called to set the mode of a type. */
typedef
void
(
*
set_type_mode_func
)(
ir_type
*
tp
,
ir_mode
*
m
);
/** A function called to set the size of a type in bytes. */
typedef
void
(
*
set_type_size_func
)(
ir_type
*
tp
,
unsigned
size
);
/** A function called to get the number of compound members */
typedef
size_t
(
*
get_n_members_func
)(
const
ir_type
*
tp
);
/** A function called to get the pos'th compound member */
typedef
ir_entity
*
(
*
get_member_func
)(
const
ir_type
*
tp
,
size_t
pos
);
typedef
size_t
(
*
get_member_index_func
)(
const
ir_type
*
tp
,
ir_entity
*
member
);
/** A function called to insert an entity into the type */
typedef
void
(
*
insert_entity_func
)(
ir_type
*
tp
,
ir_entity
*
member
);
/**
* tp_op operations.
*/
typedef
struct
tp_op_ops
{
free_attrs_func
free_attrs
;
/**< Called to free the attributes of a type. */
free_entities_func
free_entities
;
/**< Called to free the owned entities of a type. */
free_auto_entities_func
free_auto_entities
;
/**< Called to free the automatic allocated entities of a type. */
set_type_mode_func
set_type_mode
;
/**< Called to set a ir_mode of a type. */
set_type_size_func
set_type_size
;
/**< Called to set the byte size of a type. */
get_n_members_func
get_n_members
;
/**< Called to return the number of compound members. */
get_member_func
get_member
;
/**< Called to get the pos'th compound member. */
get_member_index_func
get_member_index
;
/**< Called to get the index of a compound member. */
/** Called to free the attributes of a type. */
void
(
*
free_attrs
)(
ir_type
*
type
);
/** Called to free the owned entities of a type. */
void
(
*
free_entities
)(
ir_type
*
type
);
/** Called to set a ir_mode of a type. */
void
(
*
set_type_mode
)(
ir_type
*
type
,
ir_mode
*
mode
);
/** Called to set the byte size of a type. */
void
(
*
set_type_size
)(
ir_type
*
type
,
unsigned
size
);
/** Called to return the number of compound members. */
size_t
(
*
get_n_members
)(
ir_type
const
*
type
);
/** Called to get the pos'th compound member. */
ir_entity
*
(
*
get_member
)(
ir_type
const
*
type
,
size_t
pos
);
/** Called to get the index of a compound member. */
size_t
(
*
get_member_index
)(
ir_type
const
*
type
,
ir_entity
const
*
member
);
}
tp_op_ops
;
/** possible flags for a type opcode */
...
...
@@ -67,11 +47,11 @@ enum tp_op_flags_t {
/** The type opcode. */
struct
tp_op
{
tp_opcode
code
;
/**< The tpop code. */
ident
*
name
;
/**< The name of the type opcode. */
size_t
attr_size
;
/**< The attribute size for a type of this opcode. */
unsigned
flags
;
/**< Flags for this opcode. */
tp_op_ops
ops
;
/**< tp_op operations. */
tp_opcode
code
;
/**< The tpop code. */
ident
*
name
;
/**< The name of the type opcode. */
size_t
attr_size
;
/**< The attribute size for a type of this opcode. */
unsigned
flags
;
/**< Flags for this opcode. */
tp_op_ops
ops
;
/**< tp_op operations. */
};
/**
...
...
@@ -89,12 +69,13 @@ struct tp_op {
* @param ops the tp_op operations for this type
* @return A new type opcode.
*/
const
tp_op
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
unsigned
flags
,
size_t
attr_size
,
const
tp_op_ops
*
ops
);
tp_op
const
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
unsigned
flags
,
size_t
attr_size
,
tp_op_ops
const
*
ops
);
/**
* Free a tpop data structure.
*/
void
free_tpop
(
const
tp_op
*
tpop
);
void
free_tpop
(
tp_op
const
*
tpop
);
/**
* Initialize the tpop module.
...
...
@@ -123,21 +104,17 @@ void finish_tpop(void);
* @param op The type opcode to get the size for.
* @return The size of the attribute of types with this opcode.
*/
static
inline
size_t
get_tpop_attr_size
(
const
tp_op
*
op
)
static
inline
size_t
get_tpop_attr_size
(
tp_op
const
*
op
)
{
return
op
->
attr_size
;
}
/* ---------------- *
* inline functions *
* -----------------*/
static
inline
tp_opcode
_get_tpop_code
(
const
tp_op
*
op
)
static
inline
tp_opcode
_get_tpop_code
(
tp_op
const
*
op
)
{
return
op
->
code
;
}
static
inline
ident
*
_get_tpop_ident
(
const
tp_op
*
op
)
static
inline
ident
*
_get_tpop_ident
(
tp_op
const
*
op
)
{
return
op
->
name
;
}
...
...
ir/tr/type.c
View file @
14a2aefb
...
...
@@ -146,16 +146,11 @@ static void free_type_attrs(ir_type *tp)
void
free_type
(
ir_type
*
tp
)
{
const
tp_op
*
op
=
get_type_tpop
(
tp
);
free_type_entities
(
tp
);
/* Remove from list of all types */
remove_irp_type
(
tp
);
/* Free the attributes of the type. */
free_type_attrs
(
tp
);
/* Free entities automatically allocated with the ir_type */
if
(
op
->
ops
.
free_auto_entities
)
op
->
ops
.
free_auto_entities
(
tp
);
/* And now the type itself... */
#ifdef DEBUG_libfirm
tp
->
kind
=
k_BAD
;
...
...
@@ -382,8 +377,8 @@ static void compound_free_entities(ir_type *type)
free_entity
(
compound_get_member
(
type
,
i
));
}
static
size_t
compound_get_member_index
(
const
ir_type
*
type
,
const
ir_entity
*
entity
)
static
size_t
compound_get_member_index
(
ir_type
const
*
const
type
,
ir_entity
const
*
const
entity
)
{
for
(
size_t
i
=
0
,
n
=
compound_get_n_members
(
type
);
i
<
n
;
++
i
)
{
if
(
compound_get_member
(
type
,
i
)
==
entity
)
...
...
@@ -452,7 +447,7 @@ size_t (get_class_n_members)(const ir_type *clss)
return
get_class_n_members_
(
clss
);
}
size_t
get_class_member_index
(
const
ir_type
*
clss
,
ir_entity
*
mem
)
size_t
get_class_member_index
(
ir_type
const
*
clss
,
ir_entity
const
*
const
mem
)
{
assert
(
is_Class_type
(
clss
));
return
compound_get_member_index
(
clss
,
mem
);
...
...
@@ -651,7 +646,7 @@ ir_entity *get_struct_member(const ir_type *strct, size_t pos)
return
compound_get_member
(
strct
,
pos
);
}
size_t
get_struct_member_index
(
const
ir_type
*
strct
,
ir_entity
*
mem
)
size_t
get_struct_member_index
(
ir_type
const
*
strct
,
ir_entity
const
*
const
mem
)
{
assert
(
is_Struct_type
(
strct
));
return
compound_get_member_index
(
strct
,
mem
);
...
...
@@ -878,7 +873,7 @@ ir_entity *get_union_member(const ir_type *uni, size_t pos)
return
compound_get_member
(
uni
,
pos
);
}
size_t
get_union_member_index
(
const
ir_type
*
uni
,
ir_entity
*
mem
)
size_t
get_union_member_index
(
ir_type
const
*
uni
,
ir_entity
const
*
const
mem
)
{
assert
(
is_Union_type
(
uni
));
return
compound_get_member_index
(
uni
,
mem
);
...
...
@@ -1071,10 +1066,10 @@ ir_entity *get_compound_member(const ir_type *tp, size_t pos)
return
op
->
ops
.
get_member
(
tp
,
pos
);
}
size_t
get_compound_member_index
(
const
ir_type
*
tp
,
ir_entity
*
member
)
size_t
get_compound_member_index
(
ir_type
const
*
tp
,
ir_entity
const
*
const
mem
)
{
const
tp_op
*
op
=
get_type_tpop
(
tp
);
return
op
->
ops
.
get_member_index
(
tp
,
mem
ber
);
return
op
->
ops
.
get_member_index
(
tp
,
mem
);
}
void
set_compound_variable_size
(
ir_type
*
tp
,
int
variable_size_flag
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment