# HG changeset patch # User Paul Boddie # Date 1587810948 -7200 # Node ID 8188c8867bf1b2b8658269be4003c7cbee5a1ea6 # Parent a417fbb9597dc4e11e8f7656947c64657e878950 Introduced members in each compound interface reference type for its base types. This allows reference conversion from the compound type to each base type. diff -r a417fbb9597d -r 8188c8867bf1 interface.c --- a/interface.c Fri Apr 24 23:48:49 2020 +0200 +++ b/interface.c Sat Apr 25 12:35:48 2020 +0200 @@ -51,12 +51,6 @@ write_includes_separator(iface->includes, fp); write_includes(iface->includes, fp); - /* Emit an include for memcpy usage in the compound interface conversion - macro. */ - - if (!cpp && !client) - write_general_include("", fp); - /* Generate interface abstractions. */ if (!cpp) diff -r a417fbb9597d -r 8188c8867bf1 program.c --- a/program.c Fri Apr 24 23:48:49 2020 +0200 +++ b/program.c Sat Apr 25 12:35:48 2020 +0200 @@ -48,7 +48,8 @@ /* Compound interface and dispatcher files. */ FILE *compound_dispatch_fp = NULL, *compound_dispatch_header_fp = NULL, - *compound_interface_fp = NULL, *compound_interfaces_fp = NULL; + *compound_interface_fp = NULL, *compound_interfaces_fp = NULL, + *compound_interface_type_fp = NULL; /* Processed interfaces. */ @@ -137,6 +138,11 @@ if (compound_interface_fp == NULL) return 0; + compound_interface_type_fp = get_output_file(compound_interface_type_filename, + compound_dirname, conf.compound); + if (compound_interface_type_fp == NULL) + return 0; + compound_interfaces_fp = get_output_file(compound_interfaces_filename, compound_dirname, conf.compound); if (compound_interfaces_fp == NULL) @@ -191,6 +197,15 @@ : compound_interface_prologue_c, conf.compound, conf.compound_name); + if (compound_interface_type_fp != NULL) + { + /* Begin reference type. */ + + if (conf.language != CPP_LANGUAGE) + fprintf(compound_interface_type_fp, compound_ref_type_definition_prologue_c, + conf.compound, L4_CAP_TYPE); + } + if (compound_interfaces_fp != NULL) fputs(compound_interfaces_prologue, compound_interfaces_fp); @@ -270,6 +285,12 @@ } else fprintf(compound_interface_fp, " iface_%s *to_%s;\n", iface->name, iface->name); + + /* Include reference type. */ + + if (conf.language != CPP_LANGUAGE) + fprintf(compound_interface_type_fp, compound_ref_type_definition_member_c, + iface->name, iface->name); } void end_compound_output(void) @@ -299,10 +320,7 @@ fprintf(compound_interface_fp, compound_interface_epilogue_c, conf.compound_name); - /* Include reference and object types. */ - - fprintf(compound_interface_fp, ref_type_definition_c, L4_CAP_TYPE, - conf.compound_name); + /* Include object type. */ fprintf(compound_interface_fp, object_type_definition_c, conf.compound_name, conf.compound_name, conf.compound_name); @@ -311,6 +329,17 @@ fclose(compound_interface_fp); } + if (compound_interface_type_fp != NULL) + { + /* Complete reference type. */ + + if (conf.language != CPP_LANGUAGE) + fprintf(compound_interface_type_fp, compound_ref_type_definition_epilogue_c, + conf.compound_name); + + fclose(compound_interface_type_fp); + } + if (compound_interfaces_fp != NULL) fclose(compound_interfaces_fp); } diff -r a417fbb9597d -r 8188c8867bf1 templates.h --- a/templates.h Fri Apr 24 23:48:49 2020 +0200 +++ b/templates.h Sat Apr 25 12:35:48 2020 +0200 @@ -26,6 +26,7 @@ #define client_filename_c "%s/%s_client.c" #define client_filename_cpp "%s/%s_client.cc" #define client_header_filename "%s/%s_client.h" +#define compound_interface_type_filename "%s/%s_interface_type.h" #define compound_interfaces_filename "%s/%s_interfaces.h" #define interface_filename "%s/%s_interface.h" #define server_filename_c "%s/%s_server.c" @@ -108,7 +109,7 @@ #define compound_interface_prologue_c \ "#pragma once\n\n" \ -"#include \"%s_interfaces.h\"\n\n" \ +"#include \"%s_interface_type.h\"\n\n" \ "typedef struct\n" \ "{\n" @@ -122,12 +123,22 @@ #define compound_interfaces_prologue \ "#pragma once\n\n" -/* Convert between object types by copying the reference type value into the - temporarily allocated structure member which should appear first in the - reference type. */ +#define compound_ref_type_definition_prologue_c \ +"#pragma once\n\n" \ +"#include \n" \ +"#include \"%s_interfaces.h\"\n\n" \ +"typedef union {\n" \ +" %s cap;\n" \ +" void *ptr;\n" + +#define compound_ref_type_definition_member_c \ +" ref_%s as_%s;\n" + +#define compound_ref_type_definition_epilogue_c \ +"} ref_%s;\n" #define compound_interface_conversion \ -"\n#define convert_to_%s(_self) (memcpy(&((%s) {.iface=_self->iface->to_%s}).ref, &_self->ref, sizeof(ref_%s)))\n" +"\n#define convert_to_%s(_self) (&((%s) {.iface=_self->iface->to_%s, .ref=_self->ref.as_%s}))\n" /* Dispatch functions. */ @@ -243,9 +254,6 @@ #define ref_type_definition_c \ "\ntypedef union { %s cap; void *ptr; } ref_%s;\n" -/* Note that the conversion operation relies on the ref member appearing first. - See: compound_interface_conversion */ - #define object_type_definition_c \ "\ntypedef struct\n" \ "{\n" \