summaryrefslogtreecommitdiffhomepage
path: root/ir/tr
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-12-14 09:38:34 +0100
committerMatthias Braun <matze@braunis.de>2015-12-14 09:42:50 +0100
commitaed38c309915cf54f45cc37cca6664f9582a3893 (patch)
treeee13cb37a67efabc157beb106d1d6bf22bb92acc /ir/tr
parent859487f06ccef35726df01c0b0ac992feafb8da0 (diff)
type: Ensure visibility/linkage are set on construction
This is done by introducing a new new_global_entity() function for constructing globals/adding a visibility argument to new_alias_entity().
Diffstat (limited to 'ir/tr')
-rw-r--r--ir/tr/entity.c46
-rw-r--r--ir/tr/type.c6
2 files changed, 38 insertions, 14 deletions
diff --git a/ir/tr/entity.c b/ir/tr/entity.c
index b4a8423..f12d1fd 100644
--- a/ir/tr/entity.c
+++ b/ir/tr/entity.c
@@ -32,20 +32,22 @@ ir_entity *get_unknown_entity(void)
}
static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
- ident *name, ir_type *type)
+ ident *name, ir_type *type,
+ ir_visibility visibility)
{
assert(owner != NULL);
ir_entity *res = XMALLOCZ(ir_entity);
res->kind = k_entity;
res->name = name;
+ res->ld_name = name;
res->type = type;
res->owner = owner;
res->entity_kind = kind;
res->volatility = volatility_non_volatile;
res->aligned = align_is_aligned;
res->usage = ir_usage_unknown;
- res->visibility = ir_visibility_external;
+ res->visibility = visibility;
res->nr = get_irp_new_node_nr();
/* Remember entity in its owner. */
@@ -55,11 +57,12 @@ static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
return res;
}
-ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
+static ir_entity *new_entity_vis(ir_type *owner, ident *name, ir_type *type,
+ ir_visibility vis)
{
ir_entity *res;
if (is_Method_type(type)) {
- res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type);
+ res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, vis);
res->linkage = IR_LINKAGE_CONSTANT;
res->attr.mtd_attr.properties = get_method_additional_properties(type);
res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
@@ -67,20 +70,37 @@ ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
res->attr.mtd_attr.param_weight = NULL;
res->attr.mtd_attr.irg = NULL;
} else if (is_compound_type(owner) && !is_segment_type(owner)) {
- res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type);
+ res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type,
+ vis);
res->attr.compound_member.offset = -1;
} else {
- res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type);
+ res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, vis);
}
hook_new_entity(res);
return res;
}
+ir_entity *new_entity(ir_type *owner, ident *name, ir_type *type)
+{
+ return new_entity_vis(owner, name, type, ir_visibility_external);
+}
+
+ir_entity *new_global_entity(ir_type *segment, ident *ld_name, ir_type *type,
+ ir_visibility visibility, ir_linkage linkage)
+{
+ assert(is_segment_type(segment) || segment == irp->dummy_owner);
+ ir_entity *res = new_entity_vis(segment, ld_name, type, visibility);
+ add_entity_linkage(res, linkage);
+ hook_new_entity(res);
+ return res;
+}
+
ir_entity *new_parameter_entity(ir_type *owner, size_t pos, ir_type *type)
{
ident *name = new_id_fmt("parameter.%lu", (unsigned long)pos);
- ir_entity *res = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type);
+ ir_entity *res = intern_new_entity(owner, IR_ENTITY_PARAMETER, name, type,
+ ir_visibility_private);
res->attr.compound_member.offset = -1;
res->attr.parameter.number = pos;
hook_new_entity(res);
@@ -92,16 +112,17 @@ ir_entity *new_label_entity(ir_label_t label)
ident *name = id_unique("label_%u");
ir_type *global_type = get_glob_type();
ir_entity *res = intern_new_entity(global_type, IR_ENTITY_LABEL, name,
- get_code_type());
+ get_code_type(), ir_visibility_private);
res->attr.code_attr.label = label;
hook_new_entity(res);
return res;
}
ir_entity *new_alias_entity(ir_type *owner, ident *name, ir_entity *aliased,
- ir_type *type)
+ ir_type *type, ir_visibility visibility)
{
- ir_entity *res = intern_new_entity(owner, IR_ENTITY_ALIAS, name, type);
+ ir_entity *res = intern_new_entity(owner, IR_ENTITY_ALIAS, name, type,
+ visibility);
res->attr.alias.aliased = aliased;
hook_new_entity(res);
return res;
@@ -258,7 +279,8 @@ void set_entity_ld_ident(ir_entity *const ent, ident *const ld_ident)
ent->ld_name = ld_ident;
if (old_ident != ld_ident) {
ir_type *owner = get_entity_owner(ent);
- if (is_segment_type(owner) && !(owner->flags & tf_info)) {
+ if (is_segment_type(owner) && !(owner->flags & tf_info)
+ && get_entity_visibility(ent) != ir_visibility_private) {
pmap *globals = irp->globals;
pmap_insert(globals, old_ident, NULL);
assert(!pmap_contains(globals, ld_ident));
@@ -903,7 +925,7 @@ void ir_init_entity(ir_prog *irp)
ident *const id = new_id_from_str(UNKNOWN_ENTITY_NAME);
ir_type *const utype = get_unknown_type();
irp->unknown_entity = intern_new_entity(irp->dummy_owner, IR_ENTITY_UNKNOWN,
- id, utype);
+ id, utype, ir_visibility_private);
set_entity_visibility(irp->unknown_entity, ir_visibility_external);
set_entity_ld_ident(irp->unknown_entity, id);
hook_new_entity(irp->unknown_entity);
diff --git a/ir/tr/type.c b/ir/tr/type.c
index fda0b07..a10a993 100644
--- a/ir/tr/type.c
+++ b/ir/tr/type.c
@@ -976,7 +976,8 @@ void remove_compound_member(ir_type *type, ir_entity *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);
- if (is_segment_type(type) && !(type->flags & tf_info)) {
+ if (is_segment_type(type) && !(type->flags & tf_info)
+ && get_entity_visibility(member) != ir_visibility_private) {
pmap *globals = irp->globals;
pmap_insert(globals, get_entity_ld_ident(member), NULL);
}
@@ -992,7 +993,8 @@ void add_compound_member(ir_type *type, ir_entity *entity)
assert(get_entity_type(entity) != type);
ARR_APP1(ir_entity *, type->attr.ca.members, entity);
/* Add segment members to globals map. */
- if (is_segment_type(type) && !(type->flags & tf_info)) {
+ if (is_segment_type(type) && !(type->flags & tf_info)
+ && get_entity_visibility(entity) != ir_visibility_private) {
ident *id = get_entity_ld_ident(entity);
pmap *globals = irp->globals;
/* Globals must have unique names. */