From b86f7c5f278a35e4d9248dd2e9d9b726e1ca3023 Mon Sep 17 00:00:00 2001 From: Pierce Date: Wed, 9 Sep 2015 14:28:05 -0700 Subject: [PATCH] Removed duplicate code. --- p4c_bm/plugin/sai/inc/sai_templ.h | 41 +------------------ p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp | 40 +------------------ p4c_bm/plugin/sai/src/sai_templ.c | 39 +----------------- p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift | 44 +-------------------- p4c_bm/templates/inc/pd.h | 41 +------------------ p4c_bm/templates/src/p4_pd_rpc_server.ipp | 38 +----------------- p4c_bm/templates/src/pd.c | 41 +------------------ 7 files changed, 7 insertions(+), 277 deletions(-) diff --git a/p4c_bm/plugin/sai/inc/sai_templ.h b/p4c_bm/plugin/sai/inc/sai_templ.h index cc85d5d..ee3d809 100644 --- a/p4c_bm/plugin/sai/inc/sai_templ.h +++ b/p4c_bm/plugin/sai/inc/sai_templ.h @@ -20,46 +20,7 @@ limitations under the License. #include //:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_" - -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "uint8_t" -//:: elif byte_width == 2: -//:: return "uint16_t" -//:: elif byte_width <= 4: -//:: return "uint32_t" -//:: else: -//:: return "uint8_t *" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * //:: for table, t_info in table_info.items(): diff --git a/p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp b/p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp index 0c0e7c0..096777e 100644 --- a/p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp +++ b/p4c_bm/plugin/sai/src/p4_sai_rpc_server.cpp @@ -76,45 +76,7 @@ class sai_p4_saiHandler : virtual public sai_p4_saiIf { return 0; } -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "uint8_t" -//:: elif byte_width == 2: -//:: return "uint16_t" -//:: elif byte_width <= 4: -//:: return "uint32_t" -//:: else: -//:: return "const std::string&" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * //:: for table, t_info in table_info.items(): diff --git a/p4c_bm/plugin/sai/src/sai_templ.c b/p4c_bm/plugin/sai/src/sai_templ.c index dcbd0bc..d99bf4d 100644 --- a/p4c_bm/plugin/sai/src/sai_templ.c +++ b/p4c_bm/plugin/sai/src/sai_templ.c @@ -136,44 +136,7 @@ typedef enum { } p4_table_opcode_t; -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "uint8_t" -//:: elif byte_width == 2: -//:: return "uint16_t" -//:: elif byte_width <= 4: -//:: return "uint32_t" -//:: else: -//:: return "uint8_t *" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params_name(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: params += [("action_" + name, width, name)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * //:: for table, t_info in table_info.items(): /* diff --git a/p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift b/p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift index b4b682c..770760e 100644 --- a/p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift +++ b/p4c_bm/plugin/sai/thrift/p4_sai_rpc.thrift @@ -53,49 +53,7 @@ struct sai_attribute_list { 3: list attr_list; } -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "byte" -//:: elif byte_width == 2: -//:: return "i16" -//:: elif byte_width <= 4: -//:: return "i32" -//:: elif byte_width == 6: -//:: return "MacAddr_t" -//:: elif byte_width == 16: -//:: return "IPv6_t" -//:: else: -//:: return "string" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * # Match structs diff --git a/p4c_bm/templates/inc/pd.h b/p4c_bm/templates/inc/pd.h index 9022063..c294b8c 100644 --- a/p4c_bm/templates/inc/pd.h +++ b/p4c_bm/templates/inc/pd.h @@ -22,46 +22,7 @@ limitations under the License. #include //:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_" - -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "uint8_t" -//:: elif byte_width == 2: -//:: return "uint16_t" -//:: elif byte_width <= 4: -//:: return "uint32_t" -//:: else: -//:: return "uint8_t *" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * /* MATCH STRUCTS */ diff --git a/p4c_bm/templates/src/p4_pd_rpc_server.ipp b/p4c_bm/templates/src/p4_pd_rpc_server.ipp index b0bfd94..def6cd2 100644 --- a/p4c_bm/templates/src/p4_pd_rpc_server.ipp +++ b/p4c_bm/templates/src/p4_pd_rpc_server.ipp @@ -33,43 +33,7 @@ public: //:: #endfor } -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "const int8_t" -//:: elif byte_width == 2: -//:: return "const int16_t" -//:: elif byte_width <= 4: -//:: return "const int32_t" -//:: else: -//:: return "const std::string&" -//:: #endif -//:: #enddef -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths, _get_type = get_type): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef +//:: from common import * //:: //:: def gen_pd_args(params): //:: # Need to coerce strings to appropriate type diff --git a/p4c_bm/templates/src/pd.c b/p4c_bm/templates/src/pd.c index d3ca6aa..01dc337 100644 --- a/p4c_bm/templates/src/pd.c +++ b/p4c_bm/templates/src/pd.c @@ -37,18 +37,6 @@ limitations under the License. //:: p4_pd_prefix = "p4_pd_" + p4_prefix + "_" //:: -//:: def get_type(byte_width): -//:: if byte_width == 1: -//:: return "uint8_t" -//:: elif byte_width == 2: -//:: return "uint16_t" -//:: elif byte_width <= 4: -//:: return "uint32_t" -//:: else: -//:: return "uint8_t *" -//:: #endif -//:: #enddef -//:: //:: def get_num_match_bits(match_fields, field_info): //:: num_bits = 0 //:: for field, type in match_fields: @@ -59,34 +47,7 @@ limitations under the License. //:: return num_bits //:: #enddef //:: -//:: -//:: # match_fields is list of tuples (name, type) -//:: def gen_match_params(match_fields, field_info): -//:: params = [] -//:: for field, type in match_fields: -//:: if type == "valid": -//:: params += [(field + "_valid", 1)] -//:: continue -//:: #endif -//:: f_info = field_info[field] -//:: bytes_needed = (f_info["bit_width"] + 7 ) / 8 -//:: params += [(field, bytes_needed)] -//:: if type == "lpm": params += [(field + "_prefix_length", 2)] -//:: if type == "ternary": params += [(field + "_mask", bytes_needed)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: def gen_action_params(names, byte_widths): -//:: params = [] -//:: for name, width in zip(names, byte_widths): -//:: name = "action_" + name -//:: params += [(name, width)] -//:: #endfor -//:: return params -//:: #enddef -//:: -//:: +//:: from common import * //:: for table, t_info in table_info.items(): //:: if not t_info["match_fields"]: continue