add is_unknown_entity(), is_unknown_type(), is_none_type()
authorMatthias Braun <matze@braunis.de>
Thu, 15 Dec 2011 13:40:15 +0000 (14:40 +0100)
committerMatthias Braun <matze@braunis.de>
Thu, 15 Dec 2011 18:38:46 +0000 (19:38 +0100)
include/libfirm/typerep.h
ir/tr/entity.c
ir/tr/entity_t.h
ir/tr/type.c

index bc13f24..154adfb 100644 (file)
@@ -695,6 +695,10 @@ FIRM_API ir_entity *unknown_entity;
 /** Returns the @link unknown_entity unknown entity @endlink. */
 FIRM_API ir_entity *get_unknown_entity(void);
 
+/** Tests whether entity @p entity is (the) unknown entity.
+ * @returns 1 if it is the unknown entity, 0 otherwise */
+FIRM_API int is_unknown_entity(const ir_entity *entity);
+
 /** @deprecated */
 typedef enum {
        allocation_automatic,
@@ -2081,6 +2085,8 @@ FIRM_API const tp_op *get_tpop_primitive(void);
 FIRM_API ir_type *firm_none_type;
 /** Returns the none type. */
 FIRM_API ir_type *get_none_type(void);
+/** Checks whether type @p type is the none type. */
+FIRM_API int is_none_type(const ir_type *type);
 /**
  * This type opcode is an auxiliary opcode dedicated to support type analyses.
  *
@@ -2135,6 +2141,8 @@ FIRM_API const tp_op *get_tpop_code_type(void);
 FIRM_API ir_type *firm_unknown_type;
 /** Returns the unknown type. */
 FIRM_API ir_type *get_unknown_type(void);
+/** Checks whether type @p type is the unknown type */
+FIRM_API int is_unknown_type(const ir_type *type);
 /**
  * This type opcode is an auxiliary opcode dedicated to support type analyses.
  *
index bd1a983..e7c74a8 100644 (file)
@@ -937,6 +937,11 @@ void set_entity_vtable_number(ir_entity *ent, unsigned vtable_number)
        ent->attr.mtd_attr.vtable_number = vtable_number;
 }
 
+int is_unknown_entity(const ir_entity *entity)
+{
+       return entity->entity_kind == IR_ENTITY_UNKNOWN;
+}
+
 int (is_entity)(const void *thing)
 {
        return _is_entity(thing);
@@ -1076,13 +1081,16 @@ int entity_has_definition(const ir_entity *entity)
 
 void ir_init_entity(void)
 {
+       ident *id = new_id_from_str(UNKNOWN_ENTITY_NAME);
+
        assert(firm_unknown_type && "Call init_type() before firm_init_entity()!");
        assert(!unknown_entity && "Call firm_init_entity() only once!");
 
-       unknown_entity = new_d_entity(NULL, new_id_from_str(UNKNOWN_ENTITY_NAME),
-                                     firm_unknown_type, NULL);
+       unknown_entity = intern_new_entity(NULL, IR_ENTITY_UNKNOWN, id,
+                                          firm_unknown_type, NULL);
        set_entity_visibility(unknown_entity, ir_visibility_external);
        set_entity_ld_ident(unknown_entity, get_entity_ident(unknown_entity));
+       hook_new_entity(unknown_entity);
 }
 
 void ir_finish_entity(void)
index 218b1f3..120679f 100644 (file)
@@ -117,6 +117,7 @@ typedef enum ir_entity_kind {
        IR_ENTITY_COMPOUND_MEMBER,
        IR_ENTITY_PARAMETER,
        IR_ENTITY_LABEL,
+       IR_ENTITY_UNKNOWN,
 } ir_entity_kind;
 
 /**
index eb37698..429c014 100644 (file)
@@ -1934,14 +1934,24 @@ void add_compound_member(ir_type *compound, ir_entity *entity)
        }
 }
 
-
-
 int is_code_type(const ir_type *tp)
 {
-       assert(tp && tp->kind == k_type);
+       assert(tp->kind == k_type);
        return tp->type_op == tpop_code;
 }
 
+int is_unknown_type(const ir_type *tp)
+{
+       assert(tp->kind == k_type);
+       return tp->type_op == tpop_unknown;
+}
+
+int is_none_type(const ir_type *tp)
+{
+       assert(tp->kind == k_type);
+       return tp->type_op == tpop_none;
+}
+
 int is_frame_type(const ir_type *tp)
 {
        return tp->flags & tf_frame_type;