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 #include "templates.h" 27 28 /* Generate an enumeration of operator codes. */ 29 30 void write_opcode_definition(struct interface *iface, FILE *fp) 31 { 32 fprintf(fp, opcode_enumeration_prologue, iface->name); 33 write_opcodes(iface->signatures, fp, iface->name); 34 fputs(opcode_enumeration_epilogue, fp); 35 } 36 37 /* Generate operator code enumeration entries. */ 38 39 void write_opcodes(struct signature *sig, FILE *fp, const char *name) 40 { 41 char *opcode; 42 43 if (sig == NULL) 44 return; 45 46 fprintf(fp, opcode_identifier, name, sig->operation); 47 48 /* Obtain any explicit opcode from the signature attributes. */ 49 50 opcode = get_opcode(sig->attributes); 51 if (opcode != NULL) 52 fprintf(fp, " = %s", opcode); 53 54 fputs(",\n", fp); 55 56 write_opcodes(sig->tail, fp, name); 57 } 58 59 /* Generate structures for messages corresponding to the signatures. */ 60 61 void write_structures(struct signature *sig, FILE *fp, struct interface *iface) 62 { 63 if (sig == NULL) 64 return; 65 66 write_structure(sig, fp, iface); 67 write_structures(sig->tail, fp, iface); 68 } 69 70 /* Generate message structures for a signature. */ 71 72 void write_structure(struct signature *sig, FILE *fp, struct interface *iface) 73 { 74 struct parameter *param = sig->parameters; 75 char *opname = get_operation_name(iface, sig), 76 *protocol = get_protocol(iface->attributes); 77 int input_words, input_items, output_words, output_items; 78 79 count_parameters(param, &input_words, &input_items, &output_words, &output_items); 80 81 /* Adjust the input words where a protocol is used as the opcode. */ 82 83 if (protocol != NULL) 84 input_words++; 85 86 /* Generate the structures for populating and interpreting messages. */ 87 88 if (input_words) 89 { 90 fprintf(fp, structure_prologue, "in", opname); 91 if (protocol != NULL) 92 fprintf(fp, structure_opcode_member, L4_WORD_TYPE); 93 write_declarations(param, IN_PARAMETER, WORD_CLASS, fp); 94 fputs(structure_epilogue, fp); 95 } 96 97 if (output_words) 98 { 99 fprintf(fp, structure_prologue, "out", opname); 100 write_declarations(param, OUT_PARAMETER, WORD_CLASS, fp); 101 fputs(structure_epilogue, fp); 102 } 103 104 /* Free allocated strings. */ 105 106 free(opname); 107 }