1.1 --- a/Makefile Tue Nov 12 23:40:42 2019 +0100
1.2 +++ b/Makefile Wed Nov 13 00:17:01 2019 +0100
1.3 @@ -2,7 +2,7 @@
1.4
1.5 SOURCES = \
1.6 main.c client.c common.c declaration.c dispatch.c includes.c \
1.7 - message.c program.c server.c structure.c summary.c \
1.8 + interface.c message.c program.c server.c structure.c summary.c \
1.9
1.10 PROGRAM = idl
1.11
2.1 --- a/declaration.c Tue Nov 12 23:40:42 2019 +0100
2.2 +++ b/declaration.c Wed Nov 13 00:17:01 2019 +0100
2.3 @@ -78,6 +78,22 @@
2.4 free(opname);
2.5 }
2.6
2.7 +/* Generate signatures. */
2.8 +
2.9 +void write_signatures(struct signature *sig, FILE *fp, struct interface *iface,
2.10 + void (*write_signature)(struct signature *,
2.11 + enum signature_role role,
2.12 + FILE *, struct interface *))
2.13 +{
2.14 + if (sig == NULL)
2.15 + return;
2.16 +
2.17 + write_signature(sig, DECLARATION_ROLE, fp, iface);
2.18 + write_signatures(sig->tail, fp, iface, write_signature);
2.19 +}
2.20 +
2.21 +
2.22 +
2.23 /* Generate parameters in each function signature. */
2.24
2.25 void write_parameters(struct parameter *param, FILE *fp, enum parameter_role role)
3.1 --- a/declaration.h Tue Nov 12 23:40:42 2019 +0100
3.2 +++ b/declaration.h Wed Nov 13 00:17:01 2019 +0100
3.3 @@ -30,6 +30,10 @@
3.4 enum component_role component, FILE *fp,
3.5 struct interface *iface);
3.6
3.7 +void write_signatures(struct signature *sig, FILE *fp, struct interface *iface,
3.8 + void (*write_signature)(struct signature *,
3.9 + enum signature_role role,
3.10 + FILE *, struct interface *));
3.11 /* Parameter lists. */
3.12
3.13 void write_parameters(struct parameter *param, FILE *fp, enum parameter_role role);
4.1 --- a/includes.c Tue Nov 12 23:40:42 2019 +0100
4.2 +++ b/includes.c Wed Nov 13 00:17:01 2019 +0100
4.3 @@ -23,6 +23,8 @@
4.4
4.5
4.6
4.7 +/* Write include directives having certain forms. */
4.8 +
4.9 void write_general_include(const char *filename, FILE *fp)
4.10 {
4.11 fprintf(fp, "#include %s\n", filename);
4.12 @@ -32,3 +34,22 @@
4.13 {
4.14 fprintf(fp, "#include \"%s%s\"\n", name, suffix);
4.15 }
4.16 +
4.17 +/* Write include statements. */
4.18 +
4.19 +void write_includes(struct include *inc, FILE *fp)
4.20 +{
4.21 + if (inc == NULL)
4.22 + return;
4.23 +
4.24 + /* The list is reversed. */
4.25 +
4.26 + write_includes(inc->tail, fp);
4.27 + write_general_include(inc->filename, fp);
4.28 +}
4.29 +
4.30 +void write_includes_separator(struct include *inc, FILE *fp)
4.31 +{
4.32 + if (inc != NULL)
4.33 + fputs("\n", fp);
4.34 +}
5.1 --- a/includes.h Tue Nov 12 23:40:42 2019 +0100
5.2 +++ b/includes.h Wed Nov 13 00:17:01 2019 +0100
5.3 @@ -22,6 +22,9 @@
5.4 #pragma once
5.5
5.6 #include <stdio.h>
5.7 +#include "types.h"
5.8
5.9 void write_general_include(const char *filename, FILE *fp);
5.10 void write_include(const char *name, const char *suffix, FILE *fp);
5.11 +void write_includes(struct include *inc, FILE *fp);
5.12 +void write_includes_separator(struct include *inc, FILE *fp);
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/interface.c Wed Nov 13 00:17:01 2019 +0100
6.3 @@ -0,0 +1,70 @@
6.4 +/*
6.5 + * Generation of interface headers.
6.6 + *
6.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
6.8 + *
6.9 + * This program is free software; you can redistribute it and/or
6.10 + * modify it under the terms of the GNU General Public License as
6.11 + * published by the Free Software Foundation; either version 2 of
6.12 + * the License, or (at your option) any later version.
6.13 + *
6.14 + * This program is distributed in the hope that it will be useful,
6.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 + * GNU General Public License for more details.
6.18 + *
6.19 + * You should have received a copy of the GNU General Public License
6.20 + * along with this program; if not, write to the Free Software
6.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
6.22 + * Boston, MA 02110-1301, USA
6.23 + */
6.24 +
6.25 +#include "client.h"
6.26 +#include "common.h"
6.27 +#include "declaration.h"
6.28 +#include "includes.h"
6.29 +#include "interface.h"
6.30 +#include "server.h"
6.31 +#include "templates.h"
6.32 +
6.33 +
6.34 +
6.35 +/* Output language, set in the main program. */
6.36 +
6.37 +extern enum language output_language;
6.38 +
6.39 +
6.40 +
6.41 +/* Write the definition of an interface to the given file for use by client or
6.42 + server components. Client headers employ such definitions as do server
6.43 + interface headers, whereas server wrapper headers employ other descriptions
6.44 + of their operations. */
6.45 +
6.46 +void write_interface_definition(struct interface *iface,
6.47 + enum component_role component, FILE *fp)
6.48 +{
6.49 + int input_items = get_max_input_items(iface->signatures);
6.50 +
6.51 + /* Emit include statements. */
6.52 +
6.53 + write_includes_separator(iface->includes, fp);
6.54 + write_includes(iface->includes, fp);
6.55 +
6.56 + /* Begin any namespace. */
6.57 +
6.58 + if (output_language == CPP_LANGUAGE)
6.59 + fprintf(fp, interface_prologue_cpp, iface->name);
6.60 +
6.61 + /* Emit signatures. */
6.62 +
6.63 + write_signatures(iface->signatures, fp, iface,
6.64 + (component == CLIENT_ROLE) ? write_client_signature
6.65 + : write_server_interface_signature);
6.66 +
6.67 + /* Terminate any namespace. */
6.68 +
6.69 + if (output_language == CPP_LANGUAGE)
6.70 + fputs(interface_epilogue_cpp, fp);
6.71 +
6.72 + fprintf(fp, expected_items_definition, iface->name, input_items);
6.73 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/interface.h Wed Nov 13 00:17:01 2019 +0100
7.3 @@ -0,0 +1,30 @@
7.4 +/*
7.5 + * Generation of interface headers.
7.6 + *
7.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
7.8 + *
7.9 + * This program is free software; you can redistribute it and/or
7.10 + * modify it under the terms of the GNU General Public License as
7.11 + * published by the Free Software Foundation; either version 2 of
7.12 + * the License, or (at your option) any later version.
7.13 + *
7.14 + * This program is distributed in the hope that it will be useful,
7.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.17 + * GNU General Public License for more details.
7.18 + *
7.19 + * You should have received a copy of the GNU General Public License
7.20 + * along with this program; if not, write to the Free Software
7.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
7.22 + * Boston, MA 02110-1301, USA
7.23 + */
7.24 +
7.25 +#pragma once
7.26 +
7.27 +#include <stdio.h>
7.28 +#include "types.h"
7.29 +
7.30 +
7.31 +
7.32 +void write_interface_definition(struct interface *iface,
7.33 + enum component_role component, FILE *fp);
8.1 --- a/program.c Tue Nov 12 23:40:42 2019 +0100
8.2 +++ b/program.c Wed Nov 13 00:17:01 2019 +0100
8.3 @@ -25,6 +25,7 @@
8.4 #include "declaration.h"
8.5 #include "dispatch.h"
8.6 #include "includes.h"
8.7 +#include "interface.h"
8.8 #include "message.h"
8.9 #include "program.h"
8.10 #include "server.h"
8.11 @@ -117,12 +118,6 @@
8.12 return 1;
8.13 }
8.14
8.15 -static void write_includes_separator(struct include *inc, FILE *fp)
8.16 -{
8.17 - if (inc != NULL)
8.18 - fputs("\n", fp);
8.19 -}
8.20 -
8.21
8.22
8.23 /* Generate compound code output, if requested. */
8.24 @@ -471,31 +466,7 @@
8.25 /* Emit the headers. */
8.26
8.27 if (client_header_fp != NULL)
8.28 - {
8.29 - /* Emit include statements. */
8.30 -
8.31 - write_includes_separator(iface->includes, client_header_fp);
8.32 - write_includes(iface->includes, client_header_fp);
8.33 -
8.34 - /* Begin any namespace. */
8.35 -
8.36 - if (output_language == CPP_LANGUAGE)
8.37 - fprintf(client_header_fp, interface_prologue_cpp, iface->name);
8.38 -
8.39 - /* Emit signatures. */
8.40 -
8.41 - write_signatures(iface->signatures, client_header_fp, iface,
8.42 - write_client_signature);
8.43 -
8.44 - /* Terminate any namespace. */
8.45 -
8.46 - if (output_language == CPP_LANGUAGE)
8.47 - {
8.48 - fprintf(client_header_fp, client_interface_endpoint_declaration_cpp,
8.49 - L4_CAP_TYPE);
8.50 - fputs(interface_epilogue_cpp, client_header_fp);
8.51 - }
8.52 - }
8.53 + write_interface_definition(iface, CLIENT_ROLE, client_header_fp);
8.54
8.55 if (server_header_fp != NULL)
8.56 {
8.57 @@ -516,32 +487,7 @@
8.58 }
8.59
8.60 if (server_interface_fp != NULL)
8.61 - {
8.62 - /* Emit include statements. */
8.63 -
8.64 - write_includes_separator(iface->includes, server_interface_fp);
8.65 - write_includes(iface->includes, server_interface_fp);
8.66 -
8.67 - /* Begin any namespace. */
8.68 -
8.69 - if (output_language == CPP_LANGUAGE)
8.70 - fprintf(server_interface_fp, interface_prologue_cpp, iface->name);
8.71 -
8.72 - /* Emit signatures. */
8.73 -
8.74 - write_signatures(iface->signatures, server_interface_fp, iface,
8.75 - write_server_interface_signature);
8.76 -
8.77 - /* Terminate any namespace. */
8.78 -
8.79 - if (output_language == CPP_LANGUAGE)
8.80 - fputs(interface_epilogue_cpp, server_interface_fp);
8.81 -
8.82 - input_items = get_max_input_items(iface->signatures);
8.83 -
8.84 - fprintf(server_interface_fp, expected_items_definition,
8.85 - iface->name, max_input_items);
8.86 - }
8.87 + write_interface_definition(iface, SERVER_ROLE, server_interface_fp);
8.88
8.89 /* Emit common structures. */
8.90
8.91 @@ -562,33 +508,6 @@
8.92 }
8.93 }
8.94
8.95 -/* Write include statements. */
8.96 -
8.97 -void write_includes(struct include *inc, FILE *fp)
8.98 -{
8.99 - if (inc == NULL)
8.100 - return;
8.101 -
8.102 - /* The list is reversed. */
8.103 -
8.104 - write_includes(inc->tail, fp);
8.105 - write_general_include(inc->filename, fp);
8.106 -}
8.107 -
8.108 -/* Generate signatures. */
8.109 -
8.110 -void write_signatures(struct signature *sig, FILE *fp, struct interface *iface,
8.111 - void (*write_signature)(struct signature *,
8.112 - enum signature_role role,
8.113 - FILE *, struct interface *))
8.114 -{
8.115 - if (sig == NULL)
8.116 - return;
8.117 -
8.118 - write_signature(sig, DECLARATION_ROLE, fp, iface);
8.119 - write_signatures(sig->tail, fp, iface, write_signature);
8.120 -}
8.121 -
8.122 /* Generate functions corresponding to the signatures. */
8.123
8.124 void write_functions(struct signature *sig, FILE *fp, struct interface *iface,
9.1 --- a/program.h Tue Nov 12 23:40:42 2019 +0100
9.2 +++ b/program.h Wed Nov 13 00:17:01 2019 +0100
9.3 @@ -37,17 +37,6 @@
9.4 void write_files(struct interface *iface);
9.5 void write_interfaces(struct interface *iface);
9.6
9.7 -/* Include statements. */
9.8 -
9.9 -void write_includes(struct include *inc, FILE *fp);
9.10 -
9.11 -/* Function declarations. */
9.12 -
9.13 -void write_signatures(struct signature *sig, FILE *fp, struct interface *iface,
9.14 - void (*write_signature)(struct signature *,
9.15 - enum signature_role role,
9.16 - FILE *, struct interface *));
9.17 -
9.18 /* Function details. */
9.19
9.20 void write_functions(struct signature *sig, FILE *fp, struct interface *iface,