barectf.c.j2: do not pass useless parameters to _ev_size_*() functions
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:48:48 +0000 (11:48 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 3 Sep 2020 15:48:48 +0000 (11:48 -0400)
This patch changes _CodeGen._proto_params_str() in `gen.py` to accept a
`only_dyn` parameter. When `only_dyn` is `True`, then the function only
generates function prototype parameter strings for field types which
have a dynamic size (string field types, as of this version).

This patch also changes the ft_call_params() macro to add an `only_dyn`
parameter which serves the same purpose.

The purpose of this is not calling the _ev_size_*() functions with
parameters which correspond to statically-sized field types.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
barectf/cgen.py
barectf/templates/c/barectf.c-macros.j2
barectf/templates/c/barectf.c.j2

index e566313216689503d0c020a6a8e5413c4556cb40..ebc85e131843ef5cf1bd8a1d30e404de6e1b4dc6 100644 (file)
@@ -419,7 +419,8 @@ class _CodeGen:
     # Each parameter has the prefix `name_prefix` followed with `_`.
     #
     # Members of which the name is in `exclude_set` are excluded.
-    def _proto_params_str(self, root_ft, name_prefix, const_params, exclude_set=None):
+    def _proto_params_str(self, root_ft, name_prefix, const_params, exclude_set=None,
+                          only_dyn=False):
         if root_ft is None:
             return
 
@@ -432,6 +433,9 @@ class _CodeGen:
             if member_name in exclude_set:
                 continue
 
+            if only_dyn and not member.field_type.size_is_dynamic:
+                continue
+
             params.append(_FtParam(member.field_type, member_name))
 
         return self._func_proto_params_templ.render(params=params, prefix=name_prefix,
@@ -457,26 +461,29 @@ class _CodeGen:
 
     # Returns the tracing function prototype parameters for the stream
     # and event types `stream_ev_types`.
-    def _trace_func_params_str(self, stream_ev_types, const_params):
+    def _trace_func_params_str(self, stream_ev_types, const_params, only_dyn=False):
         stream_type = stream_ev_types[0]
         ev_type = stream_ev_types[1]
         parts = []
 
         if stream_type._ev_header_ft is not None:
             parts.append(self._proto_params_str(stream_type._ev_header_ft, _RootFtPrefixes.EH,
-                                                const_params, {'id', 'timestamp'}))
+                                                const_params, {'id', 'timestamp'},
+                                                only_dyn=only_dyn))
 
         if stream_type.event_common_context_field_type is not None:
             parts.append(self._proto_params_str(stream_type.event_common_context_field_type,
-                                                _RootFtPrefixes.ECC, const_params))
+                                                _RootFtPrefixes.ECC, const_params,
+                                                only_dyn=only_dyn))
 
         if ev_type.specific_context_field_type is not None:
             parts.append(self._proto_params_str(ev_type.specific_context_field_type,
-                                                _RootFtPrefixes.SC, const_params))
+                                                _RootFtPrefixes.SC, const_params,
+                                                only_dyn=only_dyn))
 
         if ev_type.payload_field_type is not None:
             parts.append(self._proto_params_str(ev_type.payload_field_type, _RootFtPrefixes.P,
-                                                const_params))
+                                                const_params, only_dyn=only_dyn))
 
         return ''.join(parts)
 
index 4ed0add297d38b13b9db5b682bad559fdd2f73a7..4af19562a721753cacd398989d3d5d2e2544a3be 100644 (file)
@@ -55,10 +55,12 @@ const int saved_in_tracing_section = ctx->in_tracing_section;
  #
  #     , ecc_peer_id, ecc_addr, p_msg_id, p_msg
  #}
-{% macro ft_call_params(param_prefix, ft) %}
+{% macro ft_call_params(param_prefix, ft, only_dyn=false) %}
 {% if ft %}
-       {% for member_name in ft.members %}
+       {% for member_name, member in ft.members.items() %}
+               {% if not only_dyn or member.field_type.size_is_dynamic %}
 , {{ param_prefix }}_{{ member_name }}
-       {%- endfor %}
+               {%- endif %}
+       {% endfor %}
 {% endif %}
 {% endmacro %}
index 258dd7c68a11537bca6eacec97d8e71c7c97445f..c5655f34aad6f56a12cfaa99add8e263a1038cc8 100644 (file)
@@ -456,7 +456,7 @@ static void _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(void * const
        {% for ev_type in stream_type.event_types | sort %}
                {% set this_ev_ops = this_stream_ops.ev_ops[ev_type] %}
 
-static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params) }})
+static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const vctx{{ (stream_type, ev_type) | trace_func_params_str(const_params, only_dyn=true) }})
 {
        struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
        uint32_t at = ctx->at;
@@ -527,9 +527,9 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const
        ctx->in_tracing_section = 1;
 
        /* Compute event size */
-               {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type) %}
-               {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type) %}
-               {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type) %}
+               {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type, true) %}
+               {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type, true) %}
+               {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type, true) %}
                {% set params %}{{ ev_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %}
        ev_size = _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(_TO_VOID_PTR(ctx){{ params }});
 
@@ -541,6 +541,10 @@ static uint32_t _ev_size_{{ stream_type.name }}_{{ ev_type.name }}(void * const
        }
 
        /* Serialize event */
+               {% set ev_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ECC, stream_type.event_common_context_field_type) %}
+               {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.SC, ev_type.specific_context_field_type) %}
+               {% set payload_params = macros.ft_call_params(root_ft_prefixes.P, ev_type.payload_field_type) %}
+               {% set params %}{{ ev_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %}
        _serialize_ev_{{ stream_type.name }}_{{ ev_type.name }}(_TO_VOID_PTR(ctx){{ params }});
 
        /* Commit event */
This page took 0.025617 seconds and 4 git commands to generate.