1.1 --- a/interface.c Fri Apr 24 23:48:49 2020 +0200
1.2 +++ b/interface.c Sat Apr 25 12:35:48 2020 +0200
1.3 @@ -51,12 +51,6 @@
1.4 write_includes_separator(iface->includes, fp);
1.5 write_includes(iface->includes, fp);
1.6
1.7 - /* Emit an include for memcpy usage in the compound interface conversion
1.8 - macro. */
1.9 -
1.10 - if (!cpp && !client)
1.11 - write_general_include("<string.h>", fp);
1.12 -
1.13 /* Generate interface abstractions. */
1.14
1.15 if (!cpp)
2.1 --- a/program.c Fri Apr 24 23:48:49 2020 +0200
2.2 +++ b/program.c Sat Apr 25 12:35:48 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_type_fp = NULL;
2.10
2.11 /* Processed interfaces. */
2.12
2.13 @@ -137,6 +138,11 @@
2.14 if (compound_interface_fp == NULL)
2.15 return 0;
2.16
2.17 + compound_interface_type_fp = get_output_file(compound_interface_type_filename,
2.18 + compound_dirname, conf.compound);
2.19 + if (compound_interface_type_fp == NULL)
2.20 + return 0;
2.21 +
2.22 compound_interfaces_fp = get_output_file(compound_interfaces_filename,
2.23 compound_dirname, conf.compound);
2.24 if (compound_interfaces_fp == NULL)
2.25 @@ -191,6 +197,15 @@
2.26 : compound_interface_prologue_c,
2.27 conf.compound, conf.compound_name);
2.28
2.29 + if (compound_interface_type_fp != NULL)
2.30 + {
2.31 + /* Begin reference type. */
2.32 +
2.33 + if (conf.language != CPP_LANGUAGE)
2.34 + fprintf(compound_interface_type_fp, compound_ref_type_definition_prologue_c,
2.35 + conf.compound, L4_CAP_TYPE);
2.36 + }
2.37 +
2.38 if (compound_interfaces_fp != NULL)
2.39 fputs(compound_interfaces_prologue, compound_interfaces_fp);
2.40
2.41 @@ -270,6 +285,12 @@
2.42 }
2.43 else
2.44 fprintf(compound_interface_fp, " iface_%s *to_%s;\n", iface->name, iface->name);
2.45 +
2.46 + /* Include reference type. */
2.47 +
2.48 + if (conf.language != CPP_LANGUAGE)
2.49 + fprintf(compound_interface_type_fp, compound_ref_type_definition_member_c,
2.50 + iface->name, iface->name);
2.51 }
2.52
2.53 void end_compound_output(void)
2.54 @@ -299,10 +320,7 @@
2.55 fprintf(compound_interface_fp, compound_interface_epilogue_c,
2.56 conf.compound_name);
2.57
2.58 - /* Include reference and object types. */
2.59 -
2.60 - fprintf(compound_interface_fp, ref_type_definition_c, L4_CAP_TYPE,
2.61 - conf.compound_name);
2.62 + /* Include object type. */
2.63
2.64 fprintf(compound_interface_fp, object_type_definition_c,
2.65 conf.compound_name, conf.compound_name, conf.compound_name);
2.66 @@ -311,6 +329,17 @@
2.67 fclose(compound_interface_fp);
2.68 }
2.69
2.70 + if (compound_interface_type_fp != NULL)
2.71 + {
2.72 + /* Complete reference type. */
2.73 +
2.74 + if (conf.language != CPP_LANGUAGE)
2.75 + fprintf(compound_interface_type_fp, compound_ref_type_definition_epilogue_c,
2.76 + conf.compound_name);
2.77 +
2.78 + fclose(compound_interface_type_fp);
2.79 + }
2.80 +
2.81 if (compound_interfaces_fp != NULL)
2.82 fclose(compound_interfaces_fp);
2.83 }
3.1 --- a/templates.h Fri Apr 24 23:48:49 2020 +0200
3.2 +++ b/templates.h Sat Apr 25 12:35:48 2020 +0200
3.3 @@ -26,6 +26,7 @@
3.4 #define client_filename_c "%s/%s_client.c"
3.5 #define client_filename_cpp "%s/%s_client.cc"
3.6 #define client_header_filename "%s/%s_client.h"
3.7 +#define compound_interface_type_filename "%s/%s_interface_type.h"
3.8 #define compound_interfaces_filename "%s/%s_interfaces.h"
3.9 #define interface_filename "%s/%s_interface.h"
3.10 #define server_filename_c "%s/%s_server.c"
3.11 @@ -108,7 +109,7 @@
3.12
3.13 #define compound_interface_prologue_c \
3.14 "#pragma once\n\n" \
3.15 -"#include \"%s_interfaces.h\"\n\n" \
3.16 +"#include \"%s_interface_type.h\"\n\n" \
3.17 "typedef struct\n" \
3.18 "{\n"
3.19
3.20 @@ -122,12 +123,22 @@
3.21 #define compound_interfaces_prologue \
3.22 "#pragma once\n\n"
3.23
3.24 -/* Convert between object types by copying the reference type value into the
3.25 - temporarily allocated structure member which should appear first in the
3.26 - reference type. */
3.27 +#define compound_ref_type_definition_prologue_c \
3.28 +"#pragma once\n\n" \
3.29 +"#include <l4/sys/types.h>\n" \
3.30 +"#include \"%s_interfaces.h\"\n\n" \
3.31 +"typedef union {\n" \
3.32 +" %s cap;\n" \
3.33 +" void *ptr;\n"
3.34 +
3.35 +#define compound_ref_type_definition_member_c \
3.36 +" ref_%s as_%s;\n"
3.37 +
3.38 +#define compound_ref_type_definition_epilogue_c \
3.39 +"} ref_%s;\n"
3.40
3.41 #define compound_interface_conversion \
3.42 -"\n#define convert_to_%s(_self) (memcpy(&((%s) {.iface=_self->iface->to_%s}).ref, &_self->ref, sizeof(ref_%s)))\n"
3.43 +"\n#define convert_to_%s(_self) (&((%s) {.iface=_self->iface->to_%s, .ref=_self->ref.as_%s}))\n"
3.44
3.45 /* Dispatch functions. */
3.46
3.47 @@ -243,9 +254,6 @@
3.48 #define ref_type_definition_c \
3.49 "\ntypedef union { %s cap; void *ptr; } ref_%s;\n"
3.50
3.51 -/* Note that the conversion operation relies on the ref member appearing first.
3.52 - See: compound_interface_conversion */
3.53 -
3.54 #define object_type_definition_c \
3.55 "\ntypedef struct\n" \
3.56 "{\n" \