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
f119db24
Commit
f119db24
authored
Dec 06, 2015
by
Matthias Braun
Browse files
Get rid of last tp_op_op and the callback structure
parent
6f319bb1
Changes
3
Show whitespace changes
Inline
Side-by-side
ir/tr/tpop.c
View file @
f119db24
...
...
@@ -23,14 +23,12 @@ const tp_op *type_primitive; const tp_op *get_tpop_primitive(void) { return type
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
,
size_t
attr_size
,
const
tp_op_ops
*
ops
)
const
tp_op
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
size_t
attr_size
)
{
tp_op
*
res
=
XMALLOC
(
tp_op
);
res
->
code
=
code
;
res
->
name
=
name
;
res
->
attr_size
=
attr_size
;
res
->
ops
=
*
ops
;
return
res
;
}
...
...
@@ -39,39 +37,17 @@ void free_tpop(const tp_op *tpop)
free
((
void
*
)
tpop
);
}
static
const
tp_op_ops
/** tpop operations for class types */
class_ops
=
{
.
free_attrs
=
free_class_attrs
,
},
/** tpop operations for struct types */
struct_ops
=
{
.
free_attrs
=
free_compound_attrs
,
},
/** tpop operations for method types */
method_ops
=
{
.
free_attrs
=
free_method_attrs
,
},
/** tpop operations for union types */
union_ops
=
{
.
free_attrs
=
free_compound_attrs
,
},
null_ops
=
{
.
free_attrs
=
NULL
,
}
;
void
init_tpop
(
void
)
{
type_class
=
new_tpop
(
tpo_class
,
NEW_IDENT
(
"class"
),
sizeof
(
cls_attr
)
,
&
class_ops
);
type_struct
=
new_tpop
(
tpo_struct
,
NEW_IDENT
(
"struct"
),
sizeof
(
compound_attr
)
,
&
struct_ops
);
type_method
=
new_tpop
(
tpo_method
,
NEW_IDENT
(
"method"
),
sizeof
(
mtd_attr
)
,
&
method_ops
);
type_union
=
new_tpop
(
tpo_union
,
NEW_IDENT
(
"union"
),
sizeof
(
compound_attr
)
,
&
union_ops
);
type_array
=
new_tpop
(
tpo_array
,
NEW_IDENT
(
"array"
),
sizeof
(
arr_attr
)
,
&
null_ops
);
type_pointer
=
new_tpop
(
tpo_pointer
,
NEW_IDENT
(
"pointer"
),
sizeof
(
ptr_attr
)
,
&
null_ops
);
type_primitive
=
new_tpop
(
tpo_primitive
,
NEW_IDENT
(
"primitive"
),
0
,
&
null_ops
);
tpop_code
=
new_tpop
(
tpo_code
,
NEW_IDENT
(
"code"
),
0
,
&
null_ops
);
tpop_unknown
=
new_tpop
(
tpo_unknown
,
NEW_IDENT
(
"Unknown"
),
0
,
&
null_ops
);
type_class
=
new_tpop
(
tpo_class
,
NEW_IDENT
(
"class"
),
sizeof
(
cls_attr
)
);
type_struct
=
new_tpop
(
tpo_struct
,
NEW_IDENT
(
"struct"
),
sizeof
(
compound_attr
));
type_method
=
new_tpop
(
tpo_method
,
NEW_IDENT
(
"method"
),
sizeof
(
mtd_attr
)
);
type_union
=
new_tpop
(
tpo_union
,
NEW_IDENT
(
"union"
),
sizeof
(
compound_attr
));
type_array
=
new_tpop
(
tpo_array
,
NEW_IDENT
(
"array"
),
sizeof
(
arr_attr
)
);
type_pointer
=
new_tpop
(
tpo_pointer
,
NEW_IDENT
(
"pointer"
),
sizeof
(
ptr_attr
)
);
type_primitive
=
new_tpop
(
tpo_primitive
,
NEW_IDENT
(
"primitive"
),
0
);
tpop_code
=
new_tpop
(
tpo_code
,
NEW_IDENT
(
"code"
),
0
);
tpop_unknown
=
new_tpop
(
tpo_unknown
,
NEW_IDENT
(
"Unknown"
),
0
);
}
void
finish_tpop
(
void
)
...
...
ir/tr/tpop_t.h
View file @
f119db24
...
...
@@ -19,20 +19,11 @@
#define get_tpop_code(op) _get_tpop_code(op)
#define get_tpop_ident(op) _get_tpop_ident(op)
/**
* tp_op operations.
*/
typedef
struct
tp_op_ops
{
/** Called to free the attributes of a type. */
void
(
*
free_attrs
)(
ir_type
*
type
);
}
tp_op_ops
;
/** 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. */
tp_op_ops
ops
;
/**< tp_op operations. */
};
/**
...
...
@@ -46,11 +37,9 @@ struct tp_op {
* @param name an ident for the name of the type opcode.
* @param attr_size the size of the attributes necessary for a type with
* this opcode
* @param ops the tp_op operations for this type
* @return A new type opcode.
*/
tp_op
const
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
size_t
attr_size
,
tp_op_ops
const
*
ops
);
tp_op
const
*
new_tpop
(
tp_opcode
code
,
ident
*
name
,
size_t
attr_size
);
/**
* Free a tpop data structure.
...
...
ir/tr/type.c
View file @
f119db24
...
...
@@ -135,11 +135,28 @@ void free_type_entities(ir_type *const type)
free_compound_entities
(
type
);
}
static
void
free_type_attrs
(
ir_type
*
tp
)
static
void
free_type_attrs
(
ir_type
*
const
type
)
{
const
tp_op
*
tpop
=
get_type_tpop
(
tp
);
if
(
tpop
->
ops
.
free_attrs
)
tpop
->
ops
.
free_attrs
(
tp
);
switch
(
type
->
type_op
->
code
)
{
case
tpo_class
:
free_class_attrs
(
type
);
return
;
case
tpo_union
:
case
tpo_struct
:
free_compound_attrs
(
type
);
return
;
case
tpo_method
:
free_method_attrs
(
type
);
return
;
case
tpo_code
:
case
tpo_primitive
:
case
tpo_pointer
:
case
tpo_array
:
case
tpo_unknown
:
case
tpo_uninitialized
:
return
;
}
panic
(
"Invalid type"
);
}
void
free_type
(
ir_type
*
tp
)
...
...
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