Skip to content

Commit

Permalink
floogen(pkg): Sort endpoint enum correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fischeti committed Dec 19, 2024
1 parent 72dabb2 commit 3322272
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
8 changes: 5 additions & 3 deletions floogen/model/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ def compile_nis(self):
# 1D array case
case (_,):
node_idx = self.graph.get_node_arr_idx(ni_name)[0]
ni_dict["arr_idx"] = SimpleId(id=node_idx)
if ep_desc.is_sbr():
ni_dict["addr_range"] = [
rng.model_copy().set_idx(node_idx) for rng in ep_desc.addr_range
Expand Down Expand Up @@ -749,9 +750,10 @@ def render_nis(self):

def render_ep_enum(self):
"""Render the endpoint enum in the generated code."""
fields_dict = {
ep.name: self.graph.get_node_uid(node_obj=ep).id for ep in self.graph.get_ni_nodes()
}
fields_dict = {}
for ni in self.graph.get_ni_nodes():
name = ni.render_enum_name()
fields_dict[name] = self.graph.get_node_uid(node_obj=ni).id
fields_dict = dict(sorted(fields_dict.items(), key=lambda item: item[1]))
fields_dict["num_endpoints"] = len(fields_dict)
return sv_enum_typedef(name="ep_id_e", fields_dict=fields_dict)
Expand Down
11 changes: 10 additions & 1 deletion floogen/model/network_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pydantic import BaseModel
from mako.lookup import Template

from floogen.model.routing import Id, SimpleId, AddrRange, Routing, RouteMap
from floogen.model.routing import Id, SimpleId, Coord, AddrRange, Routing, RouteMap
from floogen.model.protocol import AXI4
from floogen.model.link import NarrowWideLink, AxiLink
from floogen.model.endpoint import EndpointDesc
Expand Down Expand Up @@ -47,6 +47,15 @@ def is_only_mgr(self) -> bool:
"""Return true if the network interface is only a manager."""
return self.endpoint.is_mgr() and not self.endpoint.is_sbr()

def render_enum_name(self) -> str:
"""Render the enum name."""
name = f"{self.endpoint.name}"
if isinstance(self.arr_idx, Coord):
name += f"_x{self.arr_idx.x}_y{self.arr_idx.y}"
elif isinstance(self.arr_idx, SimpleId):
name += f"_{self.arr_idx.id}"
return name


class AxiNI(NetworkInterface):
""" Axi Network Interface class."""
Expand Down
2 changes: 1 addition & 1 deletion floogen/templates/floo_axi_chimney.sv.mako
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ floo_axi_chimney #(
.id_i ( id_t'(${ni.id.render()}) ),
% endif
% if ni.routing.route_algo.value == 'SourceRouting':
.route_table_i ( RoutingTables[${snake_to_camel(ni.name)}] ),
.route_table_i ( RoutingTables[${snake_to_camel(ni.render_enum_name())}] ),
% else:
.route_table_i ( '0 ),
% endif
Expand Down
2 changes: 1 addition & 1 deletion floogen/templates/floo_nw_chimney.sv.mako
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ floo_nw_chimney #(
.id_i ( id_t'(${ni.id.render()}) ),
% endif
% if ni.routing.route_algo.value == 'SourceRouting':
.route_table_i ( RoutingTables[${snake_to_camel(ni.name)}] ),
.route_table_i ( RoutingTables[${snake_to_camel(ni.render_enum_name())}] ),
% else:
.route_table_i ( '0 ),
% endif
Expand Down

0 comments on commit 3322272

Please sign in to comment.