-static void import_entity(io_env_t *env)
-{
- long entnr = read_long(env);
- ident *name = read_ident(env);
- ident *ld_name = read_ident_null(env);
- long typenr = read_long(env);
- long ownertypenr = read_long(env);
-
- ir_type *type = get_type(env, typenr);
- ir_type *ownertype = !ownertypenr ? get_glob_type() : get_type(env, ownertypenr);
- ir_entity *entity = new_entity(ownertype, name, type);
-
- if (ld_name != NULL)
- set_entity_ld_ident(entity, ld_name);
- set_entity_offset (entity, (int) read_long(env));
- set_entity_offset_bits_remainder(entity, (unsigned char) read_long(env));
- set_entity_compiler_generated(entity, (int) read_long(env));
- set_entity_allocation (entity, read_allocation(env));
- set_entity_visibility (entity, read_visibility(env));
- set_entity_variability(entity, read_variability(env));
- set_entity_peculiarity(entity, read_peculiarity(env));
- set_entity_volatility (entity, read_volatility(env));
-
- if (get_entity_variability(entity) != variability_uninitialized &&
- get_entity_visibility(entity) != visibility_external_allocated) {
-
- if (is_compound_entity(entity)) {
- char *str = read_word(env);
- if (strcmp(str, "initializer") == 0) {
- set_entity_initializer(entity, read_initializer(env));
- } else if (strcmp(str, "noninitializer") == 0) {
- int n = (int) read_long(env);
- int i;
- for (i = 0; i < n; i++) {
- ir_entity *member = get_entity(env, read_long(env));
- ir_node *irn = get_node_or_dummy(env, read_long(env));
- add_compound_ent_value(entity, irn, member);
- }
- } else {
- parse_error(env, "expected 'initializer' or 'noninitializer', got '%s'\n", str);
- exit(1);
- }
+static void read_entity(read_env_t *env, ir_entity_kind kind)
+{
+ long entnr = read_long(env);
+ ident *name = NULL;
+ ident *ld_name = NULL;
+ ir_visibility visibility = ir_visibility_external;
+ ir_linkage linkage = IR_LINKAGE_DEFAULT;
+ ir_type *owner = NULL;
+ ir_entity *entity = NULL;
+ int compiler_generated;
+ ir_volatility volatility;
+ const char *str;
+ ir_type *type;
+
+ if (kind != IR_ENTITY_LABEL && kind != IR_ENTITY_PARAMETER) {
+ name = read_ident(env);
+ ld_name = read_ident_null(env);
+ }
+
+ visibility = read_visibility(env);
+ expect_list_begin(env);
+ while (list_has_next(env)) {
+ linkage |= read_linkage(env);
+ }
+
+ type = read_type_ref(env);
+ if (kind != IR_ENTITY_LABEL)
+ owner = read_type_ref(env);
+
+ compiler_generated = read_long(env) != 0;
+ volatility = read_volatility(env);
+
+ switch (kind) {
+ case IR_ENTITY_NORMAL:
+ entity = new_entity(owner, name, type);
+ if (ld_name != NULL)
+ set_entity_ld_ident(entity, ld_name);
+ str = read_word(env);
+ if (strcmp(str, "initializer") == 0) {
+ ir_initializer_t *initializer = read_initializer(env);
+ if (initializer != NULL)
+ set_entity_initializer(entity, initializer);
+ } else if (strcmp(str, "none") == 0) {
+ /* do nothing */
+ } else {
+ parse_error(env, "expected 'initializer' or 'none' got '%s'\n", str);
+ }
+ break;
+ case IR_ENTITY_COMPOUND_MEMBER:
+ entity = new_entity(owner, name, type);
+ if (ld_name != NULL)
+ set_entity_ld_ident(entity, ld_name);
+ set_entity_offset(entity, (int) read_long(env));
+ set_entity_offset_bits_remainder(entity, (unsigned char) read_long(env));
+ break;
+ case IR_ENTITY_METHOD:
+ entity = new_entity(owner, name, type);
+ if (ld_name != NULL)
+ set_entity_ld_ident(entity, ld_name);
+ break;
+ case IR_ENTITY_PARAMETER: {
+ char *str = read_word(env);
+ size_t parameter_number;
+ if (strcmp(str, "va_start") == 0) {
+ parameter_number = IR_VA_START_PARAMETER_NUMBER;