Annotations now passing extra parameters to extern function calls
# limitations under the License.
#!/usr/bin/env python
+from hlir16.p4node import P4Node, deep_copy
+from hlir16.hlir16 import get_fresh_node_id
+
def apply_annotations(postfix, extra_args, x):
if (x.methodCall.method.node_type=="PathExpression") :
- x.methodCall.method.ref.name += "_" + postfix
+ new_decl = deep_copy(x.methodCall.method.ref)
+ new_decl.name += "_" + postfix
+ extra_args_types = [ P4Node({'id' : get_fresh_node_id(),
+ 'node_type' : 'Parameter',
+ 'type' : arg.type,
+ 'name' : postfix + "_extra_param",
+ 'direction' : 'in',
+ 'declid' : 0, #TODO: is this important?
+ 'annotations' : []
+ }) for arg in extra_args ]
+ new_decl.type.parameters.parameters.vec += extra_args_types
+ x.methodCall.method.ref = new_decl
x.methodCall.method.path.name += "_" + postfix
x.methodCall.arguments.vec += extra_args
return x
@@ -25,7 +39,9 @@ def search_for_annotations(x):
if (x.node_type == "BlockStatement") :
name_list = [annot.name for annot in x.annotations.annotations.vec if annot.name in available_optimization_annotations]
- arg_list = [annot.expr for annot in x.annotations.annotations.vec if annot.name in available_optimization_annotations]
+ arg_list = []
+ for annot in x.annotations.annotations.vec :
+ if annot.name in available_optimization_annotations : arg_list += annot.expr
if ([] != name_list) :
x.components = map(lambda x : apply_annotations('_'.join(name_list), arg_list, x), x.components)
return x
