+ assert(is_declaration(entity));
+ decl_modifiers_t modifiers = entity->declaration.modifiers;
+ if (modifiers & DM_PURE) {
+ /* TRUE if the declaration includes the GNU
+ __attribute__((pure)) specifier. */
+ set_entity_additional_property(irentity, mtp_property_pure);
+ }
+ if (modifiers & DM_CONST) {
+ set_entity_additional_property(irentity, mtp_property_const);
+ have_const_functions = true;
+ }
+ if (modifiers & DM_USED) {
+ /* TRUE if the declaration includes the GNU
+ __attribute__((used)) specifier. */
+ set_entity_stickyness(irentity, stickyness_sticky);
+ }
+}
+
+/**
+ * Creates an entity representing a function.
+ *
+ * @param declaration the function declaration
+ */
+static ir_entity *get_function_entity(entity_t *entity)
+{
+ assert(entity->kind == ENTITY_FUNCTION);
+ if (entity->function.entity != NULL) {
+ return entity->function.entity;
+ }
+
+ symbol_t *symbol = entity->base.symbol;
+ ident *id = new_id_from_str(symbol->string);
+
+ ir_type *global_type = get_glob_type();
+ ir_type *ir_type_method = get_ir_type(entity->declaration.type);
+ bool const has_body = entity->function.statement != NULL;
+
+ /* already an entity defined? */
+ ir_entity *irentity = entitymap_get(&entitymap, symbol);
+ if (irentity != NULL) {
+ if (get_entity_visibility(irentity) == visibility_external_allocated
+ && has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);
+ }
+ goto entity_created;
+ }
+
+ dbg_info *const dbgi = get_dbg_info(&entity->base.source_position);
+ irentity = new_d_entity(global_type, id, ir_type_method, dbgi);
+ set_entity_ld_ident(irentity, create_ld_ident(irentity, entity));
+
+ handle_gnu_attributes_ent(irentity, entity);
+
+ /* static inline => local
+ * extern inline => local
+ * inline without definition => local
+ * inline with definition => external_visible */
+ storage_class_tag_t const storage_class
+ = (storage_class_tag_t) entity->declaration.storage_class;
+ bool const is_inline = entity->function.is_inline;
+ if (is_inline && storage_class == STORAGE_CLASS_NONE && has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);
+ } else if (storage_class == STORAGE_CLASS_STATIC ||
+ (is_inline && has_body)) {
+ if (!has_body) {
+ /* this entity was declared, but is defined nowhere */
+ set_entity_peculiarity(irentity, peculiarity_description);
+ }
+ set_entity_visibility(irentity, visibility_local);
+ } else if (has_body) {
+ set_entity_visibility(irentity, visibility_external_visible);
+ } else {
+ set_entity_visibility(irentity, visibility_external_allocated);
+ }
+ set_entity_allocation(irentity, allocation_static);
+
+ /* We should check for file scope here, but as long as we compile C only
+ this is not needed. */
+ if (! firm_opt.freestanding) {
+ /* check for a known runtime function */
+ for (size_t i = 0; i < sizeof(rts_data) / sizeof(rts_data[0]); ++i) {
+ if (id != rts_idents[i])
+ continue;
+
+ /* ignore those rts functions not necessary needed for current mode */
+ if ((c_mode & rts_data[i].flags) == 0)
+ continue;
+ assert(rts_entities[rts_data[i].id] == NULL);
+ rts_entities[rts_data[i].id] = irentity;
+ }
+ }
+
+ entitymap_insert(&entitymap, symbol, irentity);
+
+entity_created:
+ entity->declaration.kind = DECLARATION_KIND_FUNCTION;
+ entity->function.entity = irentity;
+
+ return irentity;
+}
+
+/**
+ * Creates a Const node representing a constant.
+ */
+static ir_node *const_to_firm(const const_expression_t *cnst)
+{
+ dbg_info *dbgi = get_dbg_info(&cnst->base.source_position);
+ ir_mode *mode = get_ir_mode(cnst->base.type);