Skip to content

Commit

Permalink
Fix how string parameters are handled
Browse files Browse the repository at this point in the history
Internal-tag: [#65044]
Signed-off-by: bbrzyski <bbrzyski@internships.antmicro.com>
  • Loading branch information
bbrzyski committed Sep 4, 2024
1 parent 15dbc01 commit 1cc95eb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/source/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ ips:
parameters:
wb_ram_data_instance:
depth: 0x1000
memfile: "top_sram.init"
memfile: '"top_sram.init"'
wb_ram_instr_instance:
depth: 0xA000
memfile: "bios.init"
memfile: '"bios.init"'
```

Note that string parameters have to be wrapped in single quotation marks like this: `'"string value"'`.

- Connect desired ports of the IP cores:

```yaml
Expand Down
2 changes: 1 addition & 1 deletion examples/soc/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ design:
depth: 0x1000
wb_ram_instr:
depth: 0xA000
memfile: "build/bios.init"
memfile: '"build/bios.init"'
ports:
wb_ram_data:
sys_clk: clk100
Expand Down
4 changes: 2 additions & 2 deletions tests/data/data_build/interconnect/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ design:
parameters:
wb_ram_data:
depth: 0x1000
memfile: "top_sram.init"
memfile: '"top_sram.init"'
wb_ram_instr:
depth: 0xA000
memfile: "top_rom.init"
memfile: '"top_rom.init"'
ports:
wb_ram_data:
sys_clk: clk100
Expand Down
17 changes: 17 additions & 0 deletions tests/tests_build/test_ip_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def axi_dispctrl_ipw_overriden(axi_dispctrl_name, axi_dispctrl_path) -> IPWrappe
)


@pytest.fixture
def axi_dispctrl_ipw_custom_params(axi_dispctrl_name, axi_dispctrl_path) -> IPWrapper:
return IPWrapper(
axi_dispctrl_path,
axi_dispctrl_name,
axi_dispctrl_name,
{"EX_WIDTH": 8, "EVAL_WIDTH": "EX_WIDTH/2", "EX_STRING": '"STRING"'},
)


# ----------------------------------------------------------------------------
# Names of ports that should be created while initializing `IPWrapper` objects
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -169,3 +179,10 @@ def test_get_port_by_interface(self, axi_dispctrl_ipw, axi_dispctrl_interfaces):

with pytest.raises(ValueError):
axi_dispctrl_ipw.get_ports_of_interface("non_existing_iface_name")

def test_params_evalutaion(self, axi_dispctrl_ipw_custom_params):
assert axi_dispctrl_ipw_custom_params._parameters == {
"p_EX_WIDTH": 8,
"p_EVAL_WIDTH": 4.0,
"p_EX_STRING": "STRING",
}
3 changes: 2 additions & 1 deletion topwrap/ipwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ def _evaluate_parameters(params: dict):
params[name] = simple_eval(param, names=params)
except Exception as e:
error(f"evaluating expression {name} failed with the following message: {str(e)}")
raise


def _eval_bounds(bounds, params):
def _eval_bounds(bounds, params: dict):
"""Replace parameter-dependent values with numbers"""
result = bounds[:]
for i, item in enumerate(bounds):
Expand Down

0 comments on commit 1cc95eb

Please sign in to comment.