1 /* 2 * Generation of message structure access operations. 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 "common.h" 23 #include "message.h" 24 25 /* Generate a variable declaration for message word accessors. */ 26 27 void write_accessor_declaration(int input_words, int output_words, 28 char *opname, FILE *fp) 29 { 30 if (input_words) 31 fprintf(fp, " struct in_words_%s *in_words;\n", opname); 32 33 if (output_words) 34 fprintf(fp, " struct out_words_%s *out_words;\n", opname); 35 } 36 37 /* Generate a variable initialisation for message word accessors. */ 38 39 void write_accessor_initialisation(enum specifier direction, 40 enum component_role component, 41 char *opname, FILE *fp) 42 { 43 char *prefix = structure_prefix(direction); 44 char *addr = reference_message(component); 45 46 fprintf(fp, "\n %s_words = (struct %s_words_%s *)", prefix, prefix, opname); 47 48 /* When writing to the message, the accessor will reserve space. 49 When reading from the message, only words will be present. */ 50 51 if (writing_to_message(component, direction)) 52 fprintf(fp, " ipc_message_reserve_words(%smsg," 53 " sizeof(struct %s_words_%s));\n", addr, prefix, opname); 54 else 55 fprintf(fp, " ipc_message_get_word_address(%smsg, 0);\n", addr); 56 } 57 58 /* Copy values between a message and local names. */ 59 60 void write_message_access(struct parameter *param, enum component_role component, 61 enum specifier direction, enum parameter_class cls, 62 FILE *fp) 63 { 64 char *name, *access, *prefix, *addr; 65 int writing = writing_to_message(component, direction); 66 int index; 67 68 /* Establish type and variable naming or message access conventions. */ 69 70 switch (cls) 71 { 72 case WORD_CLASS: prefix = structure_prefix(direction); break; 73 case ITEM_CLASS: addr = reference_message(component); break; 74 } 75 76 /* Generate an access operation for parameters having the indicated direction, 77 and having the indicated class (word or item). */ 78 79 for (index = 0; param != NULL; param = param->tail) 80 { 81 if ((param->specifier & direction) && (param->cls & cls)) 82 { 83 name = get_parameter_name(param->identifiers); 84 access = access_name(param, component); 85 86 switch (cls) 87 { 88 /* For words, access the message structure. */ 89 90 case WORD_CLASS: 91 if (writing) 92 fprintf(fp, " %s_words->%s = %s%s;\n", prefix, name, access, name); 93 else 94 fprintf(fp, " %s%s = %s_words->%s;\n", access, name, prefix, name); 95 break; 96 97 /* For items, perform access operations. */ 98 99 case ITEM_CLASS: 100 if (writing) 101 fprintf(fp, " ipc_message_add_%s(%smsg, %s%s);\n", 102 item_type_name(param), addr, access, name); 103 else 104 fprintf(fp, " ipc_message_import_%s(%smsg, %d, %s%s);\n", 105 item_type_name(param), addr, index, access, name); 106 index++; 107 break; 108 109 default: 110 break; 111 } 112 } 113 } 114 }