def make_var(key, ksize): name, hex_content = make_const(key._left) const_var = generate_var_name(f"const{ksize}", name) return const_var, hex_content
keys = entry.keys.components key_sizes = [key._left.urtype.size for key in keys] offsets = ["+".join(["0"] + [f'{ksize}' for ksize in key_sizes[0:idx]]) for idx, ksize in enumerate(key_sizes)] varinfos = [make_var(key, ksize) for key, ksize in zip(keys, key_sizes)] for key, ksize, (const_var, hex_content) in zip(keys, key_sizes, varinfos): #[ uint8_t ${const_var}[] = {$hex_content}; for key, ksize, offset, (const_var, hex_content) in zip(keys, key_sizes, offsets, varinfos): #[ memcpy(${key_var} + ((${offset} +7)/8), &${const_var}, ${(ksize+7)//8}); #{ ${table.name}_action_t ${action_var} = { #[ .action_id = action_${action_id}, #{ .${action_id}_params = { for param, value_expr in zip(params, args): _, hex_content = make_const(value_expr.expression) #[ .${param.name} = { ${hex_content} }, // ${value_expr.expression.value} #} }, #} }; mt = table.matchType.name if mt == 'exact': #[ ${mt}_add_promote(TABLE_${table.name}, ${key_var}, (uint8_t*)&${action_var}, true, false); elif mt == 'lpm': # TODO: if there are exact fields as well as an lpm field, make sure that the exact fields are in front lpm_depth = sum((f'{key.right.value:b}'.count('1') if key.node_type == 'Mask' else ksize for key, ksize, (const_var, hex_content) in zip(keys, key_sizes, varinfos))) #[ ${mt}_add_promote(TABLE_${table.name}, ${key_var}, ${lpm_depth}, (uint8_t*)&${action_var}, true, false); elif mt == 'ternary': ternary_expr = keys[0].right #[ ${mt}_add_promote(TABLE_${table.name}, ${key_var}, ${format_expr(ternary_expr)}, (uint8_t*)&${action_var}, true, false);