File: dbfixup.py

package info (click to toggle)
prjtrellis 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 83,000 kB
  • sloc: cpp: 20,813; python: 16,246; sh: 375; makefile: 262; asm: 80; ansic: 58
file content (73 lines) | stat: -rw-r--r-- 2,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pytrellis

"""
Database fix utility

Run at the end of fuzzing to "finalise" the database and remove problems that may occur during fuzzing.

The remaining functions can be called in other fuzzers as necessary.
"""


def dbfixup(family, device, tiletype):
    db = pytrellis.get_tile_bitdata(
        pytrellis.TileLocator(family, device, tiletype))

    fc = db.get_fixed_conns()
    # Where a wire is driven by both a mux and fixed connections, replace those fixed connections
    # with a mux arc with no config bits
    for mux in db.get_sinks():
        deleteFc = False
        for conn in fc:
            if conn.sink == mux:
                ad = pytrellis.ArcData()
                ad.source = conn.source
                ad.sink = conn.sink
                db.add_mux_arc(ad)
                deleteFc = True
        if deleteFc:
            db.remove_fixed_sink(mux)
    db.save()


def remove_enum_bits(family, device, tiletype, lowerright, upperleft=(0, 0)):
    """
    Remove bits from enumerations in a given tile that actually belong
    to routing bits. This can happen when e.g. routing is required for Diamond
    to set certain bits in the output, as is the case for fuzzing I/O enums
    in PIC_L0 and PIC_R0.

    Bounds are (0,0)-based. Upperleft is inclusive, lowerright is exclusive.
    """
    def in_bounding_box(bit):
        (x, y) = (bit.frame, bit.bit)

        if upperleft[0] > x or upperleft[1] > y:
            return False

        if lowerright[0] <= x or lowerright[1] <= y:
            return False

        return True

    db = pytrellis.get_tile_bitdata(
        pytrellis.TileLocator(family, device, tiletype))

    for enum in db.get_settings_enums():
        fixed_enum = pytrellis.EnumSettingBits()

        for (option, data) in db.get_data_for_enum(enum).options.items():
            fixed_bg = pytrellis.BitGroup()

            for bit in data.bits:
                if in_bounding_box(bit):
                    fixed_bg.bits.add(bit)

            fixed_enum.options[option] = fixed_bg

        fixed_enum.name = db.get_data_for_enum(enum).name
        fixed_enum.defval = db.get_data_for_enum(enum).defval

        db.remove_setting_enum(enum)
        db.add_setting_enum(fixed_enum)
    db.save()