Paul Vinciguerra | f4647ed | 2019-02-12 12:21:01 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 2 | |
| 3 | from __future__ import print_function |
| 4 | import ply.lex as lex |
| 5 | import ply.yacc as yacc |
| 6 | import sys |
| 7 | import argparse |
| 8 | import logging |
| 9 | import binascii |
| 10 | import os |
| 11 | |
Ole Troan | d6743b1 | 2018-03-07 08:40:58 +0100 | [diff] [blame] | 12 | # Ensure we don't leave temporary files around |
| 13 | sys.dont_write_bytecode = True |
| 14 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 15 | # |
| 16 | # VPP API language |
| 17 | # |
| 18 | |
| 19 | # Global dictionary of new types (including enums) |
| 20 | global_types = {} |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 21 | global_crc = 0 |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 22 | |
| 23 | |
| 24 | def global_type_add(name): |
| 25 | '''Add new type to the dictionary of types ''' |
| 26 | type_name = 'vl_api_' + name + '_t' |
| 27 | if type_name in global_types: |
| 28 | raise KeyError('Type is already defined: {}'.format(name)) |
| 29 | global_types[type_name] = True |
| 30 | |
| 31 | |
| 32 | # All your trace are belong to us! |
| 33 | def exception_handler(exception_type, exception, traceback): |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 34 | print("%s: %s" % (exception_type.__name__, exception)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 35 | |
| 36 | |
| 37 | # |
| 38 | # Lexer |
| 39 | # |
| 40 | class VPPAPILexer(object): |
| 41 | def __init__(self, filename): |
| 42 | self.filename = filename |
| 43 | |
| 44 | reserved = { |
| 45 | 'service': 'SERVICE', |
| 46 | 'rpc': 'RPC', |
| 47 | 'returns': 'RETURNS', |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 48 | 'null': 'NULL', |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 49 | 'stream': 'STREAM', |
| 50 | 'events': 'EVENTS', |
| 51 | 'define': 'DEFINE', |
| 52 | 'typedef': 'TYPEDEF', |
| 53 | 'enum': 'ENUM', |
| 54 | 'typeonly': 'TYPEONLY', |
| 55 | 'manual_print': 'MANUAL_PRINT', |
| 56 | 'manual_endian': 'MANUAL_ENDIAN', |
| 57 | 'dont_trace': 'DONT_TRACE', |
| 58 | 'autoreply': 'AUTOREPLY', |
| 59 | 'option': 'OPTION', |
| 60 | 'u8': 'U8', |
| 61 | 'u16': 'U16', |
| 62 | 'u32': 'U32', |
| 63 | 'u64': 'U64', |
| 64 | 'i8': 'I8', |
| 65 | 'i16': 'I16', |
| 66 | 'i32': 'I32', |
| 67 | 'i64': 'I64', |
| 68 | 'f64': 'F64', |
| 69 | 'bool': 'BOOL', |
| 70 | 'string': 'STRING', |
| 71 | 'import': 'IMPORT', |
| 72 | 'true': 'TRUE', |
| 73 | 'false': 'FALSE', |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 74 | 'union': 'UNION', |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | tokens = ['STRING_LITERAL', |
| 78 | 'ID', 'NUM'] + list(reserved.values()) |
| 79 | |
| 80 | t_ignore_LINE_COMMENT = '//.*' |
| 81 | |
| 82 | def t_NUM(self, t): |
| 83 | r'0[xX][0-9a-fA-F]+|\d+' |
| 84 | base = 16 if t.value.startswith('0x') else 10 |
| 85 | t.value = int(t.value, base) |
| 86 | return t |
| 87 | |
| 88 | def t_ID(self, t): |
| 89 | r'[a-zA-Z_][a-zA-Z_0-9]*' |
| 90 | # Check for reserved words |
| 91 | t.type = VPPAPILexer.reserved.get(t.value, 'ID') |
| 92 | return t |
| 93 | |
| 94 | # C string |
| 95 | def t_STRING_LITERAL(self, t): |
| 96 | r'\"([^\\\n]|(\\.))*?\"' |
| 97 | t.value = str(t.value).replace("\"", "") |
| 98 | return t |
| 99 | |
| 100 | # C or C++ comment (ignore) |
| 101 | def t_comment(self, t): |
| 102 | r'(/\*(.|\n)*?\*/)|(//.*)' |
| 103 | t.lexer.lineno += t.value.count('\n') |
| 104 | |
| 105 | # Error handling rule |
| 106 | def t_error(self, t): |
| 107 | raise ParseError("Illegal character '{}' ({})" |
| 108 | "in {}: line {}".format(t.value[0], |
| 109 | hex(ord(t.value[0])), |
| 110 | self.filename, |
| 111 | t.lexer.lineno)) |
| 112 | t.lexer.skip(1) |
| 113 | |
| 114 | # Define a rule so we can track line numbers |
| 115 | def t_newline(self, t): |
| 116 | r'\n+' |
| 117 | t.lexer.lineno += len(t.value) |
| 118 | |
| 119 | literals = ":{}[];=.," |
| 120 | |
| 121 | # A string containing ignored characters (spaces and tabs) |
| 122 | t_ignore = ' \t' |
| 123 | |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 124 | |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 125 | # |
| 126 | # Side-effect: Sets global_crc |
| 127 | # |
| 128 | def crc_block(block): |
| 129 | global global_crc |
| 130 | s = str(block).encode() |
| 131 | global_crc = binascii.crc32(s, global_crc) |
| 132 | return binascii.crc32(s) & 0xffffffff |
| 133 | |
| 134 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 135 | class Service(): |
Paul Vinciguerra | 7e0c48e | 2019-02-01 19:37:45 -0800 | [diff] [blame] | 136 | def __init__(self, caller, reply, events=None, stream=False): |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 137 | self.caller = caller |
| 138 | self.reply = reply |
| 139 | self.stream = stream |
Paul Vinciguerra | 7e0c48e | 2019-02-01 19:37:45 -0800 | [diff] [blame] | 140 | self.events = [] if events is None else events |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 141 | |
| 142 | |
| 143 | class Typedef(): |
| 144 | def __init__(self, name, flags, block): |
| 145 | self.name = name |
| 146 | self.flags = flags |
| 147 | self.block = block |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 148 | self.crc = crc_block(block) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 149 | self.manual_print = False |
| 150 | self.manual_endian = False |
| 151 | for f in flags: |
| 152 | if f == 'manual_print': |
| 153 | self.manual_print = True |
| 154 | elif f == 'manual_endian': |
| 155 | self.manual_endian = True |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 156 | global_type_add(name) |
| 157 | |
| 158 | def __repr__(self): |
| 159 | return self.name + str(self.flags) + str(self.block) |
| 160 | |
| 161 | |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 162 | class Using(): |
| 163 | def __init__(self, name, alias): |
| 164 | global global_crc |
| 165 | self.name = name |
| 166 | |
| 167 | if isinstance(alias, Array): |
Paul Vinciguerra | f4647ed | 2019-02-12 12:21:01 -0800 | [diff] [blame] | 168 | a = { 'type': alias.fieldtype, # noqa: E201 |
| 169 | 'length': alias.length } # noqa: E202 |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 170 | else: |
Paul Vinciguerra | f4647ed | 2019-02-12 12:21:01 -0800 | [diff] [blame] | 171 | a = { 'type': alias.fieldtype } # noqa: E201,E202 |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 172 | self.alias = a |
Paul Vinciguerra | 7e0c48e | 2019-02-01 19:37:45 -0800 | [diff] [blame] | 173 | self.crc = binascii.crc32(str(alias).encode()) & 0xffffffff |
| 174 | global_crc = binascii.crc32(str(alias).encode(), global_crc) |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 175 | global_type_add(name) |
| 176 | |
| 177 | def __repr__(self): |
| 178 | return self.name + str(self.alias) |
| 179 | |
| 180 | |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 181 | class Union(): |
| 182 | def __init__(self, name, block): |
| 183 | self.type = 'Union' |
| 184 | self.manual_print = False |
| 185 | self.manual_endian = False |
| 186 | global global_crc |
| 187 | self.name = name |
| 188 | self.block = block |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 189 | self.crc = crc_block(block) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 190 | global_type_add(name) |
| 191 | |
| 192 | def __repr__(self): |
| 193 | return str(self.block) |
| 194 | |
| 195 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 196 | class Define(): |
| 197 | def __init__(self, name, flags, block): |
| 198 | self.name = name |
| 199 | self.flags = flags |
| 200 | self.block = block |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 201 | self.crc = crc_block(block) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 202 | self.dont_trace = False |
| 203 | self.manual_print = False |
| 204 | self.manual_endian = False |
| 205 | self.autoreply = False |
| 206 | self.singular = False |
| 207 | for f in flags: |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 208 | if f == 'dont_trace': |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 209 | self.dont_trace = True |
| 210 | elif f == 'manual_print': |
| 211 | self.manual_print = True |
| 212 | elif f == 'manual_endian': |
| 213 | self.manual_endian = True |
| 214 | elif f == 'autoreply': |
| 215 | self.autoreply = True |
| 216 | |
| 217 | for b in block: |
| 218 | if isinstance(b, Option): |
| 219 | if b[1] == 'singular' and b[2] == 'true': |
| 220 | self.singular = True |
| 221 | block.remove(b) |
| 222 | |
| 223 | def __repr__(self): |
| 224 | return self.name + str(self.flags) + str(self.block) |
| 225 | |
| 226 | |
| 227 | class Enum(): |
| 228 | def __init__(self, name, block, enumtype='u32'): |
| 229 | self.name = name |
| 230 | self.enumtype = enumtype |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 231 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 232 | count = 0 |
| 233 | for i, b in enumerate(block): |
| 234 | if type(b) is list: |
| 235 | count = b[1] |
| 236 | else: |
| 237 | count += 1 |
| 238 | block[i] = [b, count] |
| 239 | |
| 240 | self.block = block |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 241 | self.crc = crc_block(block) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 242 | global_type_add(name) |
| 243 | |
| 244 | def __repr__(self): |
| 245 | return self.name + str(self.block) |
| 246 | |
| 247 | |
| 248 | class Import(): |
| 249 | def __init__(self, filename): |
| 250 | self.filename = filename |
| 251 | |
| 252 | # Deal with imports |
| 253 | parser = VPPAPI(filename=filename) |
| 254 | dirlist = dirlist_get() |
| 255 | f = filename |
| 256 | for dir in dirlist: |
| 257 | f = os.path.join(dir, filename) |
| 258 | if os.path.exists(f): |
| 259 | break |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 260 | if sys.version[0] == '2': |
| 261 | with open(f) as fd: |
| 262 | self.result = parser.parse_file(fd, None) |
| 263 | else: |
| 264 | with open(f, encoding='utf-8') as fd: |
| 265 | self.result = parser.parse_file(fd, None) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 266 | |
| 267 | def __repr__(self): |
| 268 | return self.filename |
| 269 | |
| 270 | |
| 271 | class Option(): |
| 272 | def __init__(self, option): |
| 273 | self.option = option |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 274 | self.crc = crc_block(option) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 275 | |
| 276 | def __repr__(self): |
| 277 | return str(self.option) |
| 278 | |
| 279 | def __getitem__(self, index): |
| 280 | return self.option[index] |
| 281 | |
| 282 | |
| 283 | class Array(): |
| 284 | def __init__(self, fieldtype, name, length): |
| 285 | self.type = 'Array' |
| 286 | self.fieldtype = fieldtype |
| 287 | self.fieldname = name |
| 288 | if type(length) is str: |
| 289 | self.lengthfield = length |
| 290 | self.length = 0 |
| 291 | else: |
| 292 | self.length = length |
| 293 | self.lengthfield = None |
| 294 | |
| 295 | def __repr__(self): |
| 296 | return str([self.fieldtype, self.fieldname, self.length, |
| 297 | self.lengthfield]) |
| 298 | |
| 299 | |
| 300 | class Field(): |
| 301 | def __init__(self, fieldtype, name): |
| 302 | self.type = 'Field' |
| 303 | self.fieldtype = fieldtype |
| 304 | self.fieldname = name |
| 305 | |
| 306 | def __repr__(self): |
| 307 | return str([self.fieldtype, self.fieldname]) |
| 308 | |
| 309 | |
| 310 | class Coord(object): |
| 311 | """ Coordinates of a syntactic element. Consists of: |
| 312 | - File name |
| 313 | - Line number |
| 314 | - (optional) column number, for the Lexer |
| 315 | """ |
| 316 | __slots__ = ('file', 'line', 'column', '__weakref__') |
| 317 | |
| 318 | def __init__(self, file, line, column=None): |
| 319 | self.file = file |
| 320 | self.line = line |
| 321 | self.column = column |
| 322 | |
| 323 | def __str__(self): |
| 324 | str = "%s:%s" % (self.file, self.line) |
| 325 | if self.column: |
| 326 | str += ":%s" % self.column |
| 327 | return str |
| 328 | |
| 329 | |
| 330 | class ParseError(Exception): |
| 331 | pass |
| 332 | |
| 333 | |
| 334 | # |
| 335 | # Grammar rules |
| 336 | # |
| 337 | class VPPAPIParser(object): |
| 338 | tokens = VPPAPILexer.tokens |
| 339 | |
| 340 | def __init__(self, filename, logger): |
| 341 | self.filename = filename |
| 342 | self.logger = logger |
| 343 | self.fields = [] |
| 344 | |
| 345 | def _parse_error(self, msg, coord): |
| 346 | raise ParseError("%s: %s" % (coord, msg)) |
| 347 | |
| 348 | def _parse_warning(self, msg, coord): |
| 349 | if self.logger: |
| 350 | self.logger.warning("%s: %s" % (coord, msg)) |
| 351 | |
| 352 | def _coord(self, lineno, column=None): |
| 353 | return Coord( |
| 354 | file=self.filename, |
| 355 | line=lineno, column=column) |
| 356 | |
| 357 | def _token_coord(self, p, token_idx): |
| 358 | """ Returns the coordinates for the YaccProduction object 'p' indexed |
| 359 | with 'token_idx'. The coordinate includes the 'lineno' and |
| 360 | 'column'. Both follow the lex semantic, starting from 1. |
| 361 | """ |
| 362 | last_cr = p.lexer.lexdata.rfind('\n', 0, p.lexpos(token_idx)) |
| 363 | if last_cr < 0: |
| 364 | last_cr = -1 |
| 365 | column = (p.lexpos(token_idx) - (last_cr)) |
| 366 | return self._coord(p.lineno(token_idx), column) |
| 367 | |
| 368 | def p_slist(self, p): |
| 369 | '''slist : stmt |
| 370 | | slist stmt''' |
| 371 | if len(p) == 2: |
| 372 | p[0] = [p[1]] |
| 373 | else: |
| 374 | p[0] = p[1] + [p[2]] |
| 375 | |
| 376 | def p_stmt(self, p): |
| 377 | '''stmt : define |
| 378 | | typedef |
| 379 | | option |
| 380 | | import |
| 381 | | enum |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 382 | | union |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 383 | | service''' |
| 384 | p[0] = p[1] |
| 385 | |
| 386 | def p_import(self, p): |
| 387 | '''import : IMPORT STRING_LITERAL ';' ''' |
| 388 | p[0] = Import(p[2]) |
| 389 | |
| 390 | def p_service(self, p): |
| 391 | '''service : SERVICE '{' service_statements '}' ';' ''' |
| 392 | p[0] = p[3] |
| 393 | |
| 394 | def p_service_statements(self, p): |
| 395 | '''service_statements : service_statement |
| 396 | | service_statements service_statement''' |
| 397 | if len(p) == 2: |
| 398 | p[0] = [p[1]] |
| 399 | else: |
| 400 | p[0] = p[1] + [p[2]] |
| 401 | |
| 402 | def p_service_statement(self, p): |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 403 | '''service_statement : RPC ID RETURNS NULL ';' |
| 404 | | RPC ID RETURNS ID ';' |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 405 | | RPC ID RETURNS STREAM ID ';' |
| 406 | | RPC ID RETURNS ID EVENTS event_list ';' ''' |
Marek Gradzki | fc70e3a | 2018-03-06 10:56:26 +0100 | [diff] [blame] | 407 | if p[2] == p[4]: |
| 408 | # Verify that caller and reply differ |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 409 | self._parse_error( |
| 410 | 'Reply ID ({}) should not be equal to Caller ID'.format(p[2]), |
| 411 | self._token_coord(p, 1)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 412 | if len(p) == 8: |
| 413 | p[0] = Service(p[2], p[4], p[6]) |
| 414 | elif len(p) == 7: |
| 415 | p[0] = Service(p[2], p[5], stream=True) |
| 416 | else: |
| 417 | p[0] = Service(p[2], p[4]) |
| 418 | |
| 419 | def p_event_list(self, p): |
| 420 | '''event_list : events |
| 421 | | event_list events ''' |
| 422 | if len(p) == 2: |
| 423 | p[0] = [p[1]] |
| 424 | else: |
| 425 | p[0] = p[1] + [p[2]] |
| 426 | |
| 427 | def p_event(self, p): |
| 428 | '''events : ID |
| 429 | | ID ',' ''' |
| 430 | p[0] = p[1] |
| 431 | |
| 432 | def p_enum(self, p): |
| 433 | '''enum : ENUM ID '{' enum_statements '}' ';' ''' |
| 434 | p[0] = Enum(p[2], p[4]) |
| 435 | |
| 436 | def p_enum_type(self, p): |
| 437 | ''' enum : ENUM ID ':' enum_size '{' enum_statements '}' ';' ''' |
| 438 | if len(p) == 9: |
| 439 | p[0] = Enum(p[2], p[6], enumtype=p[4]) |
| 440 | else: |
| 441 | p[0] = Enum(p[2], p[4]) |
| 442 | |
| 443 | def p_enum_size(self, p): |
| 444 | ''' enum_size : U8 |
| 445 | | U16 |
| 446 | | U32 ''' |
| 447 | p[0] = p[1] |
| 448 | |
| 449 | def p_define(self, p): |
| 450 | '''define : DEFINE ID '{' block_statements_opt '}' ';' ''' |
| 451 | self.fields = [] |
| 452 | p[0] = Define(p[2], [], p[4]) |
| 453 | |
| 454 | def p_define_flist(self, p): |
| 455 | '''define : flist DEFINE ID '{' block_statements_opt '}' ';' ''' |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 456 | # Legacy typedef |
| 457 | if 'typeonly' in p[1]: |
| 458 | p[0] = Typedef(p[3], p[1], p[5]) |
| 459 | else: |
| 460 | p[0] = Define(p[3], p[1], p[5]) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 461 | |
| 462 | def p_flist(self, p): |
| 463 | '''flist : flag |
| 464 | | flist flag''' |
| 465 | if len(p) == 2: |
| 466 | p[0] = [p[1]] |
| 467 | else: |
| 468 | p[0] = p[1] + [p[2]] |
| 469 | |
| 470 | def p_flag(self, p): |
| 471 | '''flag : MANUAL_PRINT |
| 472 | | MANUAL_ENDIAN |
| 473 | | DONT_TRACE |
| 474 | | TYPEONLY |
| 475 | | AUTOREPLY''' |
| 476 | if len(p) == 1: |
| 477 | return |
| 478 | p[0] = p[1] |
| 479 | |
| 480 | def p_typedef(self, p): |
| 481 | '''typedef : TYPEDEF ID '{' block_statements_opt '}' ';' ''' |
| 482 | p[0] = Typedef(p[2], [], p[4]) |
| 483 | |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 484 | def p_typedef_alias(self, p): |
| 485 | '''typedef : TYPEDEF declaration ''' |
| 486 | p[0] = Using(p[2].fieldname, p[2]) |
| 487 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 488 | def p_block_statements_opt(self, p): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 489 | '''block_statements_opt : block_statements ''' |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 490 | p[0] = p[1] |
| 491 | |
| 492 | def p_block_statements(self, p): |
| 493 | '''block_statements : block_statement |
| 494 | | block_statements block_statement''' |
| 495 | if len(p) == 2: |
| 496 | p[0] = [p[1]] |
| 497 | else: |
| 498 | p[0] = p[1] + [p[2]] |
| 499 | |
| 500 | def p_block_statement(self, p): |
| 501 | '''block_statement : declaration |
| 502 | | option ''' |
| 503 | p[0] = p[1] |
| 504 | |
| 505 | def p_enum_statements(self, p): |
| 506 | '''enum_statements : enum_statement |
| 507 | | enum_statements enum_statement''' |
| 508 | if len(p) == 2: |
| 509 | p[0] = [p[1]] |
| 510 | else: |
| 511 | p[0] = p[1] + [p[2]] |
| 512 | |
| 513 | def p_enum_statement(self, p): |
| 514 | '''enum_statement : ID '=' NUM ',' |
| 515 | | ID ',' ''' |
| 516 | if len(p) == 5: |
| 517 | p[0] = [p[1], p[3]] |
| 518 | else: |
| 519 | p[0] = p[1] |
| 520 | |
| 521 | def p_declaration(self, p): |
| 522 | '''declaration : type_specifier ID ';' ''' |
| 523 | if len(p) != 4: |
| 524 | self._parse_error('ERROR') |
| 525 | self.fields.append(p[2]) |
| 526 | p[0] = Field(p[1], p[2]) |
| 527 | |
| 528 | def p_declaration_array(self, p): |
| 529 | '''declaration : type_specifier ID '[' NUM ']' ';' |
| 530 | | type_specifier ID '[' ID ']' ';' ''' |
| 531 | if len(p) != 7: |
| 532 | return self._parse_error( |
| 533 | 'array: %s' % p.value, |
| 534 | self._coord(lineno=p.lineno)) |
| 535 | |
| 536 | # Make this error later |
| 537 | if type(p[4]) is int and p[4] == 0: |
| 538 | # XXX: Line number is wrong |
| 539 | self._parse_warning('Old Style VLA: {} {}[{}];' |
| 540 | .format(p[1], p[2], p[4]), |
| 541 | self._token_coord(p, 1)) |
| 542 | |
| 543 | if type(p[4]) is str and p[4] not in self.fields: |
| 544 | # Verify that length field exists |
| 545 | self._parse_error('Missing length field: {} {}[{}];' |
| 546 | .format(p[1], p[2], p[4]), |
| 547 | self._token_coord(p, 1)) |
| 548 | p[0] = Array(p[1], p[2], p[4]) |
| 549 | |
| 550 | def p_option(self, p): |
| 551 | '''option : OPTION ID '=' assignee ';' ''' |
| 552 | p[0] = Option([p[1], p[2], p[4]]) |
| 553 | |
| 554 | def p_assignee(self, p): |
| 555 | '''assignee : NUM |
| 556 | | TRUE |
| 557 | | FALSE |
| 558 | | STRING_LITERAL ''' |
| 559 | p[0] = p[1] |
| 560 | |
| 561 | def p_type_specifier(self, p): |
| 562 | '''type_specifier : U8 |
| 563 | | U16 |
| 564 | | U32 |
| 565 | | U64 |
| 566 | | I8 |
| 567 | | I16 |
| 568 | | I32 |
| 569 | | I64 |
| 570 | | F64 |
| 571 | | BOOL |
| 572 | | STRING''' |
| 573 | p[0] = p[1] |
| 574 | |
| 575 | # Do a second pass later to verify that user defined types are defined |
| 576 | def p_typedef_specifier(self, p): |
| 577 | '''type_specifier : ID ''' |
| 578 | if p[1] not in global_types: |
| 579 | self._parse_error('Undefined type: {}'.format(p[1]), |
| 580 | self._token_coord(p, 1)) |
| 581 | p[0] = p[1] |
| 582 | |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 583 | def p_union(self, p): |
| 584 | '''union : UNION ID '{' block_statements_opt '}' ';' ''' |
| 585 | p[0] = Union(p[2], p[4]) |
| 586 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 587 | # Error rule for syntax errors |
| 588 | def p_error(self, p): |
| 589 | if p: |
| 590 | self._parse_error( |
| 591 | 'before: %s' % p.value, |
| 592 | self._coord(lineno=p.lineno)) |
| 593 | else: |
| 594 | self._parse_error('At end of input', self.filename) |
| 595 | |
| 596 | |
| 597 | class VPPAPI(object): |
| 598 | |
| 599 | def __init__(self, debug=False, filename='', logger=None): |
| 600 | self.lexer = lex.lex(module=VPPAPILexer(filename), debug=debug) |
| 601 | self.parser = yacc.yacc(module=VPPAPIParser(filename, logger), |
Ole Troan | d6743b1 | 2018-03-07 08:40:58 +0100 | [diff] [blame] | 602 | write_tables=False, debug=debug) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 603 | self.logger = logger |
| 604 | |
| 605 | def parse_string(self, code, debug=0, lineno=1): |
| 606 | self.lexer.lineno = lineno |
| 607 | return self.parser.parse(code, lexer=self.lexer, debug=debug) |
| 608 | |
| 609 | def parse_file(self, fd, debug=0): |
| 610 | data = fd.read() |
| 611 | return self.parse_string(data, debug=debug) |
| 612 | |
| 613 | def autoreply_block(self, name): |
| 614 | block = [Field('u32', 'context'), |
| 615 | Field('i32', 'retval')] |
| 616 | return Define(name + '_reply', [], block) |
| 617 | |
| 618 | def process(self, objs): |
| 619 | s = {} |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 620 | s['Option'] = {} |
| 621 | s['Define'] = [] |
| 622 | s['Service'] = [] |
| 623 | s['types'] = [] |
| 624 | s['Import'] = [] |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 625 | s['Alias'] = {} |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 626 | for o in objs: |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 627 | tname = o.__class__.__name__ |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 628 | if isinstance(o, Define): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 629 | s[tname].append(o) |
| 630 | if o.autoreply: |
| 631 | s[tname].append(self.autoreply_block(o.name)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 632 | elif isinstance(o, Option): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 633 | s[tname][o[1]] = o[2] |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 634 | elif type(o) is list: |
| 635 | for o2 in o: |
| 636 | if isinstance(o2, Service): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 637 | s['Service'].append(o2) |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 638 | elif (isinstance(o, Enum) or |
| 639 | isinstance(o, Typedef) or |
| 640 | isinstance(o, Union)): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 641 | s['types'].append(o) |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 642 | elif isinstance(o, Using): |
| 643 | s['Alias'][o.name] = o.alias |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 644 | else: |
| 645 | if tname not in s: |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 646 | raise ValueError('Unknown class type: {} {}' |
| 647 | .format(tname, o)) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 648 | s[tname].append(o) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 649 | |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 650 | msgs = {d.name: d for d in s['Define']} |
| 651 | svcs = {s.caller: s for s in s['Service']} |
| 652 | replies = {s.reply: s for s in s['Service']} |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 653 | seen_services = {} |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 654 | |
| 655 | for service in svcs: |
| 656 | if service not in msgs: |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 657 | raise ValueError( |
| 658 | 'Service definition refers to unknown message' |
| 659 | ' definition: {}'.format(service)) |
| 660 | if svcs[service].reply != 'null' and \ |
| 661 | svcs[service].reply not in msgs: |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 662 | raise ValueError('Service definition refers to unknown message' |
| 663 | ' definition in reply: {}' |
| 664 | .format(svcs[service].reply)) |
Marek Gradzki | b533f3f | 2018-03-06 11:10:56 +0100 | [diff] [blame] | 665 | if service in replies: |
| 666 | raise ValueError('Service definition refers to message' |
| 667 | ' marked as reply: {}'.format(service)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 668 | for event in svcs[service].events: |
| 669 | if event not in msgs: |
| 670 | raise ValueError('Service definition refers to unknown ' |
| 671 | 'event: {} in message: {}' |
| 672 | .format(event, service)) |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 673 | seen_services[event] = True |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 674 | |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 675 | # Create services implicitly |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 676 | for d in msgs: |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 677 | if d in seen_services: |
| 678 | continue |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 679 | if msgs[d].singular is True: |
| 680 | continue |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 681 | if d.endswith('_reply'): |
| 682 | if d[:-6] in svcs: |
| 683 | continue |
| 684 | if d[:-6] not in msgs: |
Marek Gradzki | cc13471 | 2018-03-06 12:25:02 +0100 | [diff] [blame] | 685 | raise ValueError('{} missing calling message' |
| 686 | .format(d)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 687 | continue |
| 688 | if d.endswith('_dump'): |
| 689 | if d in svcs: |
| 690 | continue |
| 691 | if d[:-5]+'_details' in msgs: |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 692 | s['Service'].append(Service(d, d[:-5]+'_details', |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 693 | stream=True)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 694 | else: |
Marek Gradzki | cc13471 | 2018-03-06 12:25:02 +0100 | [diff] [blame] | 695 | raise ValueError('{} missing details message' |
| 696 | .format(d)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 697 | continue |
| 698 | |
| 699 | if d.endswith('_details'): |
| 700 | if d[:-8]+'_dump' not in msgs: |
Marek Gradzki | cc13471 | 2018-03-06 12:25:02 +0100 | [diff] [blame] | 701 | raise ValueError('{} missing dump message' |
| 702 | .format(d)) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 703 | continue |
| 704 | |
| 705 | if d in svcs: |
| 706 | continue |
| 707 | if d+'_reply' in msgs: |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 708 | s['Service'].append(Service(d, d+'_reply')) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 709 | else: |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 710 | raise ValueError( |
| 711 | '{} missing reply message ({}) or service definition' |
| 712 | .format(d, d+'_reply')) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 713 | |
| 714 | return s |
| 715 | |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 716 | def process_imports(self, objs, in_import, result): |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 717 | imported_objs = [] |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 718 | for o in objs: |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 719 | # Only allow the following object types from imported file |
| 720 | if in_import and not (isinstance(o, Enum) or |
| 721 | isinstance(o, Union) or |
Ole Troan | 10a0989 | 2018-06-29 11:32:33 +0200 | [diff] [blame] | 722 | isinstance(o, Typedef) or |
Ole Troan | 53fffa1 | 2018-11-13 12:36:56 +0100 | [diff] [blame] | 723 | isinstance(o, Import) or |
| 724 | isinstance(o, Using)): |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 725 | continue |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 726 | if isinstance(o, Import): |
| 727 | self.process_imports(o.result, True, result) |
Ole Troan | 10a0989 | 2018-06-29 11:32:33 +0200 | [diff] [blame] | 728 | else: |
| 729 | result.append(o) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 730 | |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 731 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 732 | # Add message ids to each message. |
| 733 | def add_msg_id(s): |
| 734 | for o in s: |
| 735 | o.block.insert(0, Field('u16', '_vl_msg_id')) |
| 736 | return s |
| 737 | |
| 738 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 739 | dirlist = [] |
| 740 | |
| 741 | |
| 742 | def dirlist_add(dirs): |
| 743 | global dirlist |
| 744 | if dirs: |
| 745 | dirlist = dirlist + dirs |
| 746 | |
| 747 | |
| 748 | def dirlist_get(): |
| 749 | return dirlist |
| 750 | |
| 751 | |
| 752 | # |
| 753 | # Main |
| 754 | # |
| 755 | def main(): |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 756 | cliparser = argparse.ArgumentParser(description='VPP API generator') |
| 757 | cliparser.add_argument('--pluginpath', default=""), |
| 758 | cliparser.add_argument('--includedir', action='append'), |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 759 | if sys.version[0] == '2': |
| 760 | cliparser.add_argument('--input', type=argparse.FileType('r'), |
| 761 | default=sys.stdin) |
Paul Vinciguerra | 7e0c48e | 2019-02-01 19:37:45 -0800 | [diff] [blame] | 762 | cliparser.add_argument('--output', nargs='?', |
| 763 | type=argparse.FileType('w'), |
| 764 | default=sys.stdout) |
| 765 | |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 766 | else: |
| 767 | cliparser.add_argument('--input', |
| 768 | type=argparse.FileType('r', encoding='UTF-8'), |
| 769 | default=sys.stdin) |
Paul Vinciguerra | 7e0c48e | 2019-02-01 19:37:45 -0800 | [diff] [blame] | 770 | cliparser.add_argument('--output', nargs='?', |
| 771 | type=argparse.FileType('w', encoding='UTF-8'), |
| 772 | default=sys.stdout) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 773 | |
| 774 | cliparser.add_argument('output_module', nargs='?', default='C') |
| 775 | cliparser.add_argument('--debug', action='store_true') |
| 776 | cliparser.add_argument('--show-name', nargs=1) |
| 777 | args = cliparser.parse_args() |
| 778 | |
| 779 | dirlist_add(args.includedir) |
| 780 | if not args.debug: |
| 781 | sys.excepthook = exception_handler |
| 782 | |
| 783 | # Filename |
| 784 | if args.show_name: |
| 785 | filename = args.show_name[0] |
| 786 | elif args.input != sys.stdin: |
| 787 | filename = args.input.name |
| 788 | else: |
| 789 | filename = '' |
| 790 | |
Marek Gradzki | 51e5968 | 2018-03-06 10:05:44 +0100 | [diff] [blame] | 791 | if args.debug: |
| 792 | logging.basicConfig(stream=sys.stdout, level=logging.WARNING) |
| 793 | else: |
| 794 | logging.basicConfig() |
| 795 | log = logging.getLogger('vppapigen') |
| 796 | |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 797 | parser = VPPAPI(debug=args.debug, filename=filename, logger=log) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 798 | parsed_objects = parser.parse_file(args.input, log) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 799 | |
| 800 | # Build a list of objects. Hash of lists. |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 801 | result = [] |
| 802 | parser.process_imports(parsed_objects, False, result) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 803 | s = parser.process(result) |
| 804 | |
| 805 | # Add msg_id field |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 806 | s['Define'] = add_msg_id(s['Define']) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 807 | |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 808 | file_crc = global_crc & 0xffffffff |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 809 | |
| 810 | # |
| 811 | # Debug |
| 812 | if args.debug: |
| 813 | import pprint |
Ole Troan | 10a0989 | 2018-06-29 11:32:33 +0200 | [diff] [blame] | 814 | pp = pprint.PrettyPrinter(indent=4, stream=sys.stderr) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 815 | for t in s['Define']: |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 816 | pp.pprint([t.name, t.flags, t.block]) |
Ole Troan | 2c2feab | 2018-04-24 00:02:37 -0400 | [diff] [blame] | 817 | for t in s['types']: |
| 818 | pp.pprint([t.name, t.block]) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 819 | |
| 820 | # |
| 821 | # Generate representation |
| 822 | # |
Paul Vinciguerra | f4647ed | 2019-02-12 12:21:01 -0800 | [diff] [blame] | 823 | from importlib.machinery import SourceFileLoader |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 824 | |
| 825 | # Default path |
Ole Troan | 3078737 | 2018-03-01 13:33:39 +0100 | [diff] [blame] | 826 | pluginpath = '' |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 827 | if not args.pluginpath: |
Ole Troan | 3078737 | 2018-03-01 13:33:39 +0100 | [diff] [blame] | 828 | cand = [] |
| 829 | cand.append(os.path.dirname(os.path.realpath(__file__))) |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 830 | cand.append(os.path.dirname(os.path.realpath(__file__)) + |
Ole Troan | 3078737 | 2018-03-01 13:33:39 +0100 | [diff] [blame] | 831 | '/../share/vpp/') |
| 832 | for c in cand: |
| 833 | c += '/' |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 834 | if os.path.isfile('{}vppapigen_{}.py' |
| 835 | .format(c, args.output_module.lower())): |
Ole Troan | 3078737 | 2018-03-01 13:33:39 +0100 | [diff] [blame] | 836 | pluginpath = c |
| 837 | break |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 838 | else: |
| 839 | pluginpath = args.pluginpath + '/' |
Ole Troan | 3078737 | 2018-03-01 13:33:39 +0100 | [diff] [blame] | 840 | if pluginpath == '': |
| 841 | raise Exception('Output plugin not found') |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 842 | module_path = '{}vppapigen_{}.py'.format(pluginpath, |
| 843 | args.output_module.lower()) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 844 | |
| 845 | try: |
Paul Vinciguerra | f4647ed | 2019-02-12 12:21:01 -0800 | [diff] [blame] | 846 | plugin = SourceFileLoader(args.output_module, |
| 847 | module_path).load_module() |
Ole Troan | 5891425 | 2018-10-23 10:50:07 +0200 | [diff] [blame] | 848 | except Exception as err: |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 849 | raise Exception('Error importing output plugin: {}, {}' |
| 850 | .format(module_path, err)) |
| 851 | |
| 852 | result = plugin.run(filename, s, file_crc) |
| 853 | if result: |
Ole Troan | 17225df | 2018-04-11 09:50:03 +0200 | [diff] [blame] | 854 | print(result, file=args.output) |
Ole Troan | 9d42087 | 2017-10-12 13:06:35 +0200 | [diff] [blame] | 855 | else: |
| 856 | raise Exception('Running plugin failed: {} {}' |
| 857 | .format(filename, result)) |
| 858 | |
| 859 | |
| 860 | if __name__ == '__main__': |
| 861 | main() |