mie: add parent pointers to region and block; two-way link between a register and its users

This commit is contained in:
2026-01-19 13:57:25 +00:00
parent da140ed0d1
commit 5e13824706
9 changed files with 43 additions and 14 deletions

View File

@@ -11,6 +11,7 @@ struct mie_register;
struct mie_block { struct mie_block {
struct mie_name b_name; struct mie_name b_name;
struct mie_region *b_parent;
MIE_VECTOR_DECLARE(struct mie_register, b_params); MIE_VECTOR_DECLARE(struct mie_register, b_params);
MIE_VECTOR_DECLARE(struct mie_op, b_ops); MIE_VECTOR_DECLARE(struct mie_op, b_ops);

View File

@@ -29,7 +29,7 @@ struct mie_op_arg {
struct mie_file_span arg_span; struct mie_file_span arg_span;
union { union {
/* only valid if F_ARG_RESOLVED is set in arg_flags */ /* only valid if F_ARG_RESOLVED is set in arg_flags */
struct mie_register *arg_value; struct mie_register_use arg_value;
/* only valid if F_ARG_RESOLVED is NOT set in arg_flags */ /* only valid if F_ARG_RESOLVED is NOT set in arg_flags */
struct mie_register_ref arg_unresolved; struct mie_register_ref arg_unresolved;
}; };

View File

@@ -5,10 +5,12 @@
#include <mie/vector.h> #include <mie/vector.h>
#include <stddef.h> #include <stddef.h>
struct mie_op;
struct mie_block; struct mie_block;
struct mie_region { struct mie_region {
struct mie_name_map *r_names; struct mie_name_map *r_names;
struct mie_op *r_parent;
MIE_VECTOR_DECLARE(struct mie_block, r_blocks); MIE_VECTOR_DECLARE(struct mie_block, r_blocks);
}; };

View File

@@ -4,6 +4,8 @@
#include <mie/name.h> #include <mie/name.h>
#include <mie/vector.h> #include <mie/vector.h>
struct mie_op;
struct mie_register;
struct mie_target_register; struct mie_target_register;
enum mie_register_flags { enum mie_register_flags {
@@ -26,6 +28,13 @@ struct mie_register_ref {
const struct mie_type *reg_type; const struct mie_type *reg_type;
}; };
/* represents a use of/resolved reference to a mie_register */
struct mie_register_use {
b_queue_entry u_entry;
struct mie_op *u_user;
struct mie_register *u_reg;
};
struct mie_register { struct mie_register {
enum mie_register_flags reg_flags; enum mie_register_flags reg_flags;
union { union {
@@ -47,6 +56,9 @@ struct mie_register {
* for which this register is a parameter * for which this register is a parameter
* if this is a BLOCK_PARAM register, this pointer is NULL */ * if this is a BLOCK_PARAM register, this pointer is NULL */
struct mie_op *reg_op; struct mie_op *reg_op;
/* list of struct mie_register_use, representing all the places
* where this register is used. */
b_queue reg_use;
}; };
extern struct mie_vector_ops mie_register_vector_ops; extern struct mie_vector_ops mie_register_vector_ops;

View File

@@ -105,9 +105,10 @@ MIE_API bool mie_parser_parse_register_list(
MIE_VECTOR_REF_PARAM(struct mie_register, out)); MIE_VECTOR_REF_PARAM(struct mie_register, out));
MIE_API bool mie_parser_parse_region( MIE_API bool mie_parser_parse_region(
struct mie_parser *ctx, struct mie_region *region); struct mie_parser *ctx, struct mie_op *parent, struct mie_region *region);
MIE_API bool mie_parser_parse_region_list( MIE_API bool mie_parser_parse_region_list(
struct mie_parser *ctx, MIE_VECTOR_REF_PARAM(struct mie_region, out)); struct mie_parser *ctx, struct mie_op *parent,
MIE_VECTOR_REF_PARAM(struct mie_region, out));
MIE_API bool mie_parser_parse_anonymous_block( MIE_API bool mie_parser_parse_anonymous_block(
struct mie_parser *ctx, struct mie_name_map *names, struct mie_parser *ctx, struct mie_name_map *names,
struct mie_block *block); struct mie_block *block);

View File

@@ -3,7 +3,7 @@
const struct mie_type *mie_op_arg_get_type(const struct mie_op_arg *arg) const struct mie_type *mie_op_arg_get_type(const struct mie_op_arg *arg)
{ {
if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) { if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) {
return arg->arg_value->reg_type; return arg->arg_value.u_reg->reg_type;
} }
return arg->arg_unresolved.reg_type; return arg->arg_unresolved.reg_type;

View File

@@ -5,5 +5,14 @@
struct mie_block *mie_region_add_block(struct mie_region *region) struct mie_block *mie_region_add_block(struct mie_region *region)
{ {
return mie_vector_emplace_back(region->r_blocks, &mie_block_vector_ops); struct mie_block *block = mie_vector_emplace_back(
region->r_blocks, &mie_block_vector_ops);
if (!block) {
return NULL;
}
block->b_parent = region;
return block;
} }

View File

@@ -759,9 +759,11 @@ bool mie_parser_parse_register_list(
return true; return true;
} }
bool mie_parser_parse_region(struct mie_parser *ctx, struct mie_region *region) bool mie_parser_parse_region(
struct mie_parser *ctx, struct mie_op *parent, struct mie_region *region)
{ {
region->r_names = mie_name_map_create(NULL); region->r_names = mie_name_map_create(NULL);
region->r_parent = parent;
if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_BRACE)) { if (!mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_BRACE)) {
return false; return false;
@@ -797,7 +799,8 @@ bool mie_parser_parse_region(struct mie_parser *ctx, struct mie_region *region)
} }
bool mie_parser_parse_region_list( bool mie_parser_parse_region_list(
struct mie_parser *ctx, MIE_VECTOR_REF_PARAM(struct mie_region, out)) struct mie_parser *ctx, struct mie_op *parent,
MIE_VECTOR_REF_PARAM(struct mie_region, out))
{ {
if (!mie_parser_check_symbol(ctx, MIE_SYM_LEFT_BRACE)) { if (!mie_parser_check_symbol(ctx, MIE_SYM_LEFT_BRACE)) {
return false; return false;
@@ -805,7 +808,7 @@ bool mie_parser_parse_region_list(
struct mie_region *region = mie_vector_ref_emplace_back(out, NULL); struct mie_region *region = mie_vector_ref_emplace_back(out, NULL);
if (!mie_parser_parse_region(ctx, region)) { if (!mie_parser_parse_region(ctx, parent, region)) {
return false; return false;
} }
@@ -820,7 +823,8 @@ bool mie_parser_parse_region_list(
struct mie_region *region = mie_vector_ref_emplace_back(out, NULL); struct mie_region *region = mie_vector_ref_emplace_back(out, NULL);
if (!mie_parser_parse_region(ctx, region)) { if (!mie_parser_parse_region(ctx, parent, region)) {
return false; return false;
} }
} }
@@ -1087,7 +1091,7 @@ static bool parse_generic_op(
if (mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_PAREN)) { if (mie_parser_parse_symbol(ctx, MIE_SYM_LEFT_PAREN)) {
mie_parser_parse_linefeed(ctx); mie_parser_parse_linefeed(ctx);
if (!mie_parser_parse_region_list( if (!mie_parser_parse_region_list(
ctx, MIE_VECTOR_REF(dest->op_regions))) { ctx, dest, MIE_VECTOR_REF(dest->op_regions))) {
return false; return false;
} }

View File

@@ -13,9 +13,9 @@ void mie_printer_print_op_arg(
const struct mie_type *arg_type = NULL; const struct mie_type *arg_type = NULL;
if (MIE_TEST_FLAGS(arg->arg_flags, MIE_OP_F_ARG_RESOLVED)) { if (MIE_TEST_FLAGS(arg->arg_flags, MIE_OP_F_ARG_RESOLVED)) {
arg_flags = arg->arg_value->reg_flags; arg_flags = arg->arg_value.u_reg->reg_flags;
arg_name = arg->arg_value->reg_name.n_str; arg_name = arg->arg_value.u_reg->reg_name.n_str;
arg_type = arg->arg_value->reg_type; arg_type = arg->arg_value.u_reg->reg_type;
} else { } else {
arg_flags = arg->arg_unresolved.reg_flags; arg_flags = arg->arg_unresolved.reg_flags;
arg_name = arg->arg_unresolved.reg_name; arg_name = arg->arg_unresolved.reg_name;
@@ -160,7 +160,7 @@ static void print_type_signature(
const struct mie_op_arg *arg = &op->op_args.items[i]; const struct mie_op_arg *arg = &op->op_args.items[i];
if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) { if (arg->arg_flags & MIE_OP_F_ARG_RESOLVED) {
type = arg->arg_value->reg_type; type = arg->arg_value.u_reg->reg_type;
} else { } else {
type = arg->arg_unresolved.reg_type; type = arg->arg_unresolved.reg_type;
} }