def process_cell(c): cellName = get_sexp_name(c) cellOrigName = get_sexp_name(c, orig=True) cellContents = get_sexp_list_contents(c) thisCell = Cell(cellName, cellOrigName) view = get_sexp_list(cellContents, "view") # assume the first is netlist view netlistView = view[0] interface = get_sexp_unique_op(get_sexp_list_contents(netlistView), "interface") ports = get_sexp_list(interface[1:], "port") contents = get_sexp_unique_op(get_sexp_list_contents(netlistView), "contents") if contents: instances = get_sexp_list(contents[1:], "instance") nets = get_sexp_list(contents[1:], "net") else: instances = [] nets = [] # add ports, from interface for port in ports: # a port may be an array portName = get_sexp_name(port) portContent = get_sexp_list_contents(port) d = get_sexp_unique_op(portContent, "direction") portDirection = get_sexp_name(d) pNames = portName if isinstance(portName, list) else [portName] for pName in pNames: thisCell.add_port(name=pName, direction=portDirection) # add contents if any for inst in instances: instName = get_sexp_name(inst) # assume the fist is VIEW_NETLIST instView = get_sexp_list_content(inst) instCell = get_sexp_list_content(instView) instLib = get_sexp_list_content(instCell) viewRef = get_sexp_name(instView) cellRef = get_sexp_name(instCell) libRef = get_sexp_name(instLib) thisCell.add_instance(name=instName, libRef=libRef, cellRef=cellRef, viewRef=viewRef) # add nets if any for net in nets: netName = get_sexp_name(net) netConns = get_sexp_list_content(net) netTerminals = get_sexp_list(netConns[1:], "portRef") terms = [ Terminal( get_sexp_name(t), get_sexp_name(get_sexp_list_content(t)) if len(t) > 2 else None) for t in netTerminals ] thisCell.add_net(name=netName, terminals=terms) return thisCell