summaryrefslogtreecommitdiffhomepage
path: root/ir/tr
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-12-14 06:55:41 +0100
committerMatthias Braun <matze@braunis.de>2015-12-14 07:23:28 +0100
commit373423a434146e5475454db33adb36bc181bae38 (patch)
treeedfd7883bf0c7fd34aeedbbcfa427beae4cb2456 /ir/tr
parente51669e4dafc624a1950f3b38c5fa1dab4e98840 (diff)
Segment types are an own kind of type now
This is cleaner than having them being class types with a tf_segment flag set.
Diffstat (limited to 'ir/tr')
-rw-r--r--ir/tr/entity.c2
-rw-r--r--ir/tr/trverify.c3
-rw-r--r--ir/tr/type.c29
-rw-r--r--ir/tr/type_t.h17
-rw-r--r--ir/tr/typewalk.c2
5 files changed, 38 insertions, 15 deletions
diff --git a/ir/tr/entity.c b/ir/tr/entity.c
index 1d91f73..0e6f721 100644
--- a/ir/tr/entity.c
+++ b/ir/tr/entity.c
@@ -66,7 +66,7 @@ ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
res->attr.mtd_attr.param_access = NULL;
res->attr.mtd_attr.param_weight = NULL;
res->attr.mtd_attr.irg = NULL;
- } else if (is_compound_type(owner) && !(owner->flags & tf_segment)) {
+ } else if (is_compound_type(owner) && !is_segment_type(owner)) {
res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type);
res->attr.compound_member.offset = -1;
} else {
diff --git a/ir/tr/trverify.c b/ir/tr/trverify.c
index 8815f31..925013e 100644
--- a/ir/tr/trverify.c
+++ b/ir/tr/trverify.c
@@ -84,7 +84,8 @@ int check_type(const ir_type *tp)
switch (get_type_opcode(tp)) {
case tpo_union:
case tpo_struct:
- case tpo_class: return check_compound_type(tp);
+ case tpo_class:
+ case tpo_segment: return check_compound_type(tp);
case tpo_primitive: return check_primitive_type(tp);
case tpo_pointer: return check_pointer_type(tp);
case tpo_array:
diff --git a/ir/tr/type.c b/ir/tr/type.c
index 5e29be3..8a72f90 100644
--- a/ir/tr/type.c
+++ b/ir/tr/type.c
@@ -61,6 +61,7 @@ const char *get_type_opcode_name(tp_opcode const opcode)
case tpo_method: return "method";
case tpo_pointer: return "pointer";
case tpo_primitive: return "primitive";
+ case tpo_segment: return "segment";
case tpo_struct: return "struct";
case tpo_uninitialized: return "uninitialized";
case tpo_union: return "union";
@@ -154,8 +155,9 @@ static void free_type_attrs(ir_type *const type)
case tpo_class:
free_class_attrs(type);
return;
- case tpo_union:
+ case tpo_segment:
case tpo_struct:
+ case tpo_union:
free_compound_attrs(type);
return;
case tpo_method:
@@ -279,7 +281,7 @@ void set_type_state(ir_type *tp, ir_type_state state)
#ifndef NDEBUG
/* Just a correctness check: */
if (state == layout_fixed && is_compound_type(tp)
- && !(tp->flags & tf_segment)) {
+ && !is_segment_type(tp)) {
for (size_t i = 0, n_mem = get_compound_n_members(tp);
i < n_mem; i++) {
ir_entity *entity = get_compound_member(tp, i);
@@ -753,14 +755,21 @@ int (is_Union_type)(const ir_type *uni)
ir_type *new_type_segment(ident *const name, type_flags const flags)
{
- ir_type *const seg = new_type_class(name);
- seg->flags |= tf_segment | flags;
- return seg;
+ ir_type *const res = new_type(tpo_segment, sizeof(compound_attr), NULL);
+ compound_init(res, name);
+ res->flags |= flags;
+ return res;
+}
+
+int (is_segment_type)(ir_type const *const type)
+{
+ return is_segment_type_(type);
}
-int is_segment_type(const ir_type *type)
+ident *get_segment_ident(ir_type const *type)
{
- return (type->flags & tf_segment) != 0;
+ assert(is_segment_type(type));
+ return type->name;
}
ir_type *new_type_array(ir_type *element_type)
@@ -1156,6 +1165,12 @@ void ir_print_type(char *buffer, size_t buffer_size, const ir_type *type)
return;
}
+ case tpo_segment: {
+ ident *id = get_segment_ident(type);
+ snprintf(buffer, buffer_size, "segment '%s'", get_id_str(id));
+ return;
+ }
+
case tpo_unknown:
snprintf(buffer, buffer_size, "unknown type");
return;
diff --git a/ir/tr/type_t.h b/ir/tr/type_t.h
index 749c4d9..af5ae54 100644
--- a/ir/tr/type_t.h
+++ b/ir/tr/type_t.h
@@ -38,6 +38,7 @@
#define is_Struct_type(strct) is_struct_type_(strct)
#define is_Method_type(method) is_method_type_(method)
#define is_Union_type(uni) is_union_type_(uni)
+#define is_segment_type(type) is_segment_type_(type)
#define is_Array_type(array) is_array_type_(array)
#define is_Pointer_type(pointer) is_pointer_type_(pointer)
#define is_Primitive_type(primitive) is_primitive_type_(primitive)
@@ -101,12 +102,11 @@ typedef enum type_flags {
tf_layout_fixed = 1U << 2, /**< Set if the layout of a type is fixed */
tf_frame_type = 1U << 3, /**< Set if this is a frame type. */
- tf_segment = 1U << 4, /**< type represents a linker segment */
- tf_global_type = 1U << 5, /**< Set only for the global type */
- tf_tls_type = 1U << 6, /**< Set only for the tls type */
- tf_info = 1U << 7, /**< infos (for example constructor, destructor pointers) */
- tf_variable_size = 1U << 8, /**< compound or array type may have variable size last element */
- tf_lowered_dw = 1U << 9, /**< hack to identify lowered doubleword params */
+ tf_global_type = 1U << 4, /**< Set only for the global type */
+ tf_tls_type = 1U << 5, /**< Set only for the tls type */
+ tf_info = 1U << 6, /**< infos (for example constructor, destructor pointers) */
+ tf_variable_size = 1U << 7, /**< compound or array type may have variable size last element */
+ tf_lowered_dw = 1U << 8, /**< hack to identify lowered doubleword params */
} type_flags;
ENUM_BITSET(type_flags)
@@ -308,6 +308,11 @@ static inline int is_union_type_(ir_type const *const type)
return get_type_opcode(type) == tpo_union;
}
+static inline int is_segment_type_(ir_type const *const type)
+{
+ return get_type_opcode(type) == tpo_segment;
+}
+
static inline int is_array_type_(ir_type const *const type)
{
return get_type_opcode(type) == tpo_array;
diff --git a/ir/tr/typewalk.c b/ir/tr/typewalk.c
index 50c8271..fcf348d 100644
--- a/ir/tr/typewalk.c
+++ b/ir/tr/typewalk.c
@@ -133,6 +133,7 @@ static void do_type_walk(ir_type *const tp, ir_entity *const ent,
case tpo_struct:
case tpo_union:
+ case tpo_segment:
for (size_t i = 0, n_mem = get_compound_n_members(tp);
i < n_mem; ++i) {
do_type_walk(NULL, get_compound_member(tp, i), pre, post, env);
@@ -361,6 +362,7 @@ void walk_types_entities(ir_type *tp, entity_walk_func *doit, void *env)
case tpo_class:
case tpo_struct:
case tpo_union:
+ case tpo_segment:
for (size_t i = 0, n = get_compound_n_members(tp); i < n; ++i)
doit(get_compound_member(tp, i), env);
return;