1 /* 2 * Structure definition. 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 "declaration.h" 25 #include "structure.h" 26 27 /* Generate an enumeration of operator codes. */ 28 29 void write_opcode_definition(struct interface *iface, FILE *fp) 30 { 31 fprintf(fp, "\nenum opcodes_%s\n{\n", iface->name); 32 write_opcodes(iface->signatures, fp, iface->name); 33 fputs("};\n", fp); 34 } 35 36 /* Generate operator code enumeration entries. */ 37 38 void write_opcodes(struct signature *sig, FILE *fp, const char *name) 39 { 40 char *opcode; 41 42 if (sig == NULL) 43 return; 44 45 fprintf(fp, " opcode_%s_%s", name, sig->operation); 46 47 /* Obtain any explicit opcode from the signature attributes. */ 48 49 opcode = get_opcode(sig->attributes); 50 if (opcode != NULL) 51 fprintf(fp, " = %s", opcode); 52 53 fputs(",\n", fp); 54 55 write_opcodes(sig->tail, fp, name); 56 } 57 58 /* Generate structures for messages corresponding to the signatures. */ 59 60 void write_structures(struct signature *sig, FILE *fp, struct interface *iface) 61 { 62 if (sig == NULL) 63 return; 64 65 write_structure(sig, fp, iface); 66 write_structures(sig->tail, fp, iface); 67 } 68 69 /* Generate message structures for a signature. */ 70 71 void write_structure(struct signature *sig, FILE *fp, struct interface *iface) 72 { 73 struct parameter *param = sig->parameters; 74 char *opname = get_operation_name(iface, sig), 75 *protocol = get_protocol(iface->attributes); 76 int input_words, input_items, output_words, output_items; 77 78 count_parameters(param, &input_words, &input_items, &output_words, &output_items); 79 80 if (input_words) 81 { 82 fprintf(fp, "\nstruct in_words_%s\n{\n", opname); 83 if (protocol != NULL) 84 fprintf(fp, " %s _op;\n", L4_WORD_TYPE); 85 write_declarations(param, IN_PARAMETER, WORD_CLASS, fp); 86 fprintf(fp, "};\n"); 87 } 88 89 if (output_words) 90 { 91 fprintf(fp, "\nstruct out_words_%s\n{\n", opname); 92 write_declarations(param, OUT_PARAMETER, WORD_CLASS, fp); 93 fprintf(fp, "};\n"); 94 } 95 96 /* Free allocated strings. */ 97 98 free(opname); 99 }