1.1 --- a/program.c Sat Nov 02 00:44:02 2019 +0100
1.2 +++ b/program.c Sat Nov 02 00:53:24 2019 +0100
1.3 @@ -24,6 +24,7 @@
1.4 #include "common.h"
1.5 #include "program.h"
1.6 #include "summary.h"
1.7 +#include "templates.h"
1.8
1.9 /* Program state set in the main program. */
1.10
1.11 @@ -43,88 +44,6 @@
1.12
1.13
1.14
1.15 -/* Filename definitions. */
1.16 -
1.17 -static char client_filename[] = "%s/%s_client.c";
1.18 -static char client_header_filename[] = "%s/%s_client.h";
1.19 -static char common_filename[] = "%s/%s_common.h";
1.20 -static char dispatcher_filename[] = "%s/%s_dispatch.c";
1.21 -static char dispatcher_header_filename[] = "%s/%s_dispatch.h";
1.22 -static char server_filename[] = "%s/%s_server.c";
1.23 -static char server_header_filename[] = "%s/%s_server.h";
1.24 -
1.25 -/* Prologue definitions and other templates. */
1.26 -
1.27 -static char client_prologue[] =
1.28 -"#include \"%s_client.h\"\n"
1.29 -"#include \"%s_common.h\"\n"
1.30 -"#include <ipc/message.h>\n";
1.31 -
1.32 -static char client_function_body_prologue[] =
1.33 -" ipc_message_t msg;\n"
1.34 -" long err;\n";
1.35 -
1.36 -static char client_function_body_call[] =
1.37 -"\n ipc_message_request(&msg, %s, _endp);\n\n"
1.38 -" err = l4_error(msg.tag);\n"
1.39 -" if (err)\n"
1.40 -" return err;\n";
1.41 -
1.42 -static char common_prologue[] =
1.43 -"#pragma once\n\n"
1.44 -"#include <l4/sys/types.h>\n";
1.45 -
1.46 -static char dispatcher_prologue[] =
1.47 -"#include \"common_dispatch.h\"\n\n"
1.48 -"void handle(ipc_message_t *msg, void *obj)\n"
1.49 -"{\n"
1.50 -" ipc_message_open(msg);\n"
1.51 -" dispatch(msg, obj);\n"
1.52 -" ipc_message_reply(msg);\n"
1.53 -" ipc_message_discard(msg);\n"
1.54 -"}\n\n"
1.55 -"void dispatch(ipc_message_t *msg, void *obj)\n"
1.56 -"{\n"
1.57 -" switch (l4_msgtag_label(msg->tag))\n"
1.58 -" {\n";
1.59 -
1.60 -static char dispatcher_epilogue[] =
1.61 -" default:\n"
1.62 -" ipc_message_send_error(msg, -L4_EBADPROTO);\n"
1.63 -" break;\n"
1.64 -" }\n"
1.65 -"}\n";
1.66 -
1.67 -static char dispatcher_header_prologue[] =
1.68 -"#pragma once\n\n"
1.69 -"#include <ipc/message.h>\n\n"
1.70 -"void handle(ipc_message_t *msg, void *obj);\n\n"
1.71 -"void dispatch(ipc_message_t *msg, void *obj);\n\n";
1.72 -
1.73 -static char header_prologue[] =
1.74 -"#pragma once\n\n"
1.75 -"#include <l4/sys/types.h>\n";
1.76 -
1.77 -static char server_prologue[] =
1.78 -"#include \"%s_server.h\"\n"
1.79 -"#include \"%s_common.h\"\n"
1.80 -"#include <ipc/message.h>\n";
1.81 -
1.82 -static char server_function_body_prologue[] =
1.83 -" long err;\n";
1.84 -
1.85 -static char server_function_body_call[] =
1.86 -" if (err)\n"
1.87 -" return err;\n";
1.88 -
1.89 -static char server_function_dispatcher_body_epilogue[] =
1.90 -" default:\n"
1.91 -" ipc_message_send_error(msg, -L4_EBADPROTO);\n"
1.92 -" break;\n"
1.93 -" }\n";
1.94 -
1.95 -
1.96 -
1.97 /* Copy values between a message and local names. */
1.98
1.99 static void copy_values(struct parameter *param, enum component_role component,
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/templates.h Sat Nov 02 00:53:24 2019 +0100
2.3 @@ -0,0 +1,102 @@
2.4 +/*
2.5 + * Template output.
2.6 + *
2.7 + * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk>
2.8 + *
2.9 + * This program is free software; you can redistribute it and/or
2.10 + * modify it under the terms of the GNU General Public License as
2.11 + * published by the Free Software Foundation; either version 2 of
2.12 + * the License, or (at your option) any later version.
2.13 + *
2.14 + * This program is distributed in the hope that it will be useful,
2.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.17 + * GNU General Public License for more details.
2.18 + *
2.19 + * You should have received a copy of the GNU General Public License
2.20 + * along with this program; if not, write to the Free Software
2.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
2.22 + * Boston, MA 02110-1301, USA
2.23 + */
2.24 +
2.25 +#pragma once
2.26 +
2.27 +/* Filename definitions. */
2.28 +
2.29 +#define client_filename "%s/%s_client.c"
2.30 +#define client_header_filename "%s/%s_client.h"
2.31 +#define common_filename "%s/%s_common.h"
2.32 +#define dispatcher_filename "%s/%s_dispatch.c"
2.33 +#define dispatcher_header_filename "%s/%s_dispatch.h"
2.34 +#define server_filename "%s/%s_server.c"
2.35 +#define server_header_filename "%s/%s_server.h"
2.36 +
2.37 +/* Prologue definitions and other templates. */
2.38 +
2.39 +#define client_prologue \
2.40 +"#include \"%s_client.h\"\n" \
2.41 +"#include \"%s_common.h\"\n" \
2.42 +"#include <ipc/message.h>\n"
2.43 +
2.44 +#define client_function_body_prologue \
2.45 +" ipc_message_t msg;\n" \
2.46 +" long err;\n"
2.47 +
2.48 +#define client_function_body_call \
2.49 +"\n ipc_message_request(&msg, %s, _endp);\n\n" \
2.50 +" err = l4_error(msg.tag);\n" \
2.51 +" if (err)\n" \
2.52 +" return err;\n"
2.53 +
2.54 +#define common_prologue \
2.55 +"#pragma once\n\n" \
2.56 +"#include <l4/sys/types.h>\n"
2.57 +
2.58 +#define dispatcher_prologue \
2.59 +"#include \"common_dispatch.h\"\n\n" \
2.60 +"void handle(ipc_message_t *msg, void *obj)\n" \
2.61 +"{\n" \
2.62 +" ipc_message_open(msg);\n" \
2.63 +" dispatch(msg, obj);\n" \
2.64 +" ipc_message_reply(msg);\n" \
2.65 +" ipc_message_discard(msg);\n" \
2.66 +"}\n\n" \
2.67 +"void dispatch(ipc_message_t *msg, void *obj)\n" \
2.68 +"{\n" \
2.69 +" switch (l4_msgtag_label(msg->tag))\n" \
2.70 +" {\n"
2.71 +
2.72 +#define dispatcher_epilogue \
2.73 +" default:\n" \
2.74 +" ipc_message_send_error(msg, -L4_EBADPROTO);\n" \
2.75 +" break;\n" \
2.76 +" }\n" \
2.77 +"}\n"
2.78 +
2.79 +#define dispatcher_header_prologue \
2.80 +"#pragma once\n\n" \
2.81 +"#include <ipc/message.h>\n\n" \
2.82 +"void handle(ipc_message_t *msg, void *obj);\n\n" \
2.83 +"void dispatch(ipc_message_t *msg, void *obj);\n\n"
2.84 +
2.85 +#define header_prologue \
2.86 +"#pragma once\n\n" \
2.87 +"#include <l4/sys/types.h>\n"
2.88 +
2.89 +#define server_prologue \
2.90 +"#include \"%s_server.h\"\n" \
2.91 +"#include \"%s_common.h\"\n" \
2.92 +"#include <ipc/message.h>\n"
2.93 +
2.94 +#define server_function_body_prologue \
2.95 +" long err;\n"
2.96 +
2.97 +#define server_function_body_call \
2.98 +" if (err)\n" \
2.99 +" return err;\n"
2.100 +
2.101 +#define server_function_dispatcher_body_epilogue \
2.102 +" default:\n" \
2.103 +" ipc_message_send_error(msg, -L4_EBADPROTO);\n" \
2.104 +" break;\n" \
2.105 +" }\n"