1.1 --- a/interface.c Thu Apr 23 23:12:19 2020 +0200
1.2 +++ b/interface.c Fri Apr 24 00:16:35 2020 +0200
1.3 @@ -51,6 +51,11 @@
1.4 write_includes_separator(iface->includes, fp);
1.5 write_includes(iface->includes, fp);
1.6
1.7 + /* Emit include for compound interface types. */
1.8 +
1.9 + if (conf.compound != NULL)
1.10 + write_include(conf.compound, "_interface_types.h", fp);
1.11 +
1.12 /* Generate interface abstractions. */
1.13
1.14 if (!cpp)
1.15 @@ -58,7 +63,16 @@
1.16 /* Define an object reference type for C. */
1.17
1.18 if (!client)
1.19 - fprintf(fp, ref_type_definition_c, L4_CAP_TYPE, name);
1.20 + {
1.21 + fprintf(fp, ref_type_definition_prologue_c);
1.22 +
1.23 + /* Provide a compound reference member for conversions. */
1.24 +
1.25 + if (conf.compound_name != NULL)
1.26 + fprintf(fp, ref_type_definition_compound_member_c, conf.compound_name);
1.27 +
1.28 + fprintf(fp, ref_type_definition_epilogue_c, L4_CAP_TYPE, name);
1.29 + }
1.30
1.31 /* Define C client signatures representing the client functions. */
1.32
2.1 --- a/program.c Thu Apr 23 23:12:19 2020 +0200
2.2 +++ b/program.c Fri Apr 24 00:16:35 2020 +0200
2.3 @@ -48,7 +48,8 @@
2.4 /* Compound interface and dispatcher files. */
2.5
2.6 FILE *compound_dispatch_fp = NULL, *compound_dispatch_header_fp = NULL,
2.7 - *compound_interface_fp = NULL, *compound_interfaces_fp = NULL;
2.8 + *compound_interface_fp = NULL, *compound_interfaces_fp = NULL,
2.9 + *compound_interface_types_fp = NULL;
2.10
2.11 /* Processed interfaces. */
2.12
2.13 @@ -141,12 +142,17 @@
2.14 compound_dirname, conf.compound);
2.15 if (compound_interfaces_fp == NULL)
2.16 return 0;
2.17 +
2.18 + compound_interface_types_fp = get_output_file(compound_interface_types_filename,
2.19 + compound_dirname, conf.compound);
2.20 + if (compound_interface_types_fp == NULL)
2.21 + return 0;
2.22 }
2.23
2.24 if (conf.routines)
2.25 {
2.26 s = (conf.language == CPP_LANGUAGE) ? server_filename_cpp :
2.27 - server_filename_c;
2.28 + server_filename_c;
2.29 compound_dispatch_fp = get_output_file(s, compound_dirname, conf.compound);
2.30 if (compound_dispatch_fp == NULL)
2.31 return 0;
2.32 @@ -194,6 +200,17 @@
2.33 if (compound_interfaces_fp != NULL)
2.34 fputs(compound_interfaces_prologue, compound_interfaces_fp);
2.35
2.36 + if (compound_interface_types_fp != NULL)
2.37 + {
2.38 + fputs(compound_interface_types_prologue, compound_interface_types_fp);
2.39 +
2.40 + /* Include reference types. */
2.41 +
2.42 + fprintf(compound_interface_types_fp, ref_type_definition_prologue_c);
2.43 + fprintf(compound_interface_types_fp, ref_type_definition_epilogue_c, L4_CAP_TYPE,
2.44 + conf.compound_name);
2.45 + }
2.46 +
2.47 return 1;
2.48 }
2.49
2.50 @@ -299,10 +316,7 @@
2.51 fprintf(compound_interface_fp, compound_interface_epilogue_c,
2.52 conf.compound_name);
2.53
2.54 - /* Include reference and object types. */
2.55 -
2.56 - fprintf(compound_interface_fp, ref_type_definition_c, L4_CAP_TYPE,
2.57 - conf.compound_name);
2.58 + /* Include object types. */
2.59
2.60 fprintf(compound_interface_fp, object_type_definition_c,
2.61 conf.compound_name, conf.compound_name, conf.compound_name);
2.62 @@ -313,6 +327,9 @@
2.63
2.64 if (compound_interfaces_fp != NULL)
2.65 fclose(compound_interfaces_fp);
2.66 +
2.67 + if (compound_interface_types_fp != NULL)
2.68 + fclose(compound_interface_types_fp);
2.69 }
2.70
2.71
3.1 --- a/templates.h Thu Apr 23 23:12:19 2020 +0200
3.2 +++ b/templates.h Fri Apr 24 00:16:35 2020 +0200
3.3 @@ -27,6 +27,7 @@
3.4 #define client_filename_cpp "%s/%s_client.cc"
3.5 #define client_header_filename "%s/%s_client.h"
3.6 #define compound_interfaces_filename "%s/%s_interfaces.h"
3.7 +#define compound_interface_types_filename "%s/%s_interface_types.h"
3.8 #define interface_filename "%s/%s_interface.h"
3.9 #define server_filename_c "%s/%s_server.c"
3.10 #define server_filename_cpp "%s/%s_server.cc"
3.11 @@ -123,7 +124,13 @@
3.12 "#pragma once\n\n"
3.13
3.14 #define compound_interface_conversion \
3.15 -"\n#define convert_to_%s(_self) (&((%s) {.ref={.ptr=_self->ref.ptr}, .iface=_self->iface->to_%s}))\n"
3.16 +"\n#define convert_to_%s(_self) (&((%s) {.ref={.compound=_self->ref}, .iface=_self->iface->to_%s}))\n"
3.17 +
3.18 +/* Compound interface types definitions. */
3.19 +
3.20 +#define compound_interface_types_prologue \
3.21 +"#pragma once\n\n" \
3.22 +"#include <l4/sys/types.h>\n"
3.23
3.24 /* Dispatch functions. */
3.25
3.26 @@ -236,8 +243,17 @@
3.27
3.28 /* Reference and object type definitions for interfaces. */
3.29
3.30 -#define ref_type_definition_c \
3.31 -"\ntypedef union { %s cap; void *ptr; } ref_%s;\n"
3.32 +#define ref_type_definition_prologue_c \
3.33 +"\ntypedef union\n" \
3.34 +"{\n"
3.35 +
3.36 +#define ref_type_definition_compound_member_c \
3.37 +" ref_%s compound;\n"
3.38 +
3.39 +#define ref_type_definition_epilogue_c \
3.40 +" %s cap;\n" \
3.41 +" void *ptr;\n" \
3.42 +"} ref_%s;\n"
3.43
3.44 #define object_type_definition_c \
3.45 "\ntypedef struct\n" \