Browse Source

tools/generate-wire.py: add option to expose tlv_record_type

Next update adds TLV test vectors: without this, we get a warning
about them being unused.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
pull/2938/head
Rusty Russell 5 years ago
committed by Christian Decker
parent
commit
b10e0e08bb
  1. 7
      tools/gen/header_template
  2. 4
      tools/gen/impl_template
  3. 1
      tools/generate-wire.py

7
tools/gen/header_template

@ -61,6 +61,12 @@ struct ${tlv.struct_name()} {
% for tlv in tlvs.values(): % for tlv in tlvs.values():
struct ${tlv.struct_name()} *${tlv.struct_name()}_new(const tal_t *ctx); struct ${tlv.struct_name()} *${tlv.struct_name()}_new(const tal_t *ctx);
% if tlv.name in options.expose_tlv_type:
#define TLVS_${tlv.name.upper()}_ARRAY_SIZE ${len(tlv.messages)}
extern const struct tlv_record_type tlvs_${tlv.name}[];
% endif
% endfor % endfor
% if options.expose_subtypes and bool(subtypes): % if options.expose_subtypes and bool(subtypes):
% for subtype in subtypes: % for subtype in subtypes:
@ -87,4 +93,5 @@ u8 *towire_${msg.name}(const tal_t *ctx${''.join([f.arg_desc_to() for f in msg.f
bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}const void *p${''.join([f.arg_desc_from() for f in msg.fields.values()])}); bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}const void *p${''.join([f.arg_desc_from() for f in msg.fields.values()])});
% endfor % endfor
#endif /* LIGHTNING_${idem} */ #endif /* LIGHTNING_${idem} */

4
tools/gen/impl_template

@ -200,7 +200,9 @@ static void fromwire_${msg.struct_name()}(const u8 **cursor, size_t *plen, void
} }
% endfor % endfor
static const struct tlv_record_type tlvs_${tlv.name}[] = { <% static = '' if tlv.name in options.expose_tlv_type else 'static '
%>\
${static}const struct tlv_record_type tlvs_${tlv.name}[] = {
% for msg in tlv.messages.values(): % for msg in tlv.messages.values():
{ ${msg.number}, towire_${msg.struct_name()}, fromwire_${msg.struct_name()} }, { ${msg.number}, towire_${msg.struct_name()}, fromwire_${msg.struct_name()} },
% endfor % endfor

1
tools/generate-wire.py

@ -628,6 +628,7 @@ if __name__ == "__main__":
parser.add_argument("-P", "--print_wire", help="generate wire printing source files", parser.add_argument("-P", "--print_wire", help="generate wire printing source files",
action="store_true", default=False) action="store_true", default=False)
parser.add_argument("--page", choices=['header', 'impl'], help="page to print") parser.add_argument("--page", choices=['header', 'impl'], help="page to print")
parser.add_argument('--expose-tlv-type', action='append', default=[])
parser.add_argument('header_filename', help='The filename of the header') parser.add_argument('header_filename', help='The filename of the header')
parser.add_argument('enum_name', help='The name of the enum to produce') parser.add_argument('enum_name', help='The name of the enum to produce')
parser.add_argument("files", help='Files to read in (or stdin)', nargs=REMAINDER) parser.add_argument("files", help='Files to read in (or stdin)', nargs=REMAINDER)

Loading…
Cancel
Save