diff options
author | Ole Troan <ot@cisco.com> | 2019-09-11 17:49:08 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2019-09-19 14:24:54 +0000 |
commit | 75761b933f3e28494bae4b2cf5636a07ffe6ce18 (patch) | |
tree | a9663623eba8a5c26c6bcceab1606c946ce29754 /src/tools/vppapigen | |
parent | fbc388986e3f38aaedff87b843137be81b7d4f91 (diff) |
api: split vl_api_prefix into two
One type for address with prefix and one type for prefix.
Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Icfec51d9b7d5cde1d69fbecdd97498688ab7b295
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/tools/vppapigen')
-rwxr-xr-x | src/tools/vppapigen/vppapigen.py | 7 | ||||
-rw-r--r-- | src/tools/vppapigen/vppapigen_c.py | 76 | ||||
-rw-r--r-- | src/tools/vppapigen/vppapigen_json.py | 3 |
3 files changed, 39 insertions, 47 deletions
diff --git a/src/tools/vppapigen/vppapigen.py b/src/tools/vppapigen/vppapigen.py index 03362b0e656..861b71ddf43 100755 --- a/src/tools/vppapigen/vppapigen.py +++ b/src/tools/vppapigen/vppapigen.py @@ -206,6 +206,9 @@ class Using(): def __init__(self, name, flags, alias): self.name = name self.vla = False + self.block = [] + self.manual_print = True + self.manual_endian = True self.manual_print = False self.manual_endian = False @@ -750,7 +753,6 @@ class VPPAPI(object): s['Service'] = [] s['types'] = [] s['Import'] = [] - s['Alias'] = {} crc = 0 for o in objs: tname = o.__class__.__name__ @@ -770,10 +772,9 @@ class VPPAPI(object): s['Service'].append(o2) elif (isinstance(o, Enum) or isinstance(o, Typedef) or + isinstance(o, Using) or isinstance(o, Union)): s['types'].append(o) - elif isinstance(o, Using): - s['Alias'][o.name] = o else: if tname not in s: raise ValueError('Unknown class type: {} {}' diff --git a/src/tools/vppapigen/vppapigen_c.py b/src/tools/vppapigen/vppapigen_c.py index d6cdda8baac..7c383c27472 100644 --- a/src/tools/vppapigen/vppapigen_c.py +++ b/src/tools/vppapigen/vppapigen_c.py @@ -95,7 +95,7 @@ def api2c(fieldtype): return fieldtype -def typedefs(objs, aliases, filename): +def typedefs(objs, filename): name = filename.replace('.', '_') output = '''\ @@ -108,16 +108,14 @@ def typedefs(objs, aliases, filename): ''' output = output.format(module=name) - for k, v in aliases.items(): - if 'length' in v.alias: - output += ('typedef %s vl_api_%s_t[%s];\n' - % (v.alias['type'], k, v.alias['length'])) - else: - output += 'typedef %s vl_api_%s_t;\n' % (v.alias['type'], k) - for o in objs: tname = o.__class__.__name__ - if tname == 'Enum': + if tname == 'Using': + if 'length' in o.alias: + output += 'typedef %s vl_api_%s_t[%s];\n' % (o.alias['type'], o.name, o.alias['length']) + else: + output += 'typedef %s vl_api_%s_t;\n' % (o.alias['type'], o.name) + elif tname == 'Enum': if o.enumtype == 'u32': output += "typedef enum {\n" else: @@ -282,7 +280,7 @@ class Printfun(): write(' return format(s, "{}", *a);\n' .format(format_strings[v.alias['type']])) else: - write(' return format(s, "{} (print not implemented)"' + write(' return format(s, "{} (print not implemented)");\n' .format(k)) def print_enum(self, o, stream): @@ -357,7 +355,7 @@ static inline void *vl_api_{name}_t_print (vl_api_{name}_t *a, void *handle) return '' -def printfun_types(objs, aliases, stream, modulename): +def printfun_types(objs, stream, modulename): write = stream.write pp = Printfun(stream) @@ -380,15 +378,6 @@ static inline u8 *format_vl_api_{name}_t (u8 *s, va_list * args) indent += 2; ''' - for k, v in aliases.items(): - if v.manual_print: - write("/***** manual: vl_api_%s_t_print *****/\n\n" % k) - continue - - write(signature.format(name=k)) - pp.print_alias(k, v, stream) - write('}\n\n') - for t in objs: if t.__class__.__name__ == 'Enum': write(signature.format(name=t.name)) @@ -401,6 +390,12 @@ static inline u8 *format_vl_api_{name}_t (u8 *s, va_list * args) write("/***** manual: vl_api_%s_t_print *****/\n\n" % t.name) continue + if t.__class__.__name__ == 'Using': + write(signature.format(name=t.name)) + pp.print_alias(t.name, t, stream) + write('}\n\n') + continue + write(signature.format(name=t.name)) for o in t.block: pp.print_obj(o, stream) @@ -485,7 +480,7 @@ def endianfun_obj(o): return output -def endianfun(objs, aliases, modulename): +def endianfun(objs, modulename): output = '''\ /****** Endian swap functions *****/\n\ @@ -509,23 +504,6 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a) int i __attribute__((unused)); ''' - for k, v in aliases.items(): - if v.manual_endian: - output += "/***** manual: vl_api_%s_t_endian *****/\n\n" % k - continue - - output += signature.format(name=k) - if ('length' in v.alias and v.alias['length'] and - v.alias['type'] == 'u8'): - output += (' /* a->{name} = a->{name} (no-op) */\n' - .format(name=k)) - elif v.alias['type'] in format_strings: - output += (' *a = {}(*a);\n' - .format(endian_strings[v.alias['type']])) - else: - output += ' /* Not Implemented yet {} */'.format(k) - output += '}\n\n' - for t in objs: if t.__class__.__name__ == 'Enum': output += signature.format(name=t.name) @@ -543,6 +521,21 @@ static inline void vl_api_{name}_t_endian (vl_api_{name}_t *a) output += "/***** manual: vl_api_%s_t_endian *****/\n\n" % t.name continue + + if t.__class__.__name__ == 'Using': + output += signature.format(name=t.name) + if ('length' in t.alias and t.alias['length'] and + t.alias['type'] == 'u8'): + output += (' /* a->{name} = a->{name} (no-op) */\n' + .format(name=t.name)) + elif t.alias['type'] in format_strings: + output += (' *a = {}(*a);\n' + .format(endian_strings[t.alias['type']])) + else: + output += ' /* Not Implemented yet {} */'.format(t.name) + output += '}\n\n' + continue + output += signature.format(name=t.name) for o in t.block: @@ -588,12 +581,11 @@ def run(input_filename, s): output += msg_ids(s) output += msg_names(s) output += msg_name_crc_list(s, filename) - output += typedefs(s['types'] + s['Define'], s['Alias'], - filename + file_extension) - printfun_types(s['types'], s['Alias'], stream, modulename) + output += typedefs(s['types'] + s['Define'], filename + file_extension) + printfun_types(s['types'], stream, modulename) printfun(s['Define'], stream, modulename) output += stream.getvalue() - output += endianfun(s['types'] + s['Define'], s['Alias'], modulename) + output += endianfun(s['types'] + s['Define'], modulename) output += version_tuple(s, basename) output += bottom_boilerplate.format(input_filename=basename, file_crc=s['file_crc']) diff --git a/src/tools/vppapigen/vppapigen_json.py b/src/tools/vppapigen/vppapigen_json.py index ef1c9823c33..f67a3d62da1 100644 --- a/src/tools/vppapigen/vppapigen_json.py +++ b/src/tools/vppapigen/vppapigen_json.py @@ -58,7 +58,6 @@ def walk_defs(s, is_message=False): r.append(d) return r - # # Plugin entry point # @@ -74,6 +73,6 @@ def run(filename, s): if o.__class__.__name__ == 'Enum'])) j['services'] = walk_services(s['Service']) j['options'] = s['Option'] - j['aliases'] = {k: v.alias for k, v in s['Alias'].items()} + j['aliases'] = {o.name:o.alias for o in s['types'] if o.__class__.__name__ == 'Using'} j['vl_api_version'] = hex(s['file_crc']) return json.dumps(j, indent=4, separators=(',', ': ')) |