aboutsummaryrefslogtreecommitdiffstats
path: root/ice40/transform_arachne_loc.py
blob: 1479284527f8106ef8d7a97e5c3c8fa4e824eea7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
import json
import sys
import re

with open(sys.argv[1]) as f:
    data = json.load(f)
    
for mod, moddata in data["modules"].items():
    if "cells" in moddata:
        for cell, celldata in moddata["cells"].items():
            pos = re.split('[,/]', celldata["attributes"]["loc"])
            pos = [int(_) for _ in pos]
            if celldata["type"] == "ICESTORM_LC":
                celldata["attributes"]["BEL"] = "X%d/Y%d/lc%d" % (pos[0], pos[1], pos[2])
            elif celldata["type"] == "SB_IO":
                celldata["attributes"]["BEL"] = "X%d/Y%d/io%d" % (pos[0], pos[1], pos[2])
            elif "RAM" in celldata["type"]:
                celldata["attributes"]["BEL"] = "X%d/Y%d/ram" % (pos[0], pos[1])
            elif celldata["type"] == "SB_GB":
                celldata["attributes"]["BEL"] = "X%d/Y%d/gb" % (pos[0], pos[1])
            else:
                assert False
print(json.dumps(data, sort_keys=True, indent=4))