#!/usr/bin/env python import sys, re if len(sys.argv) != 2: raise ValueError('Filename argument missing') filename = sys.argv[1] with open(filename, 'r') as f: data = f.read() identifiers = re.findall(r"\.INIT\((\d+'d\d+\)\s*\)\s*identifier_str\d+)", data) f = sys.stdout f.write("[\n") for identifier in identifiers: m = re.match(r"(\d+)'d(\d+)\)\s*\)\s*(\S+)", identifier) if m is not None: cell = m.group(3) # the literal must be converted to hex for Vivado Tcl `set_property` init = "{}'h{:X}".format(m.group(1), int(m.group(2))) f.write(' {{ cell = "{}"; init = "{}"; }}\n'.format(cell, init)) f.write("]\n")