Last active
January 14, 2019 02:55
-
-
Save sbourdeauducq/fdf00f0fc771584c1ae3cb01be9b1ed6 to your computer and use it in GitHub Desktop.
quick and dirty hack to extract GTH transceiver parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
from pyverilog.vparser.parser import parse | |
from pyverilog.vparser import ast | |
topnode, directives = parse(["/home/sb/ultrascaletest/ultrascaletest.srcs/sources_1/ip/gtwizard_ultrascale_0/synth/gtwizard_ultrascale_0_gthe3_channel_wrapper.v"]) | |
gth_inst = None | |
def ast_walk(nodes): | |
global gth_inst | |
for node in nodes: | |
if isinstance(node, ast.InstanceList): | |
assert node.instances[0].module == "gtwizard_ultrascale_v1_7_5_gthe3_channel" | |
assert gth_inst is None | |
gth_inst = node.instances[0] | |
elif hasattr(node, "children"): | |
ast_walk(node.children()) | |
parameters = OrderedDict() | |
ports = OrderedDict() | |
prefix_len = len("GTHE3_CHANNEL_") | |
ast_walk([topnode]) | |
for c in gth_inst.children(): | |
if isinstance(c, ast.ParamArg): | |
if c.paramname == "NUM_CHANNELS" or c.paramname.endswith("_TIE_EN"): | |
continue | |
if c.paramname.endswith("_VAL"): | |
is_port = True | |
name = c.paramname[:-4] | |
else: | |
is_port = False | |
name = c.paramname | |
name = name[prefix_len:] | |
value_obj = c.children()[0] | |
if isinstance(value_obj, ast.IntConst): | |
if "'b" in value_obj.value: | |
value_fmt = "0b" + value_obj.value.partition("'b")[2] | |
else: | |
value_fmt = value_obj.value | |
elif isinstance(value_obj, ast.StringConst): | |
value_fmt = "\"" + value_obj.value + "\"" | |
else: | |
value_fmt = value_obj.value | |
if is_port: | |
ports["i_" + name] = value_fmt | |
else: | |
parameters[name] = value_fmt | |
elif isinstance(c, ast.PortArg): | |
name = c.portname[prefix_len:] | |
if "i_" + name not in ports: | |
ports["o_" + name] = "" | |
for k, v in parameters.items(): | |
print("p_{}={},".format(k, v)) | |
for k, v in ports.items(): | |
print("{}={},".format(k, v)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment