def gen_rtl(block: IpBlock, outdir: str) -> int:
    # Read Register templates
    reg_top_tpl = Template(
        filename=resource_filename('reggen', 'reg_top.sv.tpl'))
    reg_pkg_tpl = Template(
        filename=resource_filename('reggen', 'reg_pkg.sv.tpl'))

    # Generate <block>_reg_pkg.sv
    #
    # This defines the various types used to interface between the *_reg_top
    # module(s) and the block itself.
    reg_pkg_path = os.path.join(outdir, block.name.lower() + "_reg_pkg.sv")
    with open(reg_pkg_path, 'w', encoding='UTF-8') as fout:
        try:
            fout.write(reg_pkg_tpl.render(block=block))
        except:  # noqa F722 for template Exception handling
            log.error(exceptions.text_error_template().render())
            return 1

    # Generate the register block implementation(s). For a device interface
    # with no name we generate the register module "<block>_reg_top" (writing
    # to <block>_reg_top.sv). In any other case, we also need the interface
    # name, giving <block>_<ifname>_reg_top.
    lblock = block.name.lower()
    for if_name, rb in block.reg_blocks.items():
        if if_name is None:
            mod_base = lblock
        else:
            mod_base = lblock + '_' + if_name.lower()

        mod_name = mod_base + '_reg_top'
        reg_top_path = os.path.join(outdir, mod_name + '.sv')
        with open(reg_top_path, 'w', encoding='UTF-8') as fout:
            try:
                fout.write(reg_top_tpl.render(block=block,
                                              mod_base=mod_base,
                                              mod_name=mod_name,
                                              if_name=if_name,
                                              rb=rb))
            except:  # noqa F722 for template Exception handling
                log.error(exceptions.text_error_template().render())
                return 1

    return 0