1 /* 2 * Generation of server dispatch functions. 3 * 4 * Copyright (C) 2019 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <stdlib.h> 23 #include "common.h" 24 #include "dispatch.h" 25 #include "templates.h" 26 27 28 29 /* Output language, set in the main program. */ 30 31 extern enum language output_language; 32 33 34 35 /* Generate a dispatch function signature for the interface. */ 36 37 void write_dispatcher_signature(FILE *fp, struct interface *iface) 38 { 39 char *type = (output_language == CPP_LANGUAGE) ? iface->name : "void"; 40 41 fprintf(fp, "\nvoid dispatch_%s(ipc_message_t *msg, %s *_self);\n", iface->name, type); 42 } 43 44 /* Generate a dispatch function for the different operations. */ 45 46 void write_dispatcher(struct signature *sig, FILE *fp, struct interface *iface) 47 { 48 char *type = (output_language == CPP_LANGUAGE) ? iface->name : "void"; 49 50 fprintf(fp, "\nvoid dispatch_%s(ipc_message_t *msg, %s *_self)\n{\n", 51 iface->name, type); 52 53 /* Interpret an operation indicator in the word data if a protocol applies to 54 the entire interface. */ 55 56 if (get_protocol(iface->attributes)) 57 fputs(" switch (ipc_message_get_word(msg, 0))\n {\n", fp); 58 else 59 fputs(" switch (l4_msgtag_label(msg->tag))\n {\n", fp); 60 61 write_dispatcher_cases(sig, fp, iface); 62 fputs(server_function_dispatcher_body_epilogue, fp); 63 64 fputs("}\n", fp); 65 } 66 67 /* Generate each dispatch possibility within an interface. */ 68 69 void write_dispatcher_cases(struct signature *sig, FILE *fp, struct interface *iface) 70 { 71 char *opcode, *opname, *protocol; 72 73 if (sig == NULL) 74 return; 75 76 opname = get_operation_name(iface, sig); 77 opcode = get_opcode_identifier(NULL, opname); 78 79 /* Generate the case and invocation. */ 80 81 fprintf(fp, dispatch_function_wrapper_case, opcode, opname); 82 83 /* Generate the other cases. */ 84 85 write_dispatcher_cases(sig->tail, fp, iface); 86 87 /* Free allocated strings. */ 88 89 free(opcode); 90 free(opname); 91 }