Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
4790cf11
Commit
4790cf11
authored
Dec 06, 2015
by
Matthias Braun
Browse files
Remove more unnecessary dispatch to common compound code
parent
2b9dfcb0
Changes
4
Hide whitespace changes
Inline
Side-by-side
ir/tr/tpop.c
View file @
4790cf11
...
...
@@ -44,12 +44,10 @@ static const tp_op_ops
/** tpop operations for class types */
class_ops
=
{
.
free_attrs
=
free_class_attrs
,
.
free_entities
=
free_compound_entities
,
},
/** tpop operations for struct types */
struct_ops
=
{
.
free_attrs
=
free_struct_attrs
,
.
free_entities
=
free_compound_entities
,
.
free_attrs
=
free_compound_attrs
,
},
/** tpop operations for method types */
method_ops
=
{
...
...
@@ -57,8 +55,7 @@ static const tp_op_ops
},
/** tpop operations for union types */
union_ops
=
{
.
free_attrs
=
free_union_attrs
,
.
free_entities
=
free_compound_entities
,
.
free_attrs
=
free_compound_attrs
,
},
null_ops
=
{
.
free_attrs
=
NULL
,
...
...
ir/tr/tpop_t.h
View file @
4790cf11
...
...
@@ -25,8 +25,6 @@
typedef
struct
tp_op_ops
{
/** 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
);
}
tp_op_ops
;
/** possible flags for a type opcode */
...
...
ir/tr/type.c
View file @
4790cf11
...
...
@@ -51,6 +51,7 @@
#include "array.h"
static
ir_type
*
new_type
(
tp_op
const
*
type_op
,
ir_mode
*
mode
);
static
void
free_compound_entities
(
ir_type
*
type
);
ir_type
*
get_code_type
(
void
)
{
...
...
@@ -128,11 +129,10 @@ static ir_type *new_type(tp_op const *type_op, ir_mode *mode)
return
res
;
}
void
free_type_entities
(
ir_type
*
tp
)
void
free_type_entities
(
ir_type
*
const
type
)
{
const
tp_op
*
op
=
get_type_tpop
(
tp
);
if
(
op
->
ops
.
free_entities
!=
NULL
)
op
->
ops
.
free_entities
(
tp
);
if
(
is_compound_type
(
type
))
free_compound_entities
(
type
);
}
static
void
free_type_attrs
(
ir_type
*
tp
)
...
...
@@ -316,36 +316,17 @@ static void compound_init(ir_type *const type, ident *const name)
type
->
attr
.
ca
.
members
=
NEW_ARR_F
(
ir_entity
*
,
0
);
}
static
void
compound_
free_
attrs
(
ir_type
*
type
)
void
free_
compound_attrs
(
ir_type
*
type
)
{
DEL_ARR_F
(
type
->
attr
.
ca
.
members
);
}
static
void
compound_add_member
(
ir_type
*
type
,
ir_entity
*
entity
)
{
/* try to detect double-add */
assert
(
get_entity_type
(
entity
)
!=
type
);
ARR_APP1
(
ir_entity
*
,
type
->
attr
.
ca
.
members
,
entity
);
}
void
free_compound_entities
(
ir_type
*
type
)
static
void
free_compound_entities
(
ir_type
*
type
)
{
for
(
size_t
i
=
get_compound_n_members
(
type
);
i
--
>
0
;
)
free_entity
(
get_compound_member
(
type
,
i
));
}
static
void
compound_remove_member
(
ir_type
*
type
,
const
ir_entity
*
member
)
{
for
(
size_t
i
=
0
,
n
=
ARR_LEN
(
type
->
attr
.
ca
.
members
);
i
<
n
;
++
i
)
{
if
(
get_compound_member
(
type
,
i
)
==
member
)
{
for
(;
i
<
n
-
1
;
++
i
)
type
->
attr
.
ca
.
members
[
i
]
=
type
->
attr
.
ca
.
members
[
i
+
1
];
ARR_SETLEN
(
ir_entity
*
,
type
->
attr
.
ca
.
members
,
n
-
1
);
break
;
}
}
}
ir_type
*
new_type_class
(
ident
*
name
)
{
ir_type
*
res
=
new_type
(
type_class
,
NULL
);
...
...
@@ -359,7 +340,7 @@ ir_type *new_type_class(ident *name)
void
free_class_attrs
(
ir_type
*
clss
)
{
assert
(
is_Class_type
(
clss
));
compound_
free_
attrs
(
clss
);
free_
compound_attrs
(
clss
);
DEL_ARR_F
(
clss
->
attr
.
cla
.
subtypes
);
DEL_ARR_F
(
clss
->
attr
.
cla
.
supertypes
);
}
...
...
@@ -377,12 +358,6 @@ const char *get_class_name(const ir_type *clss)
return
get_id_str
(
get_class_ident
(
clss
));
}
static
void
add_class_member
(
ir_type
*
clss
,
ir_entity
*
member
)
{
assert
(
is_Class_type
(
clss
));
compound_add_member
(
clss
,
member
);
}
size_t
get_class_n_members
(
const
ir_type
*
clss
)
{
assert
(
is_Class_type
(
clss
));
...
...
@@ -401,12 +376,6 @@ size_t get_class_member_index(ir_type const *clss, ir_entity const *const mem)
return
get_compound_member_index
(
clss
,
mem
);
}
static
void
remove_class_member
(
ir_type
*
clss
,
ir_entity
*
member
)
{
assert
(
is_Class_type
(
clss
));
compound_remove_member
(
clss
,
member
);
}
void
add_class_subtype
(
ir_type
*
clss
,
ir_type
*
subtype
)
{
assert
(
is_Class_type
(
clss
));
...
...
@@ -535,12 +504,6 @@ ir_type *new_type_struct(ident *name)
return
res
;
}
void
free_struct_attrs
(
ir_type
*
strct
)
{
assert
(
is_Struct_type
(
strct
));
compound_free_attrs
(
strct
);
}
ident
*
get_struct_ident
(
const
ir_type
*
strct
)
{
assert
(
is_Struct_type
(
strct
));
...
...
@@ -561,13 +524,6 @@ size_t get_struct_n_members(const ir_type *strct)
return
get_compound_n_members
(
strct
);
}
static
void
add_struct_member
(
ir_type
*
strct
,
ir_entity
*
member
)
{
assert
(
is_Struct_type
(
strct
));
assert
(
get_type_tpop
(
get_entity_type
(
member
))
!=
type_method
);
compound_add_member
(
strct
,
member
);
}
ir_entity
*
get_struct_member
(
const
ir_type
*
strct
,
size_t
pos
)
{
assert
(
is_Struct_type
(
strct
));
...
...
@@ -580,12 +536,6 @@ size_t get_struct_member_index(ir_type const *strct, ir_entity const *const mem)
return
get_compound_member_index
(
strct
,
mem
);
}
static
void
remove_struct_member
(
ir_type
*
strct
,
ir_entity
*
member
)
{
assert
(
is_Struct_type
(
strct
));
compound_remove_member
(
strct
,
member
);
}
int
(
is_Struct_type
)(
const
ir_type
*
strct
)
{
return
is_struct_type_
(
strct
);
...
...
@@ -748,12 +698,6 @@ ir_type *new_type_union(ident *name)
return
res
;
}
void
free_union_attrs
(
ir_type
*
uni
)
{
assert
(
is_Union_type
(
uni
));
compound_free_attrs
(
uni
);
}
ident
*
get_union_ident
(
const
ir_type
*
uni
)
{
assert
(
is_Union_type
(
uni
));
...
...
@@ -774,12 +718,6 @@ size_t get_union_n_members(const ir_type *uni)
return
get_compound_n_members
(
uni
);
}
static
void
add_union_member
(
ir_type
*
uni
,
ir_entity
*
member
)
{
assert
(
is_Union_type
(
uni
));
compound_add_member
(
uni
,
member
);
}
ir_entity
*
get_union_member
(
const
ir_type
*
uni
,
size_t
pos
)
{
assert
(
is_Union_type
(
uni
));
...
...
@@ -792,12 +730,6 @@ size_t get_union_member_index(ir_type const *uni, ir_entity const *const mem)
return
get_compound_member_index
(
uni
,
mem
);
}
static
void
remove_union_member
(
ir_type
*
uni
,
ir_entity
*
member
)
{
assert
(
is_Union_type
(
uni
));
compound_remove_member
(
uni
,
member
);
}
int
(
is_Union_type
)(
const
ir_type
*
uni
)
{
return
is_union_type_
(
uni
);
...
...
@@ -1019,26 +951,25 @@ const char *get_compound_name(const ir_type *tp)
return
get_id_str
(
get_compound_ident
(
tp
));
}
void
remove_compound_member
(
ir_type
*
compound
,
ir_entity
*
entity
)
void
remove_compound_member
(
ir_type
*
type
,
ir_entity
*
member
)
{
switch
(
get_type_tpop_code
(
compound
))
{
case
tpo_class
:
remove_class_member
(
compound
,
entity
);
break
;
case
tpo_struct
:
remove_struct_member
(
compound
,
entity
);
break
;
case
tpo_union
:
remove_union_member
(
compound
,
entity
);
break
;
default:
panic
(
"argument for remove_compound_member not a compound type"
);
assert
(
is_compound_type
(
type
));
for
(
size_t
i
=
0
,
n
=
ARR_LEN
(
type
->
attr
.
ca
.
members
);
i
<
n
;
++
i
)
{
if
(
get_compound_member
(
type
,
i
)
==
member
)
{
for
(;
i
<
n
-
1
;
++
i
)
type
->
attr
.
ca
.
members
[
i
]
=
type
->
attr
.
ca
.
members
[
i
+
1
];
ARR_SETLEN
(
ir_entity
*
,
type
->
attr
.
ca
.
members
,
n
-
1
);
break
;
}
}
}
void
add_compound_member
(
ir_type
*
compound
,
ir_entity
*
entity
)
void
add_compound_member
(
ir_type
*
type
,
ir_entity
*
entity
)
{
switch
(
get_type_tpop_code
(
compound
))
{
case
tpo_class
:
add_class_member
(
compound
,
entity
);
break
;
case
tpo_struct
:
add_struct_member
(
compound
,
entity
);
break
;
case
tpo_union
:
add_union_member
(
compound
,
entity
);
break
;
default:
panic
(
"argument for add_compound_member not a compound type"
);
}
assert
(
is_compound_type
(
type
));
/* try to detect double-add */
assert
(
get_entity_type
(
entity
)
!=
type
);
ARR_APP1
(
ir_entity
*
,
type
->
attr
.
ca
.
members
,
entity
);
}
int
is_code_type
(
const
ir_type
*
tp
)
...
...
ir/tr/type_t.h
View file @
4790cf11
...
...
@@ -153,12 +153,10 @@ struct ir_type {
void
free_type_entities
(
ir_type
*
tp
);
void
free_compound_
entitie
s
(
ir_type
*
type
);
void
free_compound_
attr
s
(
ir_type
*
type
);
void
free_class_attrs
(
ir_type
*
clss
);
void
free_struct_attrs
(
ir_type
*
strct
);
void
free_method_attrs
(
ir_type
*
method
);
void
free_union_attrs
(
ir_type
*
uni
);
void
add_compound_member
(
ir_type
*
compound
,
ir_entity
*
entity
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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