Skip to content

Commit

Permalink
Remove unnecessary variable for enum member parser and rename paramAc…
Browse files Browse the repository at this point in the history
…tion and objectName for better naming convention. (#474)
  • Loading branch information
r12f authored Dec 9, 2023
1 parent c06909c commit f3be928
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
16 changes: 7 additions & 9 deletions dash-pipeline/SAI/sai_api_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self):
self.type = None
self.isresourcetype = None
self.isreadonly = None
self.objectName = None
self.object_name = None
self.skipattr = None
self.field = None

Expand Down Expand Up @@ -223,7 +223,7 @@ def _parse_sai_object_annotation(self, p4rt_anno_list):
elif kv['key'] == 'isreadonly':
self.isreadonly = kv['value']['stringValue']
elif kv['key'] == 'objects':
self.objectName = kv['value']['stringValue']
self.object_name = kv['value']['stringValue']
elif kv['key'] == 'skipattr':
self.skipattr = kv['value']['stringValue']
else:
Expand All @@ -239,7 +239,6 @@ class SAIEnumMember(SAIObject):
'''
def __init__(self):
super().__init__()
self.sai_name = ""
self.p4rt_value = ""

def parse_p4rt(self, p4rt_member):
Expand All @@ -250,7 +249,6 @@ def parse_p4rt(self, p4rt_member):
{ "name": "INVALID", "value": "AAA=" }
'''
self.sai_name = self.name
self.p4rt_value = p4rt_member


Expand Down Expand Up @@ -413,7 +411,7 @@ def __init__(self):
self.bitwidth = 0
self.default = None
self.ip_is_v6_field_id = 0
self.paramActions = []
self.param_actions = []

def parse_p4rt(self, p4rt_table_action_param, sai_enums, ip_is_v6_param_ids):
'''
Expand Down Expand Up @@ -568,11 +566,11 @@ def __merge_action_params_to_table_params(self, action):
for table_action_param in self.action_params:
# Already have this param in the table.
if table_action_param.name == action_param.name:
table_action_param.paramActions.append(action.name)
table_action_param.param_actions.append(action.name)
break
else:
# New param is found, add it to the table.
action_param.paramActions = [action.name]
action_param.param_actions = [action.name]
self.action_params.append(action_param)


Expand Down Expand Up @@ -646,7 +644,7 @@ def __update_table_param_object_name_reference(self):
table_ref = param.name[:-len("_id")]
for table_name in all_table_names:
if table_ref.endswith(table_name):
param.objectName = table_name
param.object_name = table_name

# Update object name reference for keys
for table in sai_api.tables:
Expand All @@ -656,7 +654,7 @@ def __update_table_param_object_name_reference(self):
table_ref = key.sai_key_name[:-len("_id")]
for table_name in all_table_names:
if table_ref.endswith(table_name):
key.objectName = table_name
key.object_name = table_name


def __parse_sai_table_action(self, p4rt_actions, sai_enums):
Expand Down
10 changes: 5 additions & 5 deletions dash-pipeline/SAI/templates/saiapi.h.j2
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct _sai_{{ table.name }}_t
* @brief {{ key.match_type | capitalize | replace('Lpm', 'LPM') }} matched key {{ key.sai_key_name }}
{% if key.type == 'sai_object_id_t' %}
*
* @objects SAI_OBJECT_TYPE_{{ key.objectName | upper }}
* @objects SAI_OBJECT_TYPE_{{ key.object_name | upper }}
{% endif %}
*/
{{ key.type }} {{ key.sai_key_name | lower }};
Expand Down Expand Up @@ -159,7 +159,7 @@ typedef enum _sai_{{ table.name }}_attr_t
{% if param.skipattr == 'true' %}
{% else %}
/**
* @brief Action {% for action in param.paramActions %}{{ action }}{{ ", " if not loop.last else "" }}{% endfor %} parameter {{ param.name | upper }}
* @brief Action {% for action in param.param_actions %}{{ action }}{{ ", " if not loop.last else "" }}{% endfor %} parameter {{ param.name | upper }}
*
* @type {{ param.type }}
{% if param.isreadonly == 'true' %}
Expand All @@ -179,7 +179,7 @@ typedef enum _sai_{{ table.name }}_attr_t
{% elif param.type == 'bool' %}
* @default false
{% elif param.type == 'sai_object_id_t' %}
* @objects SAI_OBJECT_TYPE_{{ param.objectName | upper }}
* @objects SAI_OBJECT_TYPE_{{ param.object_name | upper }}
* @allownull true
* @default SAI_NULL_OBJECT_ID
{% elif param.field == 's32' %}
Expand All @@ -192,8 +192,8 @@ typedef enum _sai_{{ table.name }}_attr_t
{% endif %}
{% endif %}
{% if table.actions | length > 1 %}
{% if param.paramActions | length > 0 %}
* @validonly {% for action in param.paramActions %}SAI_{{ table.name | upper }}_ATTR_ACTION == SAI_{{ table.name | upper }}_ACTION_{{ action | upper }}{{ " or " if not loop.last else "" }}{% endfor %}
{% if param.param_actions | length > 0 %}
* @validonly {% for action in param.param_actions %}SAI_{{ table.name | upper }}_ATTR_ACTION == SAI_{{ table.name | upper }}_ACTION_{{ action | upper }}{{ " or " if not loop.last else "" }}{% endfor %}

{% endif %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion dash-pipeline/SAI/templates/saienums.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
typedef enum _sai_{{ enum.name }}_t
{
{% for member in enum.members %}
SAI_{{ enum.name | upper }}_{{ member.sai_name | upper }},
SAI_{{ enum.name | upper }}_{{ member.name | upper }},

{% endfor %}
} sai_{{ enum.name }}_t;
Expand Down

0 comments on commit f3be928

Please sign in to comment.