<commit_before>
import argparse
import os
import sys
import threading

from litex.soc.tools.remote import RemoteServer
from litex.soc.tools.remote import RemoteClient
from litex.soc.tools.remote import CommUART

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from make import make_args, make_testdir


class ServerProxy(threading.Thread):
    daemon = True

    def __init__(self, port):
        threading.Thread.__init__(self)
        self.port = port
        self.ready = False

    def run(self):
        print("Starting proxy to {}".format(self.port))
        self.comm = CommUART(self.port, 19200)
        self.server = RemoteServer(self.comm)
        self.server.open()
        self.server.start()
        self.ready = True


def connect(desc, *args, **kw):
    parser = argparse.ArgumentParser(description=desc)
    make_args(parser, *args, **kw)
    parser.add_argument("--ipaddress")
    parser.add_argument("--port") #, desc="Serial port")
    args = parser.parse_args()

    if args.port:
        s = ServerProxy(args.port)
        s.start()
        while not s.ready:
            continue

        args.ipaddress = "127.0.0.1"

    elif not args.ipaddress:
        args.ipaddress = "{}.50".format(args.iprange)

    print("Connecting to {}".format(args.ipaddress))
    wb = RemoteClient(args.ipaddress, 1234, csr_csv="{}/csr.csv".format(make_testdir(args)))
    wb.open()
    print()
    print("Device DNA: {}".format(get_dna(wb)))
    print("   Git Rev: {}".format(get_git(wb)))
    print("  Platform: {}".format(get_platform(wb)))
    print()

    return args, wb


def print_memmap(wb):
    print("Memory Map")
    print("-"*20)
    for n, mem in sorted(wb.mems.d.items(), key=lambda i: i[1].base):
        mb = mem.size/1024/1024
        if mb > 1.0:
            extra_str = " ({:4} Mbytes)".format(int(mb))
        else:
            extra_str = ""
        print("{:20} @ 0x{:08x} -- {: 12} kbytes {}".format(n, mem.base, int(mem.size/1024), extra_str))


def get_dna(wb):
    try:
        dna = wb.regs.dna_id.read()
        return hex(dna)
    except KeyError:
        return 'Unknown'


def get_git(wb):
    try:
        commit = wb.regs.git_info_commit.read()
        return hex(commit)[2:]
    except KeyError:<commit_msg>Output if an analyzer is found.<commit_after>
import argparse
import os
import sys
import threading

from litex.soc.tools.remote import RemoteServer
from litex.soc.tools.remote import RemoteClient
from litex.soc.tools.remote import CommUART

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from make import make_args, make_testdir


class ServerProxy(threading.Thread):
    daemon = True

    def __init__(self, port):
        threading.Thread.__init__(self)
        self.port = port
        self.ready = False

    def run(self):
        print("Starting proxy to {}".format(self.port))
        self.comm = CommUART(self.port, 19200)
        self.server = RemoteServer(self.comm)
        self.server.open()
        self.server.start()
        self.ready = True


def connect(desc, *args, **kw):
    parser = argparse.ArgumentParser(description=desc)
    make_args(parser, *args, **kw)
    parser.add_argument("--ipaddress")
    parser.add_argument("--port") #, desc="Serial port")
    args = parser.parse_args()

    if args.port:
        s = ServerProxy(args.port)
        s.start()
        while not s.ready:
            continue

        args.ipaddress = "127.0.0.1"

    elif not args.ipaddress:
        args.ipaddress = "{}.50".format(args.iprange)

    print("Connecting to {}".format(args.ipaddress))
    wb = RemoteClient(args.ipaddress, 1234, csr_csv="{}/csr.csv".format(make_testdir(args)))
    wb.open()
    print()
    print("Device DNA: {}".format(get_dna(wb)))
    print("   Git Rev: {}".format(get_git(wb)))
    print("  Platform: {}".format(get_platform(wb)))
    print("  Analyzer: {}".format(["Yes", "No"][hasattr(wb.regs, "analyzer")]))
    print()

    return args, wb


def print_memmap(wb):
    print("Memory Map")
    print("-"*20)
    for n, mem in sorted(wb.mems.d.items(), key=lambda i: i[1].base):
        mb = mem.size/1024/1024
        if mb > 1.0:
            extra_str = " ({:4} Mbytes)".format(int(mb))
        else:
            extra_str = ""
        print("{:20} @ 0x{:08x} -- {: 12} kbytes {}".format(n, mem.base, int(mem.size/1024), extra_str))


def get_dna(wb):
    try:
        dna = wb.regs.dna_id.read()
        return hex(dna)
    except KeyError:
        return 'Unknown'


def get_git(wb):
    try:
        commit = wb.regs.git_info_commit.read()
        return hex(commit)[2:]
    except KeyError:
{'fraction_non_alphanumeric': 0.15294627383015597, 'fraction_numerical': 0.018630849220103985, 'mean_word_length': 2.696557245796637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7007818', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1554, 'n_words': 327}