def dump_registers(json_dict, hlir, keep_pragmas=False):
    registers = []
    id_ = 0
    for name, p4_register in hlir.p4_registers.items():
        if p4_register.binding and (p4_register.binding[0] == p4.P4_DIRECT):
            LOG_CRITICAL("'{}' is a direct register; direct registers are not "
                         "supported by bmv2".format(name))
        register_dict = OrderedDict()
        register_dict["name"] = name
        register_dict["id"] = id_
        id_ += 1
        if p4_register.layout is not None:  # pragma: no cover
            LOG_CRITICAL("registers with layout not supported")
        register_dict["bitwidth"] = p4_register.width
        register_dict["size"] = p4_register.instance_count

        if keep_pragmas:
            add_pragmas(register_dict, p4_register)

        registers.append(register_dict)

    json_dict["register_arrays"] = registers