Beispiel #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--chip',
        dest='chips',
        type=str,
        nargs='*',
        help='Chip for which to generate the header (all chips if unspecified)'
    )
    parser.add_argument('--sort',
                        choices=['name', 'address'],
                        default='address',
                        help='Sort key for registers, fields, and enum values')
    parser.add_argument('--guard', type=str, help='Name of the #include guard')
    parser.add_argument('files',
                        metavar='FILE',
                        type=str,
                        nargs='+',
                        help='Register database file')
    args = parser.parse_args()

    regdb = None
    for filename in args.files:
        with open(filename, 'r') as filp:
            db = RegisterDatabase.from_json(json.load(filp))
            if regdb is None:
                regdb = db
            else:
                regdb.update(db)

    deduplicate_enums(regdb)
    deduplicate_register_types(regdb)

    w = HeaderWriter(regdb, guard=args.guard)
    w.print(sys.stdout, sort=args.sort)
Beispiel #2
0
def main():
    # Parse PKT3 types
    with open(sys.argv[1], 'r') as filp:
        packets = parse_packet3(filp)

    # Register database parse
    regdb = None
    for filename in sys.argv[2:]:
        with open(filename, 'r') as filp:
            try:
                db = RegisterDatabase.from_json(json.load(filp))
                if regdb is None:
                    regdb = db
                else:
                    regdb.update(db)
            except json.JSONDecodeError as e:
                print('Error reading {}'.format(sys.argv[1]), file=sys.stderr)
                raise

    # The ac_debug code only distinguishes by gfx_level
    regdb.merge_chips(['gfx8', 'fiji', 'stoney'], 'gfx8')

    # Write it all out
    w = TableWriter()
    w.write(regdb, packets)
Beispiel #3
0
def json_canonicalize(filp, chips = None):
    regdb = RegisterDatabase.from_json(json.load(filp))

    if chips is not None:
        for regmap in regdb.register_mappings():
            assert not hasattr(regmap, 'chips')
            regmap.chips = [chips]

    deduplicate_enums(regdb)
    deduplicate_register_types(regdb)
    deduce_missing_register_types(regdb)
    regdb.garbage_collect()

    return regdb.encode_json_pretty()
Beispiel #4
0
def main():
    regdb = RegisterDatabase()
    for filename in sys.argv[1:]:
        with open(filename, 'r') as filp:
            regdb.update(RegisterDatabase.from_json(json.load(filp)))

    deduplicate_enums(regdb)
    deduplicate_register_types(regdb)

    print(regdb.encode_json_pretty())
def main():
    regdb_filename = sys.argv[1]
    with open(regdb_filename, 'r') as filp:
        regdb = RegisterDatabase.from_json(json.load(filp))

    if len(sys.argv) > 2:
        for regmap in regdb.register_mappings():
            assert not hasattr(regmap, 'chips')
            regmap.chips = [sys.argv[2]]

    deduplicate_enums(regdb)
    deduplicate_register_types(regdb)
    deduce_missing_register_types(regdb)
    regdb.garbage_collect()

    print(regdb.encode_json_pretty())
Beispiel #6
0
                return None

            gfx10_fmt = self.plain_gfx10_formats[key]
            return Object(
                img_format=gfx10_fmt.img_format,
                flags=gfx10_fmt.flags + extra_flags,
            )

        return None


if __name__ == '__main__':
    vk_formats = parse(sys.argv[1])

    with open(sys.argv[2], 'r') as filp:
        db = RegisterDatabase.from_json(json.load(filp))

    gfx10_formats = [
        Gfx10Format(entry) for entry in db.enum('IMG_FORMAT').entries
    ]

    mapping = Gfx10FormatMapping(vk_formats, gfx10_formats)

    formats = []
    for fmt in vk_formats:
        if fmt.name in HARDCODED:
            obj = HARDCODED[fmt.name]
        else:
            obj = mapping.map(fmt)

        if obj is not None:
Beispiel #7
0
    def parse_header(self, filp):
        regdb = RegisterDatabase()
        chips = ['gfx6', 'gfx7', 'gfx8', 'fiji', 'stoney', 'gfx9']

        self.__regmap = None
        self.__fields = None
        self.__field = None
        self.__enumentries = None

        for line in filp:
            if not line.startswith('#define '):
                continue

            line = line[8:].strip()

            comment = None
            m = RE_comment.search(line)
            if m is not None:
                comment = m.group(2) or m.group(4)
                comment = comment.strip()
                line = line[:m.span()[0]].strip()

            split = line.split(None, 1)
            name = split[0]

            m = RE_prefix.match(name)
            if m is None:
                continue

            prefix = m.group(1)
            prefix_address = int(m.group(2), 16)
            name = name[m.span()[1]:]

            if prefix == 'V':
                value = int(split[1], 0)

                for entry in self.__enumentries:
                    if name == entry.name:
                        sys.exit(
                            'Duplicate value define: name = {0}'.format(name))

                entry = Object(name=name, value=value)
                if comment is not None:
                    entry.comment = comment
                self.__enumentries.append(entry)
                continue

            if prefix == 'S':
                self.__fini_field()

                if not name.endswith('(x)'):
                    sys.exit('Missing (x) in S line: {0}'.line)
                name = name[:-3]

                for field in self.__fields:
                    if name == field.name:
                        sys.exit('Duplicate field define: {0}'.format(name))

                m = RE_set_value.match(split[1])
                if m is not None:
                    unshifted_mask = int(m.group(1), 0)
                    shift = int(m.group(2), 0)
                else:
                    m = RE_set_value_no_shift.match(split[1])
                    if m is not None:
                        unshifted_mask = int(m.group(2), 0)
                        shift = 0
                    else:
                        sys.exit('Bad S_xxx_xxx define: {0}'.format(line))

                num_bits = int(math.log2(unshifted_mask + 1))
                if unshifted_mask != (1 << num_bits) - 1:
                    sys.exit('Bad unshifted mask in {0}'.format(line))

                self.__field = Object(
                    name=name,
                    bits=[shift, shift + num_bits - 1],
                )
                if comment is not None:
                    self.__field.comment = comment
                self.__enumentries = []

            if prefix == 'R':
                self.__fini_field()
                self.__fini_register()

                if regdb.register_mappings_by_name(name):
                    sys.exit('Duplicate register define: {0}'.format(name))

                address = int(split[1], 0)
                if address != prefix_address:
                    sys.exit('Inconsistent register address: {0}'.format(line))

                self.__regmap = Object(
                    name=name,
                    chips=self.chips,
                    map=Object(to=self.address_space, at=address),
                )
                self.__fields = []

        self.__fini_field()
        self.__fini_register()
Beispiel #8
0
 def __init__(self, address_space):
     self.regdb = RegisterDatabase()
     self.chips = ['gfx6', 'gfx7', 'gfx8', 'fiji', 'stoney', 'gfx9']
     self.address_space = address_space