Commit 7f9f6b54 authored by Moritz Kroll's avatar Moritz Kroll
Browse files

irio: Fixed handling of frame types and value types

[r25539]
parent f28c0db4
...@@ -1858,6 +1858,10 @@ void set_method_param_type(ir_type *method, int pos, ir_type *tp); ...@@ -1858,6 +1858,10 @@ void set_method_param_type(ir_type *method, int pos, ir_type *tp);
/** Returns an entity that represents the copied value argument. Only necessary /** Returns an entity that represents the copied value argument. Only necessary
for compounds passed by value. This information is constructed only on demand. */ for compounds passed by value. This information is constructed only on demand. */
ir_entity *get_method_value_param_ent(ir_type *method, int pos); ir_entity *get_method_value_param_ent(ir_type *method, int pos);
/**
* Sets the type that represents the copied value arguments.
*/
void set_method_value_param_type(ir_type *method, ir_type *tp);
/** /**
* Returns a type that represents the copied value arguments if one * Returns a type that represents the copied value arguments if one
* was allocated, else NULL. * was allocated, else NULL.
...@@ -2373,6 +2377,13 @@ int is_value_param_type(const ir_type *tp); ...@@ -2373,6 +2377,13 @@ int is_value_param_type(const ir_type *tp);
*/ */
int is_lowered_type(const ir_type *tp); int is_lowered_type(const ir_type *tp);
/**
* Makes a new value type. Value types are struct types,
* so all struct access functions work.
* Value types are not in the global list of types.
*/
ir_type *new_type_value(ident *name);
/** /**
* Makes a new frame type. Frame types are class types, * Makes a new frame type. Frame types are class types,
* so all class access functions work. * so all class access functions work.
...@@ -2559,10 +2570,8 @@ typedef void class_walk_func(ir_type *clss, void *env); ...@@ -2559,10 +2570,8 @@ typedef void class_walk_func(ir_type *clss, void *env);
* Does not touch frame types or types for value params ... */ * Does not touch frame types or types for value params ... */
void type_walk(type_walk_func *pre, type_walk_func *post, void *env); void type_walk(type_walk_func *pre, type_walk_func *post, void *env);
/** Touches every type, entity, and frame types in unspecified order. If new /** Touches every type, entity, frame type, and value param type in
* types/entities are created during the traversal these will * unspecified order. */
* be visited, too.
* Does not touch types for value params ... (??) */
void type_walk_plus_frames(type_walk_func *pre, type_walk_func *post, void *env); void type_walk_plus_frames(type_walk_func *pre, type_walk_func *post, void *env);
/** Walks over all type information reachable from an ir graph. /** Walks over all type information reachable from an ir graph.
......
...@@ -65,6 +65,7 @@ typedef enum typetag_t ...@@ -65,6 +65,7 @@ typedef enum typetag_t
tt_builtin, tt_builtin,
tt_initializer, tt_initializer,
tt_iro, tt_iro,
tt_keyword,
tt_peculiarity, tt_peculiarity,
tt_pin_state, tt_pin_state,
tt_tpo, tt_tpo,
...@@ -74,6 +75,17 @@ typedef enum typetag_t ...@@ -74,6 +75,17 @@ typedef enum typetag_t
tt_volatility tt_volatility
} typetag_t; } typetag_t;
typedef enum keyword_t
{
kw_constirg,
kw_entity,
kw_frametype,
kw_irg,
kw_valuetype,
kw_type,
kw_typegraph
} keyword_t;
typedef struct symbol_t typedef struct symbol_t
{ {
const char *str; /**< The name of this symbol. */ const char *str; /**< The name of this symbol. */
...@@ -139,6 +151,7 @@ static void symtbl_init(void) ...@@ -139,6 +151,7 @@ static void symtbl_init(void)
set_insert(symtbl, &key, sizeof(key), string_hash(s, sizeof(s)-1) + tt * 17) set_insert(symtbl, &key, sizeof(key), string_hash(s, sizeof(s)-1) + tt * 17)
#define INSERTENUM(tt, e) INSERT(#e, tt, e) #define INSERTENUM(tt, e) INSERT(#e, tt, e)
#define INSERTKEYWORD(k) INSERT(#k, tt_keyword, kw_##k)
INSERT("array", tt_tpo, tpo_array); INSERT("array", tt_tpo, tpo_array);
INSERT("class", tt_tpo, tpo_class); INSERT("class", tt_tpo, tpo_class);
...@@ -149,6 +162,14 @@ static void symtbl_init(void) ...@@ -149,6 +162,14 @@ static void symtbl_init(void)
INSERT("union", tt_tpo, tpo_union); INSERT("union", tt_tpo, tpo_union);
INSERT("Unknown", tt_tpo, tpo_unknown); INSERT("Unknown", tt_tpo, tpo_unknown);
INSERTKEYWORD(constirg);
INSERTKEYWORD(entity);
INSERTKEYWORD(frametype);
INSERTKEYWORD(irg);
INSERTKEYWORD(valuetype);
INSERTKEYWORD(type);
INSERTKEYWORD(typegraph);
#include "gen_irio_lex.inl" #include "gen_irio_lex.inl"
INSERTENUM(tt_align, align_non_aligned); INSERTENUM(tt_align, align_non_aligned);
...@@ -326,7 +347,8 @@ static void export_type(io_env_t *env, ir_type *tp) ...@@ -326,7 +347,8 @@ static void export_type(io_env_t *env, ir_type *tp)
{ {
FILE *f = env->file; FILE *f = env->file;
int i; int i;
fprintf(f, "\ttype %ld %s \"%s\" %u %u %s %s ", fprintf(f, "\t%s %ld %s \"%s\" %u %u %s %s ",
is_frame_type(tp) ? "frametype" : is_value_param_type(tp) ? "valuetype" : "type",
get_type_nr(tp), get_type_nr(tp),
get_type_tpop_name(tp), get_type_tpop_name(tp),
get_type_name(tp), get_type_name(tp),
...@@ -528,8 +550,11 @@ void ir_export(const char *filename) ...@@ -528,8 +550,11 @@ void ir_export(const char *filename)
for(i = 0; i < n_irgs; i++) for(i = 0; i < n_irgs; i++)
{ {
ir_graph *irg = get_irp_irg(i); ir_graph *irg = get_irp_irg(i);
ir_type *valuetype = get_irg_value_param_type(irg);
fprintf(env.file, "}\n\nirg %ld {\n", get_entity_nr(get_irg_entity(irg))); fprintf(env.file, "}\n\nirg %ld %ld %ld {\n", get_entity_nr(get_irg_entity(irg)),
get_type_nr(get_irg_frame_type(irg)),
valuetype == NULL ? -1 : get_type_nr(valuetype));
env.ignoreblocks = 0; env.ignoreblocks = 0;
irg_block_walk_graph(irg, NULL, export_node, &env); irg_block_walk_graph(irg, NULL, export_node, &env);
...@@ -924,7 +949,7 @@ static ir_initializer_t *read_initializer(io_env_t *env) ...@@ -924,7 +949,7 @@ static ir_initializer_t *read_initializer(io_env_t *env)
/** Reads a type description and remembers it by its id. */ /** Reads a type description and remembers it by its id. */
static void import_type(io_env_t *env) static void import_type(io_env_t *env, keyword_t kwkind)
{ {
char buf[1024]; char buf[1024];
int i; int i;
...@@ -939,6 +964,38 @@ static void import_type(io_env_t *env) ...@@ -939,6 +964,38 @@ static void import_type(io_env_t *env)
ident *id = new_id_from_str(name); ident *id = new_id_from_str(name);
const char *kindstr;
if(kwkind == kw_frametype)
{
if(symbol(tpop, tt_tpo) != tpo_class)
{
printf("Frame type must be a class type in line %i:%i\n", env->line, env->col);
skip_to(env, '\n');
return;
}
type = new_type_frame(id);
set_type_size_bytes(type, size);
kindstr = "frametype";
}
else if(kwkind == kw_valuetype)
{
if(symbol(tpop, tt_tpo) != tpo_struct)
{
printf("Value type must be a struct type in line %i:%i\n", env->line, env->col);
skip_to(env, '\n');
return;
}
type = new_type_value(id);
set_type_size_bytes(type, size);
kindstr = "valuetype";
}
else
{
switch(symbol(tpop, tt_tpo)) switch(symbol(tpop, tt_tpo))
{ {
case tpo_array: case tpo_array:
...@@ -1035,6 +1092,8 @@ static void import_type(io_env_t *env) ...@@ -1035,6 +1092,8 @@ static void import_type(io_env_t *env)
skip_to(env, '\n'); skip_to(env, '\n');
return; return;
} }
kindstr = "type";
}
set_type_alignment_bytes(type, align); set_type_alignment_bytes(type, align);
set_type_visibility(type, vis); set_type_visibility(type, vis);
...@@ -1043,7 +1102,7 @@ static void import_type(io_env_t *env) ...@@ -1043,7 +1102,7 @@ static void import_type(io_env_t *env)
ARR_APP1(ir_type *, env->fixedtypes, type); ARR_APP1(ir_type *, env->fixedtypes, type);
set_id(env, typenr, type); set_id(env, typenr, type);
printf("Insert type %s %ld\n", name, typenr); printf("Insert %s %s %ld\n", kindstr, name, typenr);
} }
/** Reads an entity description and remembers it by its id. */ /** Reads an entity description and remembers it by its id. */
...@@ -1115,13 +1174,24 @@ static int parse_typegraph(io_env_t *env) ...@@ -1115,13 +1174,24 @@ static int parse_typegraph(io_env_t *env)
// parse all types first // parse all types first
while(1) while(1)
{ {
int isframetype = 0;
kind = read_str(env); kind = read_str(env);
if(kind[0] == '}' && !kind[1]) break; if(kind[0] == '}' && !kind[1]) break;
if(!strcmp(kind, "type")) keyword_t kwkind = (keyword_t) symbol(kind, tt_keyword);
import_type(env); switch(kwkind)
else {
case kw_type:
case kw_frametype:
case kw_valuetype:
import_type(env, kwkind);
break;
default:
skip_to(env, '\n'); skip_to(env, '\n');
break;
}
} }
// now parse rest // now parse rest
...@@ -1132,14 +1202,22 @@ static int parse_typegraph(io_env_t *env) ...@@ -1132,14 +1202,22 @@ static int parse_typegraph(io_env_t *env)
kind = read_str(env); kind = read_str(env);
if(kind[0] == '}' && !kind[1]) break; if(kind[0] == '}' && !kind[1]) break;
if(!strcmp(kind, "type")) switch(symbol(kind, tt_keyword))
{
case kw_type:
case kw_frametype:
case kw_valuetype:
skip_to(env, '\n'); skip_to(env, '\n');
else if(!strcmp(kind, "entity")) break;
case kw_entity:
import_entity(env); import_entity(env);
else break;
{
default:
printf("Type graph element not supported yet: \"%s\"\n", kind); printf("Type graph element not supported yet: \"%s\"\n", kind);
skip_to(env, '\n'); skip_to(env, '\n');
break;
} }
} }
return 1; return 1;
...@@ -1306,21 +1384,34 @@ void ir_import(const char *filename) ...@@ -1306,21 +1384,34 @@ void ir_import(const char *filename)
{ {
const char *str = read_str(env); const char *str = read_str(env);
if(!*str) break; if(!*str) break;
if(!strcmp(str, "typegraph")) switch(symbol(str, tt_keyword))
{ {
if(!parse_typegraph(env)) break; case kw_typegraph:
} if(!parse_typegraph(env)) goto end;
else if(!strcmp(str, "irg")) break;
case kw_irg:
{ {
ir_graph *irg = new_ir_graph(get_entity(env, read_long(env)), 0); ir_entity *irgent = get_entity(env, read_long(env));
if(!parse_graph(env, irg)) break; long valuetypeid;
ir_graph *irg = new_ir_graph(irgent, 0);
set_irg_frame_type(irg, get_type(env, read_long(env)));
valuetypeid = read_long(env);
if(valuetypeid != -1)
set_method_value_param_type(get_entity_type(irgent),
get_type(env, valuetypeid));
if(!parse_graph(env, irg)) goto end;
break;
} }
else if(!strcmp(str, "constirg"))
{ case kw_constirg:
if(!parse_graph(env, get_const_code_irg())) break; if(!parse_graph(env, get_const_code_irg())) goto end;
break;
} }
} }
end:
n = ARR_LEN(env->fixedtypes); n = ARR_LEN(env->fixedtypes);
for(i = 0; i < n; i++) for(i = 0; i < n; i++)
set_type_state(env->fixedtypes[i], layout_fixed); set_type_state(env->fixedtypes[i], layout_fixed);
......
...@@ -1326,6 +1326,14 @@ ir_entity *get_method_value_param_ent(ir_type *method, int pos) { ...@@ -1326,6 +1326,14 @@ ir_entity *get_method_value_param_ent(ir_type *method, int pos) {
return method->attr.ma.params[pos].ent; return method->attr.ma.params[pos].ent;
} }
/*
* Sets the type that represents the copied value arguments.
*/
void set_method_value_param_type(ir_type *method, ir_type *tp) {
assert(method && (method->type_op == type_method));
method->attr.ma.value_params = tp;
}
/* /*
* Returns a type that represents the copied value arguments. * Returns a type that represents the copied value arguments.
*/ */
...@@ -2041,6 +2049,18 @@ int is_lowered_type(const ir_type *tp) { ...@@ -2041,6 +2049,18 @@ int is_lowered_type(const ir_type *tp) {
return tp->flags & tf_lowered_type; return tp->flags & tf_lowered_type;
} }
/* Makes a new value type. */
ir_type *new_type_value(ident *name) {
ir_type *res = new_type_struct(name);
res->flags |= tf_value_param_type;
/* Remove type from type list. Must be treated differently than other types. */
remove_irp_type(res);
return res;
}
/* Makes a new frame type. */ /* Makes a new frame type. */
ir_type *new_type_frame(ident *name) { ir_type *new_type_frame(ident *name) {
ir_type *res = new_type_class(name); ir_type *res = new_type_class(name);
......
...@@ -286,6 +286,10 @@ void type_walk_plus_frames(type_walk_func *pre, type_walk_func *post, void *env) ...@@ -286,6 +286,10 @@ void type_walk_plus_frames(type_walk_func *pre, type_walk_func *post, void *env)
ir_graph *irg = get_irp_irg(i); ir_graph *irg = get_irp_irg(i);
cont.typ = get_irg_frame_type(irg); cont.typ = get_irg_frame_type(irg);
do_type_walk(cont, pre, post, env); do_type_walk(cont, pre, post, env);
cont.typ = get_method_value_param_type(get_entity_type(get_irg_entity(irg)));
if(cont.typ)
do_type_walk(cont, pre, post, env);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment