Ole Troan | 1b1ccad | 2019-10-25 18:30:40 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 2 | |
| 3 | import argparse |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 4 | import inspect |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 5 | import os |
| 6 | import sys |
| 7 | import logging |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 8 | from vapi_json_parser import ( |
| 9 | Field, |
| 10 | Struct, |
| 11 | Enum, |
| 12 | Union, |
| 13 | Message, |
| 14 | JsonParser, |
| 15 | SimpleType, |
| 16 | StructType, |
| 17 | Alias, |
| 18 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 19 | |
| 20 | |
| 21 | class CField(Field): |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 22 | def get_c_name(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 23 | return "vapi_type_%s" % self.name |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 24 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 25 | def get_c_def(self): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 26 | if self.type.get_c_name() == "string": |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 27 | if self.len: |
| 28 | return "u8 %s[%d];" % (self.name, self.len) |
| 29 | else: |
| 30 | return "vl_api_string_t %s;" % (self.name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 31 | else: |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 32 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 33 | return "%s %s[%d];" % (self.type.get_c_name(), self.name, self.len) |
Ole Troan | e5ff5a3 | 2019-08-23 22:55:18 +0200 | [diff] [blame] | 34 | else: |
| 35 | return "%s %s;" % (self.type.get_c_name(), self.name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 36 | |
| 37 | def get_swap_to_be_code(self, struct, var): |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 38 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 39 | if self.len > 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 40 | return ( |
| 41 | "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }" |
| 42 | " while(0);" |
| 43 | % (self.len, self.type.get_swap_to_be_code(struct, "%s[i]" % var)) |
| 44 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 45 | else: |
| 46 | if self.nelem_field.needs_byte_swap(): |
| 47 | nelem_field = "%s(%s%s)" % ( |
| 48 | self.nelem_field.type.get_swap_to_host_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 49 | struct, |
| 50 | self.nelem_field.name, |
| 51 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 52 | else: |
| 53 | nelem_field = "%s%s" % (struct, self.nelem_field.name) |
| 54 | return ( |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 55 | "do { unsigned i; for (i = 0; i < %s; ++i) { %s } }" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 56 | " while(0);" |
| 57 | % ( |
| 58 | nelem_field, |
| 59 | self.type.get_swap_to_be_code(struct, "%s[i]" % var), |
| 60 | ) |
| 61 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 62 | return self.type.get_swap_to_be_code(struct, "%s" % var) |
| 63 | |
| 64 | def get_swap_to_host_code(self, struct, var): |
Paul Vinciguerra | d7a32eb | 2020-05-01 10:09:58 -0400 | [diff] [blame] | 65 | if self.len is not None and type(self.len) != dict: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 66 | if self.len > 0: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 67 | return ( |
| 68 | "do { unsigned i; for (i = 0; i < %d; ++i) { %s } }" |
| 69 | " while(0);" |
| 70 | % (self.len, self.type.get_swap_to_host_code(struct, "%s[i]" % var)) |
| 71 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 72 | else: |
| 73 | # nelem_field already swapped to host here... |
| 74 | return ( |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 75 | "do { unsigned i; for (i = 0; i < %s%s; ++i) { %s } }" |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | " while(0);" |
| 77 | % ( |
| 78 | struct, |
| 79 | self.nelem_field.name, |
| 80 | self.type.get_swap_to_host_code(struct, "%s[i]" % var), |
| 81 | ) |
| 82 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 83 | return self.type.get_swap_to_host_code(struct, "%s" % var) |
| 84 | |
| 85 | def needs_byte_swap(self): |
| 86 | return self.type.needs_byte_swap() |
| 87 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 88 | def get_vla_parameter_name(self, path): |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 89 | return "%s_%s_array_size" % ("_".join(path), self.name) |
| 90 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 91 | def get_vla_field_name(self, path): |
| 92 | return ".".join(path + [self.nelem_field.name]) |
| 93 | |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 94 | def get_alloc_vla_param_names(self, path): |
| 95 | if self.is_vla(): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 96 | result = [self.get_vla_parameter_name(path)] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 97 | else: |
| 98 | result = [] |
| 99 | if self.type.has_vla(): |
| 100 | t = self.type.get_alloc_vla_param_names(path + [self.name]) |
| 101 | result.extend(t) |
| 102 | return result |
| 103 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 104 | def get_vla_calc_size_code(self, prefix, path, is_alloc): |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 105 | if self.is_vla(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 106 | result = [ |
| 107 | "sizeof(%s.%s[0]) * %s" |
| 108 | % ( |
| 109 | ".".join([prefix] + path), |
| 110 | self.name, |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 111 | ( |
| 112 | self.get_vla_parameter_name(path) |
| 113 | if is_alloc |
| 114 | else "%s.%s" % (prefix, self.get_vla_field_name(path)) |
| 115 | ), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 116 | ) |
| 117 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 118 | else: |
| 119 | result = [] |
| 120 | if self.type.has_vla(): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 121 | t = self.type.get_vla_calc_size_code(prefix, path + [self.name], is_alloc) |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 122 | result.extend(t) |
| 123 | return result |
| 124 | |
| 125 | def get_vla_assign_code(self, prefix, path): |
| 126 | result = [] |
| 127 | if self.is_vla(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 128 | result.append( |
| 129 | "%s.%s = %s" |
| 130 | % ( |
| 131 | ".".join([prefix] + path), |
| 132 | self.nelem_field.name, |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 133 | self.get_vla_parameter_name(path), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 134 | ) |
| 135 | ) |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 136 | if self.type.has_vla(): |
| 137 | t = self.type.get_vla_assign_code(prefix, path + [self.name]) |
| 138 | result.extend(t) |
| 139 | return result |
| 140 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 141 | |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 142 | class CAlias(CField): |
| 143 | def get_c_name(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 144 | return "vapi_type_%s" % self.name |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 145 | |
| 146 | def get_c_def(self): |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 147 | if self.len is not None: |
Klement Sekera | 173e20c | 2018-12-12 12:57:32 +0100 | [diff] [blame] | 148 | return "typedef %s vapi_type_%s[%d];" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 149 | self.type.get_c_name(), |
| 150 | self.name, |
| 151 | self.len, |
| 152 | ) |
Ole Troan | 8c8acc0 | 2018-11-27 10:05:23 +0100 | [diff] [blame] | 153 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 154 | return "typedef %s vapi_type_%s;" % (self.type.get_c_name(), self.name) |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 155 | |
| 156 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 157 | class CStruct(Struct): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 158 | def get_c_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 159 | return "\n".join( |
| 160 | [ |
| 161 | "typedef struct __attribute__((__packed__)) {\n%s" |
| 162 | % ("\n".join([" %s" % x.get_c_def() for x in self.fields])), |
| 163 | "} %s;" % self.get_c_name(), |
| 164 | ] |
| 165 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 166 | |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 167 | def get_vla_assign_code(self, prefix, path): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 168 | return [ |
| 169 | x |
| 170 | for f in self.fields |
| 171 | if f.has_vla() |
| 172 | for x in f.get_vla_assign_code(prefix, path) |
| 173 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 174 | |
| 175 | def get_alloc_vla_param_names(self, path): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 176 | return [ |
| 177 | x |
| 178 | for f in self.fields |
| 179 | if f.has_vla() |
| 180 | for x in f.get_alloc_vla_param_names(path) |
| 181 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 182 | |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 183 | def get_vla_calc_size_code(self, prefix, path, is_alloc): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 184 | return [ |
| 185 | x |
| 186 | for f in self.fields |
| 187 | if f.has_vla() |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 188 | for x in f.get_vla_calc_size_code(prefix, path, is_alloc) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 189 | ] |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 190 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 191 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 192 | class CSimpleType(SimpleType): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 193 | swap_to_be_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 194 | "i16": "htobe16", |
| 195 | "u16": "htobe16", |
| 196 | "i32": "htobe32", |
| 197 | "u32": "htobe32", |
| 198 | "i64": "htobe64", |
| 199 | "u64": "htobe64", |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | swap_to_host_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 203 | "i16": "be16toh", |
| 204 | "u16": "be16toh", |
| 205 | "i32": "be32toh", |
| 206 | "u32": "be32toh", |
| 207 | "i64": "be64toh", |
| 208 | "u64": "be64toh", |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 211 | __packed = "__attribute__((packed))" |
| 212 | pack_dict = { |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 213 | "i8": __packed, |
| 214 | "u8": __packed, |
| 215 | "i16": __packed, |
| 216 | "u16": __packed, |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 219 | def get_c_name(self): |
| 220 | return self.name |
| 221 | |
| 222 | def get_swap_to_be_func_name(self): |
| 223 | return self.swap_to_be_dict[self.name] |
| 224 | |
| 225 | def get_swap_to_host_func_name(self): |
| 226 | return self.swap_to_host_dict[self.name] |
| 227 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 228 | def get_packed_string(self): |
| 229 | return self.pack_dict[self.name] |
| 230 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 231 | def get_swap_to_be_code(self, struct, var, cast=None): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 232 | x = "%s%s" % (struct, var) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 233 | return "%s = %s%s(%s);" % ( |
| 234 | x, |
| 235 | "(%s)" % cast if cast else "", |
| 236 | self.get_swap_to_be_func_name(), |
| 237 | x, |
| 238 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 239 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 240 | def get_swap_to_host_code(self, struct, var, cast=None): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 241 | x = "%s%s" % (struct, var) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 242 | return "%s = %s%s(%s);" % ( |
| 243 | x, |
| 244 | "(%s)" % cast if cast else "", |
| 245 | self.get_swap_to_host_func_name(), |
| 246 | x, |
| 247 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 248 | |
| 249 | def needs_byte_swap(self): |
| 250 | try: |
| 251 | self.get_swap_to_host_func_name() |
| 252 | return True |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 253 | except KeyError: |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 254 | pass |
| 255 | return False |
| 256 | |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 257 | def get_packed(self): |
| 258 | return self.pack_dict.get(self.name, "") |
| 259 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 260 | |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 261 | class CEnum(Enum): |
| 262 | def get_c_name(self): |
| 263 | return "vapi_enum_%s" % self.name |
| 264 | |
| 265 | def get_c_def(self): |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 266 | return "typedef enum {\n%s\n} %s %s;" % ( |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 267 | "\n".join([" %s = %s," % (i, j) for i, j in self.value_pairs]), |
Neale Ranns | b5c0d35 | 2020-04-22 16:06:45 +0000 | [diff] [blame] | 268 | self.type.get_packed(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 269 | self.get_c_name(), |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 270 | ) |
| 271 | |
| 272 | def needs_byte_swap(self): |
| 273 | return self.type.needs_byte_swap() |
| 274 | |
| 275 | def get_swap_to_be_code(self, struct, var): |
| 276 | return self.type.get_swap_to_be_code(struct, var, self.get_c_name()) |
| 277 | |
| 278 | def get_swap_to_host_code(self, struct, var): |
| 279 | return self.type.get_swap_to_host_code(struct, var, self.get_c_name()) |
| 280 | |
| 281 | |
| 282 | class CUnion(Union): |
| 283 | def get_c_name(self): |
| 284 | return "vapi_union_%s" % self.name |
| 285 | |
| 286 | def get_c_def(self): |
| 287 | return "typedef union {\n%s\n} %s;" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 288 | "\n".join([" %s %s;" % (i.get_c_name(), j) for i, j in self.type_pairs]), |
| 289 | self.get_c_name(), |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 290 | ) |
| 291 | |
| 292 | def needs_byte_swap(self): |
| 293 | return False |
| 294 | |
| 295 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 296 | class CStructType(StructType, CStruct): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 297 | def get_c_name(self): |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 298 | if self.name == "vl_api_string_t": |
| 299 | return "vl_api_string_t" |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 300 | return "vapi_type_%s" % self.name |
| 301 | |
| 302 | def get_swap_to_be_func_name(self): |
| 303 | return "%s_hton" % self.get_c_name() |
| 304 | |
| 305 | def get_swap_to_host_func_name(self): |
| 306 | return "%s_ntoh" % self.get_c_name() |
| 307 | |
| 308 | def get_swap_to_be_func_decl(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 309 | return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name()) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 310 | |
| 311 | def get_swap_to_be_func_def(self): |
| 312 | return "%s\n{\n%s\n}" % ( |
| 313 | self.get_swap_to_be_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 314 | "\n".join( |
| 315 | [ |
| 316 | " %s" % p.get_swap_to_be_code("msg->", "%s" % p.name) |
| 317 | for p in self.fields |
| 318 | if p.needs_byte_swap() |
| 319 | ] |
| 320 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 321 | ) |
| 322 | |
| 323 | def get_swap_to_host_func_decl(self): |
| 324 | return "void %s(%s *msg)" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 325 | self.get_swap_to_host_func_name(), |
| 326 | self.get_c_name(), |
| 327 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 328 | |
| 329 | def get_swap_to_host_func_def(self): |
| 330 | return "%s\n{\n%s\n}" % ( |
| 331 | self.get_swap_to_host_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 332 | "\n".join( |
| 333 | [ |
| 334 | " %s" % p.get_swap_to_host_code("msg->", "%s" % p.name) |
| 335 | for p in self.fields |
| 336 | if p.needs_byte_swap() |
| 337 | ] |
| 338 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 339 | ) |
| 340 | |
| 341 | def get_swap_to_be_code(self, struct, var): |
| 342 | return "%s(&%s%s);" % (self.get_swap_to_be_func_name(), struct, var) |
| 343 | |
| 344 | def get_swap_to_host_code(self, struct, var): |
| 345 | return "%s(&%s%s);" % (self.get_swap_to_host_func_name(), struct, var) |
| 346 | |
| 347 | def needs_byte_swap(self): |
| 348 | for f in self.fields: |
| 349 | if f.needs_byte_swap(): |
| 350 | return True |
| 351 | return False |
| 352 | |
| 353 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 354 | class CMessage(Message): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 355 | def __init__(self, logger, definition, json_parser): |
| 356 | super(CMessage, self).__init__(logger, definition, json_parser) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 357 | self.payload_members = [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 358 | " %s" % p.get_c_def() for p in self.fields if p.type != self.header |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 359 | ] |
| 360 | |
| 361 | def has_payload(self): |
| 362 | return len(self.payload_members) > 0 |
| 363 | |
| 364 | def get_msg_id_name(self): |
| 365 | return "vapi_msg_id_%s" % self.name |
| 366 | |
| 367 | def get_c_name(self): |
| 368 | return "vapi_msg_%s" % self.name |
| 369 | |
| 370 | def get_payload_struct_name(self): |
| 371 | return "vapi_payload_%s" % self.name |
| 372 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 373 | def get_alloc_func_name(self): |
| 374 | return "vapi_alloc_%s" % self.name |
| 375 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 376 | def get_alloc_vla_param_names(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 377 | return [ |
| 378 | x |
| 379 | for f in self.fields |
| 380 | if f.has_vla() |
| 381 | for x in f.get_alloc_vla_param_names([]) |
| 382 | ] |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 383 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 384 | def get_alloc_func_decl(self): |
| 385 | return "%s* %s(struct vapi_ctx_s *ctx%s)" % ( |
| 386 | self.get_c_name(), |
| 387 | self.get_alloc_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 388 | "".join([", size_t %s" % n for n in self.get_alloc_vla_param_names()]), |
| 389 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 390 | |
| 391 | def get_alloc_func_def(self): |
| 392 | extra = [] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 393 | if self.header.has_field("client_index"): |
| 394 | extra.append(" msg->header.client_index = vapi_get_client_index(ctx);") |
| 395 | if self.header.has_field("context"): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 396 | extra.append(" msg->header.context = 0;") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 397 | return "\n".join( |
| 398 | [ |
| 399 | "%s" % self.get_alloc_func_decl(), |
| 400 | "{", |
| 401 | " %s *msg = NULL;" % self.get_c_name(), |
| 402 | " const size_t size = sizeof(%s)%s;" |
| 403 | % ( |
| 404 | self.get_c_name(), |
| 405 | "".join( |
| 406 | [ |
| 407 | " + %s" % x |
| 408 | for f in self.fields |
| 409 | if f.has_vla() |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 410 | for x in f.get_vla_calc_size_code( |
| 411 | "msg->payload", [], is_alloc=True |
| 412 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 413 | ] |
| 414 | ), |
| 415 | ), |
| 416 | " /* cast here required to play nicely with C++ world ... */", |
| 417 | " msg = (%s*)vapi_msg_alloc(ctx, size);" % self.get_c_name(), |
| 418 | " if (!msg) {", |
| 419 | " return NULL;", |
| 420 | " }", |
| 421 | ] |
| 422 | + extra |
| 423 | + [ |
| 424 | " msg->header._vl_msg_id = vapi_lookup_vl_msg_id(ctx, %s);" |
| 425 | % self.get_msg_id_name(), |
| 426 | "".join( |
| 427 | [ |
| 428 | " %s;\n" % line |
| 429 | for f in self.fields |
| 430 | if f.has_vla() |
| 431 | for line in f.get_vla_assign_code("msg->payload", []) |
| 432 | ] |
| 433 | ), |
| 434 | " return msg;", |
| 435 | "}", |
| 436 | ] |
| 437 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 438 | |
| 439 | def get_calc_msg_size_func_name(self): |
| 440 | return "vapi_calc_%s_msg_size" % self.name |
| 441 | |
| 442 | def get_calc_msg_size_func_decl(self): |
| 443 | return "uword %s(%s *msg)" % ( |
| 444 | self.get_calc_msg_size_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 445 | self.get_c_name(), |
| 446 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 447 | |
| 448 | def get_calc_msg_size_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 449 | return "\n".join( |
| 450 | [ |
| 451 | "%s" % self.get_calc_msg_size_func_decl(), |
| 452 | "{", |
| 453 | " return sizeof(*msg)%s;" |
| 454 | % "".join( |
| 455 | [ |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 456 | " + %s" % x |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 457 | for f in self.fields |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 458 | if f.has_vla() |
| 459 | for x in f.get_vla_calc_size_code( |
| 460 | "msg->payload", [], is_alloc=False |
| 461 | ) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 462 | ] |
| 463 | ), |
| 464 | "}", |
| 465 | ] |
| 466 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 467 | |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 468 | def get_verify_msg_size_func_name(self): |
| 469 | return f"vapi_verify_{self.name}_msg_size" |
| 470 | |
| 471 | def get_verify_msg_size_func_decl(self): |
| 472 | return "int %s(%s *msg, uword buf_size)" % ( |
| 473 | self.get_verify_msg_size_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 474 | self.get_c_name(), |
| 475 | ) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 476 | |
| 477 | def get_verify_msg_size_func_def(self): |
| 478 | return inspect.cleandoc( |
| 479 | f""" |
| 480 | {self.get_verify_msg_size_func_decl()} |
| 481 | {{ |
| 482 | if (sizeof({self.get_c_name()}) > buf_size) |
| 483 | {{ |
| 484 | VAPI_ERR("Truncated '{self.name}' msg received, received %lu" |
| 485 | "bytes, expected %lu bytes.", buf_size, |
| 486 | sizeof({self.get_c_name()})); |
| 487 | return -1; |
| 488 | }} |
| 489 | if ({self.get_calc_msg_size_func_name()}(msg) > buf_size) |
| 490 | {{ |
| 491 | VAPI_ERR("Truncated '{self.name}' msg received, received %lu" |
| 492 | "bytes, expected %lu bytes.", buf_size, |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 493 | {self.get_calc_msg_size_func_name()}(msg)); |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 494 | return -1; |
| 495 | }} |
| 496 | return 0; |
| 497 | }} |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 498 | """ |
| 499 | ) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 500 | |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 501 | def get_c_def(self): |
| 502 | if self.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 503 | return "\n".join( |
| 504 | [ |
| 505 | "typedef struct __attribute__ ((__packed__)) {", |
| 506 | "%s " % "\n".join(self.payload_members), |
| 507 | "} %s;" % self.get_payload_struct_name(), |
| 508 | "", |
| 509 | "typedef struct __attribute__ ((__packed__)) {", |
| 510 | ( |
| 511 | " %s %s;" % (self.header.get_c_name(), self.fields[0].name) |
| 512 | if self.header is not None |
| 513 | else "" |
| 514 | ), |
| 515 | " %s payload;" % self.get_payload_struct_name(), |
| 516 | "} %s;" % self.get_c_name(), |
| 517 | ] |
| 518 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 519 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 520 | return "\n".join( |
| 521 | [ |
| 522 | "typedef struct __attribute__ ((__packed__)) {", |
| 523 | ( |
| 524 | " %s %s;" % (self.header.get_c_name(), self.fields[0].name) |
| 525 | if self.header is not None |
| 526 | else "" |
| 527 | ), |
| 528 | "} %s;" % self.get_c_name(), |
| 529 | ] |
| 530 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 531 | |
| 532 | def get_swap_payload_to_host_func_name(self): |
| 533 | return "%s_payload_ntoh" % self.get_c_name() |
| 534 | |
| 535 | def get_swap_payload_to_be_func_name(self): |
| 536 | return "%s_payload_hton" % self.get_c_name() |
| 537 | |
| 538 | def get_swap_payload_to_host_func_decl(self): |
| 539 | return "void %s(%s *payload)" % ( |
| 540 | self.get_swap_payload_to_host_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 541 | self.get_payload_struct_name(), |
| 542 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 543 | |
| 544 | def get_swap_payload_to_be_func_decl(self): |
| 545 | return "void %s(%s *payload)" % ( |
| 546 | self.get_swap_payload_to_be_func_name(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 547 | self.get_payload_struct_name(), |
| 548 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 549 | |
| 550 | def get_swap_payload_to_be_func_def(self): |
| 551 | return "%s\n{\n%s\n}" % ( |
| 552 | self.get_swap_payload_to_be_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 553 | "\n".join( |
| 554 | [ |
| 555 | " %s" % p.get_swap_to_be_code("payload->", "%s" % p.name) |
| 556 | for p in self.fields |
| 557 | if p.needs_byte_swap() and p.type != self.header |
| 558 | ] |
| 559 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 560 | ) |
| 561 | |
| 562 | def get_swap_payload_to_host_func_def(self): |
| 563 | return "%s\n{\n%s\n}" % ( |
| 564 | self.get_swap_payload_to_host_func_decl(), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 565 | "\n".join( |
| 566 | [ |
| 567 | " %s" % p.get_swap_to_host_code("payload->", "%s" % p.name) |
| 568 | for p in self.fields |
| 569 | if p.needs_byte_swap() and p.type != self.header |
| 570 | ] |
| 571 | ), |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 572 | ) |
| 573 | |
| 574 | def get_swap_to_host_func_name(self): |
| 575 | return "%s_ntoh" % self.get_c_name() |
| 576 | |
| 577 | def get_swap_to_be_func_name(self): |
| 578 | return "%s_hton" % self.get_c_name() |
| 579 | |
| 580 | def get_swap_to_host_func_decl(self): |
| 581 | return "void %s(%s *msg)" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 582 | self.get_swap_to_host_func_name(), |
| 583 | self.get_c_name(), |
| 584 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 585 | |
| 586 | def get_swap_to_be_func_decl(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 587 | return "void %s(%s *msg)" % (self.get_swap_to_be_func_name(), self.get_c_name()) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 588 | |
| 589 | def get_swap_to_be_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 590 | return "\n".join( |
| 591 | [ |
| 592 | "%s" % self.get_swap_to_be_func_decl(), |
| 593 | "{", |
| 594 | ( |
| 595 | ' VAPI_DBG("Swapping `%s\'@%%p to big endian", msg);' |
| 596 | % self.get_c_name() |
| 597 | ), |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 598 | ( |
| 599 | " %s(&msg->header);" % self.header.get_swap_to_be_func_name() |
| 600 | if self.header is not None |
| 601 | else "" |
| 602 | ), |
| 603 | ( |
| 604 | " %s(&msg->payload);" % self.get_swap_payload_to_be_func_name() |
| 605 | if self.has_payload() |
| 606 | else "" |
| 607 | ), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 608 | "}", |
| 609 | ] |
| 610 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 611 | |
| 612 | def get_swap_to_host_func_def(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 613 | return "\n".join( |
| 614 | [ |
| 615 | "%s" % self.get_swap_to_host_func_decl(), |
| 616 | "{", |
| 617 | ( |
| 618 | ' VAPI_DBG("Swapping `%s\'@%%p to host byte order", msg);' |
| 619 | % self.get_c_name() |
| 620 | ), |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 621 | ( |
| 622 | " %s(&msg->header);" % self.header.get_swap_to_host_func_name() |
| 623 | if self.header is not None |
| 624 | else "" |
| 625 | ), |
| 626 | ( |
| 627 | " %s(&msg->payload);" % self.get_swap_payload_to_host_func_name() |
| 628 | if self.has_payload() |
| 629 | else "" |
| 630 | ), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 631 | "}", |
| 632 | ] |
| 633 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 634 | |
| 635 | def get_op_func_name(self): |
| 636 | return "vapi_%s" % self.name |
| 637 | |
| 638 | def get_op_func_decl(self): |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 639 | stream_param_lines = [] |
| 640 | if self.has_stream_msg: |
| 641 | stream_param_lines = [ |
| 642 | "vapi_error_e (*details_callback)(struct vapi_ctx_s *ctx", |
| 643 | " void *callback_ctx", |
| 644 | " vapi_error_e rv", |
| 645 | " bool is_last", |
| 646 | " %s *details)" |
| 647 | % self.stream_msg.get_payload_struct_name(), |
| 648 | "void *details_callback_ctx", |
| 649 | ] |
| 650 | |
| 651 | return "vapi_error_e %s(%s)" % ( |
| 652 | self.get_op_func_name(), |
| 653 | ",\n ".join( |
| 654 | [ |
| 655 | "struct vapi_ctx_s *ctx", |
| 656 | "%s *msg" % self.get_c_name(), |
| 657 | "vapi_error_e (*reply_callback)(struct vapi_ctx_s *ctx", |
| 658 | " void *callback_ctx", |
| 659 | " vapi_error_e rv", |
| 660 | " bool is_last", |
| 661 | " %s *reply)" |
| 662 | % self.reply.get_payload_struct_name(), |
| 663 | ] |
| 664 | + [ |
| 665 | "void *reply_callback_ctx", |
| 666 | ] |
| 667 | + stream_param_lines |
| 668 | ), |
| 669 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 670 | |
| 671 | def get_op_func_def(self): |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 672 | param_check_lines = [" if (!msg || !reply_callback) {"] |
| 673 | store_request_lines = [ |
| 674 | " vapi_store_request(ctx, req_context, %s, %s, " |
| 675 | % ( |
| 676 | self.reply.get_msg_id_name(), |
| 677 | "VAPI_REQUEST_DUMP" if self.reply_is_stream else "VAPI_REQUEST_REG", |
| 678 | ), |
| 679 | " (vapi_cb_t)reply_callback, reply_callback_ctx);", |
| 680 | ] |
| 681 | if self.has_stream_msg: |
| 682 | param_check_lines = [ |
| 683 | " if (!msg || !reply_callback || !details_callback) {" |
| 684 | ] |
| 685 | store_request_lines = [ |
| 686 | f" vapi_store_request(ctx, req_context, {self.stream_msg.get_msg_id_name()}, VAPI_REQUEST_STREAM, ", |
| 687 | " (vapi_cb_t)details_callback, details_callback_ctx);", |
| 688 | f" vapi_store_request(ctx, req_context, {self.reply.get_msg_id_name()}, VAPI_REQUEST_REG, ", |
| 689 | " (vapi_cb_t)reply_callback, reply_callback_ctx);", |
| 690 | ] |
| 691 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 692 | return "\n".join( |
| 693 | [ |
| 694 | "%s" % self.get_op_func_decl(), |
| 695 | "{", |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 696 | ] |
| 697 | + param_check_lines |
| 698 | + [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 699 | " return VAPI_EINVAL;", |
| 700 | " }", |
| 701 | " if (vapi_is_nonblocking(ctx) && vapi_requests_full(ctx)) {", |
| 702 | " return VAPI_EAGAIN;", |
| 703 | " }", |
| 704 | " vapi_error_e rv;", |
| 705 | " if (VAPI_OK != (rv = vapi_producer_lock (ctx))) {", |
| 706 | " return rv;", |
| 707 | " }", |
| 708 | " u32 req_context = vapi_gen_req_context(ctx);", |
| 709 | " msg->header.context = req_context;", |
| 710 | " %s(msg);" % self.get_swap_to_be_func_name(), |
| 711 | ( |
| 712 | " if (VAPI_OK == (rv = vapi_send_with_control_ping " |
| 713 | "(ctx, msg, req_context))) {" |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 714 | if (self.reply_is_stream and not self.has_stream_msg) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 715 | else " if (VAPI_OK == (rv = vapi_send (ctx, msg))) {" |
| 716 | ), |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 717 | ] |
| 718 | + store_request_lines |
| 719 | + [ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 720 | " if (VAPI_OK != vapi_producer_unlock (ctx)) {", |
| 721 | " abort (); /* this really shouldn't happen */", |
| 722 | " }", |
| 723 | " if (vapi_is_nonblocking(ctx)) {", |
| 724 | " rv = VAPI_OK;", |
| 725 | " } else {", |
| 726 | " rv = vapi_dispatch(ctx);", |
| 727 | " }", |
| 728 | " } else {", |
| 729 | " %s(msg);" % self.get_swap_to_host_func_name(), |
| 730 | " if (VAPI_OK != vapi_producer_unlock (ctx)) {", |
| 731 | " abort (); /* this really shouldn't happen */", |
| 732 | " }", |
| 733 | " }", |
| 734 | " return rv;", |
| 735 | "}", |
| 736 | "", |
| 737 | ] |
| 738 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 739 | |
| 740 | def get_event_cb_func_decl(self): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 741 | if not self.is_reply and not self.is_event: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 742 | raise Exception("Cannot register event callback for non-reply message") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 743 | if self.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 744 | return "\n".join( |
| 745 | [ |
| 746 | "void vapi_set_%s_event_cb (" % self.get_c_name(), |
| 747 | " struct vapi_ctx_s *ctx, ", |
| 748 | ( |
| 749 | " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, " |
| 750 | "void *callback_ctx, %s *payload)," |
| 751 | % self.get_payload_struct_name() |
| 752 | ), |
| 753 | " void *callback_ctx)", |
| 754 | ] |
| 755 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 756 | else: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 757 | return "\n".join( |
| 758 | [ |
| 759 | "void vapi_set_%s_event_cb (" % self.get_c_name(), |
| 760 | " struct vapi_ctx_s *ctx, ", |
| 761 | " vapi_error_e (*callback)(struct vapi_ctx_s *ctx, " |
| 762 | "void *callback_ctx),", |
| 763 | " void *callback_ctx)", |
| 764 | ] |
| 765 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 766 | |
| 767 | def get_event_cb_func_def(self): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 768 | if not self.is_reply and not self.is_event: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 769 | raise Exception("Cannot register event callback for non-reply function") |
| 770 | return "\n".join( |
| 771 | [ |
| 772 | "%s" % self.get_event_cb_func_decl(), |
| 773 | "{", |
| 774 | ( |
| 775 | " vapi_set_event_cb(ctx, %s, (vapi_event_cb)callback, " |
| 776 | "callback_ctx);" % self.get_msg_id_name() |
| 777 | ), |
| 778 | "}", |
| 779 | ] |
| 780 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 781 | |
| 782 | def get_c_metadata_struct_name(self): |
| 783 | return "__vapi_metadata_%s" % self.name |
| 784 | |
| 785 | def get_c_constructor(self): |
| 786 | has_context = False |
| 787 | if self.header is not None: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 788 | has_context = self.header.has_field("context") |
| 789 | return "\n".join( |
| 790 | [ |
| 791 | "static void __attribute__((constructor)) __vapi_constructor_%s()" |
| 792 | % self.name, |
| 793 | "{", |
| 794 | ' static const char name[] = "%s";' % self.name, |
| 795 | ' static const char name_with_crc[] = "%s_%s";' |
| 796 | % (self.name, self.crc[2:]), |
| 797 | " static vapi_message_desc_t %s = {" |
| 798 | % self.get_c_metadata_struct_name(), |
| 799 | " name,", |
| 800 | " sizeof(name) - 1,", |
| 801 | " name_with_crc,", |
| 802 | " sizeof(name_with_crc) - 1,", |
| 803 | " true," if has_context else " false,", |
Dave Wallace | 940a70f | 2024-04-03 12:31:42 -0400 | [diff] [blame] | 804 | ( |
| 805 | " offsetof(%s, context)," % self.header.get_c_name() |
| 806 | if has_context |
| 807 | else " 0," |
| 808 | ), |
| 809 | ( |
| 810 | (" offsetof(%s, payload)," % self.get_c_name()) |
| 811 | if self.has_payload() |
| 812 | else " VAPI_INVALID_MSG_ID," |
| 813 | ), |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 814 | " (verify_msg_size_fn_t)%s," % self.get_verify_msg_size_func_name(), |
| 815 | " (generic_swap_fn_t)%s," % self.get_swap_to_be_func_name(), |
| 816 | " (generic_swap_fn_t)%s," % self.get_swap_to_host_func_name(), |
| 817 | " VAPI_INVALID_MSG_ID,", |
| 818 | " };", |
| 819 | "", |
| 820 | " %s = vapi_register_msg(&%s);" |
| 821 | % (self.get_msg_id_name(), self.get_c_metadata_struct_name()), |
| 822 | ' VAPI_DBG("Assigned msg id %%d to %s", %s);' |
| 823 | % (self.name, self.get_msg_id_name()), |
| 824 | "}", |
| 825 | ] |
| 826 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 827 | |
| 828 | |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 829 | def emit_definition(parser, json_file, emitted, o): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 830 | if o in emitted: |
| 831 | return |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 832 | if o.name in ("msg_header1_t", "msg_header2_t"): |
| 833 | return |
| 834 | if hasattr(o, "depends"): |
| 835 | for x in o.depends: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 836 | emit_definition(parser, json_file, emitted, x) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 837 | if hasattr(o, "reply"): |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 838 | emit_definition(parser, json_file, emitted, o.reply) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 839 | if hasattr(o, "stream_msg"): |
| 840 | emit_definition(parser, json_file, emitted, o.stream_msg) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 841 | if hasattr(o, "get_c_def"): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 842 | if ( |
| 843 | o not in parser.enums_by_json[json_file] |
| 844 | and o not in parser.types_by_json[json_file] |
| 845 | and o not in parser.unions_by_json[json_file] |
| 846 | and o.name not in parser.messages_by_json[json_file] |
| 847 | and o not in parser.aliases_by_json[json_file] |
| 848 | ): |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 849 | return |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 850 | guard = "defined_%s" % o.get_c_name() |
| 851 | print("#ifndef %s" % guard) |
| 852 | print("#define %s" % guard) |
| 853 | print("%s" % o.get_c_def()) |
| 854 | print("") |
| 855 | function_attrs = "static inline " |
| 856 | if o.name in parser.messages_by_json[json_file]: |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 857 | if o.has_payload(): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 858 | print("%s%s" % (function_attrs, o.get_swap_payload_to_be_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 859 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 860 | print("%s%s" % (function_attrs, o.get_swap_payload_to_host_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 861 | print("") |
| 862 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 863 | print("") |
| 864 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
| 865 | print("") |
| 866 | print("%s%s" % (function_attrs, o.get_calc_msg_size_func_def())) |
Klement Sekera | a25ce96 | 2021-11-15 15:52:37 +0100 | [diff] [blame] | 867 | print("") |
| 868 | print("%s%s" % (function_attrs, o.get_verify_msg_size_func_def())) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 869 | if not o.is_reply and not o.is_event and not o.is_stream: |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 870 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 871 | print("%s%s" % (function_attrs, o.get_alloc_func_def())) |
| 872 | print("") |
| 873 | print("%s%s" % (function_attrs, o.get_op_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 874 | print("") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 875 | print("%s" % o.get_c_constructor()) |
Stanislav Zaikin | 56777b9 | 2022-07-21 19:07:50 +0200 | [diff] [blame] | 876 | if (o.is_reply or o.is_event) and not o.is_stream: |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 877 | print("") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 878 | print("%s%s;" % (function_attrs, o.get_event_cb_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 879 | elif hasattr(o, "get_swap_to_be_func_def"): |
| 880 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 881 | print("") |
| 882 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 883 | print("#endif") |
Klement Sekera | 34a962b | 2018-09-06 19:31:36 +0200 | [diff] [blame] | 884 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 885 | emitted.append(o) |
| 886 | |
| 887 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 888 | def gen_json_unified_header(parser, logger, j, io, name): |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 889 | d, f = os.path.split(j) |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 890 | logger.info("Generating header `%s'" % name) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 891 | orig_stdout = sys.stdout |
| 892 | sys.stdout = io |
| 893 | include_guard = "__included_%s" % ( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 894 | j.replace(".", "_") |
| 895 | .replace("/", "_") |
| 896 | .replace("-", "_") |
| 897 | .replace("+", "_") |
| 898 | .replace("@", "_") |
| 899 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 900 | print("#ifndef %s" % include_guard) |
| 901 | print("#define %s" % include_guard) |
| 902 | print("") |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 903 | print("#include <stdlib.h>") |
| 904 | print("#include <stddef.h>") |
| 905 | print("#include <arpa/inet.h>") |
| 906 | print("#include <vapi/vapi_internal.h>") |
| 907 | print("#include <vapi/vapi.h>") |
| 908 | print("#include <vapi/vapi_dbg.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 909 | print("") |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 910 | print("#ifdef __cplusplus") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 911 | print('extern "C" {') |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 912 | print("#endif") |
Klement Sekera | 03e1d55 | 2023-08-06 19:33:16 +0200 | [diff] [blame] | 913 | |
| 914 | print("#ifndef __vl_api_string_swap_fns_defined__") |
| 915 | print("#define __vl_api_string_swap_fns_defined__") |
| 916 | print("") |
| 917 | print("#include <vlibapi/api_types.h>") |
| 918 | print("") |
| 919 | function_attrs = "static inline " |
| 920 | o = parser.types["vl_api_string_t"] |
| 921 | print("%s%s" % (function_attrs, o.get_swap_to_be_func_def())) |
| 922 | print("") |
| 923 | print("%s%s" % (function_attrs, o.get_swap_to_host_func_def())) |
| 924 | print("") |
| 925 | print("#endif //__vl_api_string_swap_fns_defined__") |
| 926 | |
Filip Tehlar | f0e67d7 | 2021-07-23 22:03:05 +0000 | [diff] [blame] | 927 | if name == "memclnt.api.vapi.h": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 928 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 929 | print( |
| 930 | "static inline vapi_error_e vapi_send_with_control_ping " |
| 931 | "(vapi_ctx_t ctx, void * msg, u32 context);" |
| 932 | ) |
Dave Wallace | 6081dda | 2022-02-23 15:36:02 -0500 | [diff] [blame] | 933 | elif name == "vlib.api.vapi.h": |
| 934 | print("#include <vapi/memclnt.api.vapi.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 935 | else: |
Florin Coras | a1400ce | 2021-09-15 09:02:08 -0700 | [diff] [blame] | 936 | print("#include <vapi/vlib.api.vapi.h>") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 937 | print("") |
| 938 | for m in parser.messages_by_json[j].values(): |
| 939 | print("extern vapi_msg_id_t %s;" % m.get_msg_id_name()) |
| 940 | print("") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 941 | print( |
| 942 | "#define DEFINE_VAPI_MSG_IDS_%s\\" |
| 943 | % f.replace(".", "_").replace("/", "_").replace("-", "_").upper() |
| 944 | ) |
| 945 | print( |
| 946 | "\\\n".join( |
| 947 | [ |
| 948 | " vapi_msg_id_t %s;" % m.get_msg_id_name() |
| 949 | for m in parser.messages_by_json[j].values() |
| 950 | ] |
| 951 | ) |
| 952 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 953 | print("") |
| 954 | print("") |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 955 | emitted = [] |
| 956 | for e in parser.enums_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 957 | emit_definition(parser, j, emitted, e) |
Klement Sekera | 2108c0c | 2018-08-24 11:43:20 +0200 | [diff] [blame] | 958 | for u in parser.unions_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 959 | emit_definition(parser, j, emitted, u) |
Ole Troan | 52ca756 | 2018-03-06 17:45:32 +0100 | [diff] [blame] | 960 | for t in parser.types_by_json[j]: |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 961 | emit_definition(parser, j, emitted, t) |
Ole Troan | 75761b9 | 2019-09-11 17:49:08 +0200 | [diff] [blame] | 962 | for a in parser.aliases_by_json[j]: |
| 963 | emit_definition(parser, j, emitted, a) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 964 | for m in parser.messages_by_json[j].values(): |
Klement Sekera | 1732e47 | 2018-08-28 17:23:18 +0200 | [diff] [blame] | 965 | emit_definition(parser, j, emitted, m) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 966 | |
| 967 | print("") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 968 | |
Florin Coras | a1400ce | 2021-09-15 09:02:08 -0700 | [diff] [blame] | 969 | if name == "vlib.api.vapi.h": |
Dave Wallace | 6081dda | 2022-02-23 15:36:02 -0500 | [diff] [blame] | 970 | vapi_send_with_control_ping_function = """ |
| 971 | static inline vapi_error_e |
| 972 | vapi_send_with_control_ping (vapi_ctx_t ctx, void *msg, u32 context) |
| 973 | { |
| 974 | vapi_msg_control_ping *ping = vapi_alloc_control_ping (ctx); |
| 975 | if (!ping) |
| 976 | { |
| 977 | return VAPI_ENOMEM; |
| 978 | } |
| 979 | ping->header.context = context; |
| 980 | vapi_msg_control_ping_hton (ping); |
| 981 | return vapi_send2 (ctx, msg, ping); |
| 982 | } |
| 983 | """ |
| 984 | print("%s" % vapi_send_with_control_ping_function) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 985 | print("") |
| 986 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 987 | print("#ifdef __cplusplus") |
| 988 | print("}") |
| 989 | print("#endif") |
| 990 | print("") |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 991 | print("#endif") |
| 992 | sys.stdout = orig_stdout |
| 993 | |
| 994 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 995 | def json_to_c_header_name(json_name): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 996 | if json_name.endswith(".json"): |
| 997 | return "%s.vapi.h" % os.path.splitext(json_name)[0] |
| 998 | raise Exception("Unexpected json name `%s'!" % json_name) |
| 999 | |
| 1000 | |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1001 | def gen_c_unified_headers(parser, logger, prefix, remove_path): |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1002 | if prefix == "" or prefix is None: |
| 1003 | prefix = "" |
| 1004 | else: |
| 1005 | prefix = "%s/" % prefix |
| 1006 | for j in parser.json_files: |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1007 | if remove_path: |
| 1008 | d, f = os.path.split(j) |
| 1009 | else: |
| 1010 | f = j |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1011 | with open("%s%s" % (prefix, json_to_c_header_name(f)), "w") as io: |
| 1012 | gen_json_unified_header(parser, logger, j, io, json_to_c_header_name(f)) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1013 | |
| 1014 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1015 | if __name__ == "__main__": |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1016 | try: |
| 1017 | verbose = int(os.getenv("V", 0)) |
| 1018 | except: |
| 1019 | verbose = 0 |
| 1020 | |
| 1021 | if verbose >= 2: |
| 1022 | log_level = 10 |
| 1023 | elif verbose == 1: |
| 1024 | log_level = 20 |
| 1025 | else: |
| 1026 | log_level = 40 |
| 1027 | |
| 1028 | logging.basicConfig(stream=sys.stdout, level=log_level) |
| 1029 | logger = logging.getLogger("VAPI C GEN") |
| 1030 | logger.setLevel(log_level) |
| 1031 | |
Klement Sekera | dc15be2 | 2017-06-12 06:49:33 +0200 | [diff] [blame] | 1032 | argparser = argparse.ArgumentParser(description="VPP C API generator") |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1033 | argparser.add_argument( |
| 1034 | "files", |
| 1035 | metavar="api-file", |
| 1036 | action="append", |
| 1037 | type=str, |
| 1038 | help="json api file" "(may be specified multiple times)", |
| 1039 | ) |
| 1040 | argparser.add_argument("--prefix", action="store", default=None, help="path prefix") |
| 1041 | argparser.add_argument( |
| 1042 | "--remove-path", action="store_true", help="remove path from filename" |
| 1043 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1044 | args = argparser.parse_args() |
| 1045 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 1046 | jsonparser = JsonParser( |
| 1047 | logger, |
| 1048 | args.files, |
| 1049 | simple_type_class=CSimpleType, |
| 1050 | enum_class=CEnum, |
| 1051 | union_class=CUnion, |
| 1052 | struct_type_class=CStructType, |
| 1053 | field_class=CField, |
| 1054 | message_class=CMessage, |
| 1055 | alias_class=CAlias, |
| 1056 | ) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1057 | |
| 1058 | # not using the model of having separate generated header and code files |
| 1059 | # with generated symbols present in shared library (per discussion with |
| 1060 | # Damjan), to avoid symbol version issues in .so |
| 1061 | # gen_c_headers_and_code(jsonparser, logger, args.prefix) |
| 1062 | |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1063 | gen_c_unified_headers(jsonparser, logger, args.prefix, args.remove_path) |
Klement Sekera | 8f2a4ea | 2017-05-04 06:15:18 +0200 | [diff] [blame] | 1064 | |
| 1065 | for e in jsonparser.exceptions: |
Damjan Marion | 4c64b6e | 2018-08-26 18:14:46 +0200 | [diff] [blame] | 1066 | logger.warning(e) |