# HG changeset patch # User Paul Boddie # Date 1572631652 -3600 # Node ID 658e4c1a972029a95acbe9130384cbfbc2a27b76 # Parent e567e37edc97bf2f6f77709f66528e4ba0adc2e2 Introduced a parameter class enumeration to differentiate between words, items, and different item types. Combined structure member and variable list generation, employing the parameter class enumeration and a special "any parameter" specifier enumeration value. diff -r e567e37edc97 -r 658e4c1a9720 common.c --- a/common.c Fri Nov 01 17:20:36 2019 +0100 +++ b/common.c Fri Nov 01 19:07:32 2019 +0100 @@ -145,8 +145,7 @@ and items. */ void count_parameters(struct parameter *param, int *input_words, - int *input_items, int *output_words, - int *output_items) + int *input_items, int *output_words, int *output_items) { for (*input_words = 0, *input_items = 0, *output_words = 0, *output_items = 0; param != NULL; @@ -154,12 +153,12 @@ { if (param->specifier & IN_PARAMETER) { - if (param->item) (*input_items)++; + if (param->cls & ITEM_CLASS) (*input_items)++; else (*input_words)++; } else { - if (param->item) (*output_items)++; + if (param->cls & ITEM_CLASS) (*output_items)++; else (*output_words)++; } } diff -r e567e37edc97 -r 658e4c1a9720 idl.y --- a/idl.y Fri Nov 01 17:20:36 2019 +0100 +++ b/idl.y Fri Nov 01 19:07:32 2019 +0100 @@ -190,9 +190,9 @@ ; parameter : specifier item identifiers - { $$.specifier = $1; $$.item = $2; $$.identifiers = copy_identifier($3); } + { $$.specifier = $1; $$.cls = $2; $$.identifiers = copy_identifier($3); } | specifier identifiers - { $$.specifier = $1; $$.item = 0; $$.identifiers = copy_identifier($2); } + { $$.specifier = $1; $$.cls = WORD_CLASS; $$.identifiers = copy_identifier($2); } ; specifier : IN | INOUT | OUT ; diff -r e567e37edc97 -r 658e4c1a9720 program.c --- a/program.c Fri Nov 01 17:20:36 2019 +0100 +++ b/program.c Fri Nov 01 19:07:32 2019 +0100 @@ -150,7 +150,7 @@ for (; param != NULL; param = param->tail) { - if ((param->specifier & direction) && !param->item) + if ((param->specifier & direction) && (param->cls & WORD_CLASS)) { name = get_parameter_name(param->identifiers); @@ -177,10 +177,10 @@ for (index = 0; param != NULL; param = param->tail) { - if ((param->specifier & direction) && param->item) + if ((param->specifier & direction) && (param->cls & ITEM_CLASS)) { name = get_parameter_name(param->identifiers); - type = param->item == FPAGE_ITEM ? "page" : "capability"; + type = param->cls == FPAGE_ITEM ? "page" : "capability"; fprintf(fp, " ipc_message_import_%s(%smsg, %d, %s);\n", type, addr, index, name); @@ -199,7 +199,7 @@ for (; param != NULL; param = param->tail) { - if ((param->specifier & direction) && !param->item) + if ((param->specifier & direction) && (param->cls & WORD_CLASS)) { name = get_parameter_name(param->identifiers); deref = dereference_name(param, direction); @@ -226,10 +226,10 @@ for (; param != NULL; param = param->tail) { - if ((param->specifier & direction) && param->item) + if ((param->specifier & direction) && (param->cls & ITEM_CLASS)) { name = get_parameter_name(param->identifiers); - type = param->item == FPAGE_ITEM ? "page" : "item"; + type = param->cls == FPAGE_ITEM ? "page" : "item"; deref = dereference_name(param, direction); fprintf(fp, " ipc_message_add_%s(%smsg, %s%s);\n", @@ -857,7 +857,7 @@ /* Generate variable declarations. */ - write_variables(param, fp); + write_declarations(param, ANY_PARAMETER, ANY_CLASS, fp); /* Generate types parameterised with the qualified operation name. */ @@ -953,14 +953,14 @@ if (input_words) { fprintf(fp, "\nstruct in_words_%s\n{\n", opname); - write_structure_members(param, IN_PARAMETER, fp); + write_declarations(param, IN_PARAMETER, WORD_CLASS, fp); fprintf(fp, "};\n"); } if (output_words) { fprintf(fp, "\nstruct out_words_%s\n{\n", opname); - write_structure_members(param, OUT_PARAMETER, fp); + write_declarations(param, OUT_PARAMETER, WORD_CLASS, fp); fprintf(fp, "};\n"); } @@ -1004,9 +1004,9 @@ { /* Items must have their type identifiers restored. */ - if (param->item) + if (param->cls & ITEM_CLASS) { - type = param->item == FPAGE_ITEM ? L4_FPAGE_TYPE : L4_CAP_TYPE; + type = param->cls == FPAGE_ITEM ? L4_FPAGE_TYPE : L4_CAP_TYPE; fprintf(fp, " %s", type); } @@ -1018,26 +1018,15 @@ } } -/* Generate variable declarations for parameters. */ +/* Write structure members for word data structures or variable declarations for + parameters. */ -void write_variables(struct parameter *param, FILE *fp) +void write_declarations(struct parameter *param, enum specifier direction, + enum parameter_class cls, FILE *fp) { for (; param != NULL; param = param->tail) { - fputs(" ", fp); - write_parameter(param, fp, STRUCTURE_ROLE); - fputs(";\n", fp); - } -} - -/* Write structure members for word data. */ - -void write_structure_members(struct parameter *param, - enum specifier direction, FILE *fp) -{ - for (; param != NULL; param = param->tail) - { - if ((param->specifier & direction) && !param->item) + if ((param->specifier & direction) && (param->cls & cls)) { fputs(" ", fp); write_parameter(param, fp, STRUCTURE_ROLE); diff -r e567e37edc97 -r 658e4c1a9720 program.h --- a/program.h Fri Nov 01 17:20:36 2019 +0100 +++ b/program.h Fri Nov 01 19:07:32 2019 +0100 @@ -27,6 +27,8 @@ #define L4_CAP_TYPE "l4_cap_idx_t" #define L4_FPAGE_TYPE "l4_fpage_t" +/* Output role of a parameter. */ + enum parameter_role { SIGNATURE_ROLE, @@ -89,18 +91,16 @@ void write_structures(struct signature *sig, FILE *fp, struct interface *iface); void write_structure(struct signature *sig, FILE *fp, struct interface *iface); -void write_structure_members(struct parameter *param, - enum specifier direction, FILE *fp); +/* Parameter lists. */ + +void write_parameters(struct parameter *param, FILE *fp, enum parameter_role role); +void write_parameter(struct parameter *param, FILE *fp, enum parameter_role role); /* Operation codes. */ void write_opcodes(struct signature *sig, FILE *fp, const char *name); -/* Parameter lists. */ +/* Structure members and variable lists. */ -void write_parameters(struct parameter *param, FILE *fp, enum parameter_role role); -void write_parameter(struct parameter *param, FILE *fp, enum parameter_role role); - -/* Variable lists for parameters. */ - -void write_variables(struct parameter *param, FILE *fp); +void write_declarations(struct parameter *param, enum specifier direction, + enum parameter_class cls, FILE *fp); diff -r e567e37edc97 -r 658e4c1a9720 summary.c --- a/summary.c Fri Nov 01 17:20:36 2019 +0100 +++ b/summary.c Fri Nov 01 19:07:32 2019 +0100 @@ -85,9 +85,9 @@ /* Items must have their type identifiers restored. */ - if (param->item) + if (param->cls & ITEM_CLASS) { - type = param->item == FPAGE_ITEM ? "fpage" : "cap"; + type = param->cls == FPAGE_ITEM ? "fpage" : "cap"; printf(" %s", type); } diff -r e567e37edc97 -r 658e4c1a9720 types.h --- a/types.h Fri Nov 01 17:20:36 2019 +0100 +++ b/types.h Fri Nov 01 19:07:32 2019 +0100 @@ -28,14 +28,18 @@ IN_PARAMETER = 1, OUT_PARAMETER = 2, INOUT_PARAMETER = 3, + ANY_PARAMETER = 3, }; -/* Item values. */ +/* Data class of a parameter. */ -enum item +enum parameter_class { - CAP_ITEM = 1, - FPAGE_ITEM = 2, + WORD_CLASS = 1, + CAP_ITEM = 2, + FPAGE_ITEM = 4, + ITEM_CLASS = 6, /* all item values combined */ + ANY_CLASS = 7, /* WORD_CLASS | ITEM_CLASS */ }; /* Include declarations. */ @@ -58,8 +62,8 @@ struct parameter { - int specifier; - int item; + enum specifier specifier; + enum parameter_class cls; struct identifier *identifiers; struct parameter *tail; };