import barectf.config as barectf_config
import collections
import copy
-import re
from typing import List, Optional, Mapping, Callable, Any, Set, Tuple
import typing
from barectf.typing import Count, Alignment
return typing.cast(_Op, ret_op)
ds_ops = create_ds_ops()
- c_src = self._create_file_template('barectf.c.j2').render(header_file_name=header_file_name,
- bitfield_header_file_name=bitfield_header_file_name,
- root_ft_prefixes=_RootFtPrefixes,
- root_ft_prefix_names=_ROOT_FT_PREFIX_NAMES,
- ds_ops=ds_ops,
- ds_op_pkt_ctx_op=ds_op_pkt_ctx_op)
-
- # Jinja 2 makes it hard to have multiple contiguous blocks
- # delimited with empty lines when using a for loop, while not
- # also having an empty line at the end.
- #
- # Therefore, we often get this rendered pattern:
- #
- # /* ... */
- # ...;
- # ...;
- #
- # /* ... */
- # ...;
- # ...;
- # ...;
- #
- # }
- #
- # It's ugly, so fix it here.
- return re.sub(r'(\n)\s*\n(\s*})', r'\1\2', c_src)
+ return self._create_file_template('barectf.c.j2').render(header_file_name=header_file_name,
+ bitfield_header_file_name=bitfield_header_file_name,
+ root_ft_prefixes=_RootFtPrefixes,
+ root_ft_prefix_names=_ROOT_FT_PREFIX_NAMES,
+ ds_ops=ds_ops,
+ ds_op_pkt_ctx_op=ds_op_pkt_ctx_op)
end:
return;
}
- {% if dst._er_header_ft %}
+ {% if dst._er_header_ft %}
static void _serialize_er_header_{{ dst.name }}(void * const vctx,
const uint32_t ert_id)
{
{{ this_ds_ops.er_header_op.serialize_str(dst=dst) | indent_tab }}
}
+
{% endif %}
{% if dst.event_record_common_context_field_type %}
-
static void _serialize_er_common_ctx_{{ dst.name }}(void * const vctx{{ dst | serialize_er_common_ctx_func_params_str(const_params) }})
{
struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
{{ this_ds_ops.er_common_ctx_op.serialize_str(dst=dst) | indent_tab }}
}
+
{% endif %}
{# internal serialization functions #}
{% for ert in dst.event_record_types | sort %}
-
static void _serialize_er_{{ dst.name }}_{{ ert.name }}(void * const vctx{{ (dst, ert) | trace_func_params_str(const_params) }})
{
struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
{{ this_er_ops.payload_op.serialize_str(dst=dst, ert=ert) | indent_tab }}
{% endif %}
}
+
{% endfor %}
{# internal size functions #}
{% for ert in dst.event_record_types | sort %}
{% set this_er_ops = this_ds_ops.er_ops[ert] %}
-
static uint32_t _er_size_{{ dst.name }}_{{ ert.name }}(void * const vctx{{ (dst, ert) | trace_func_params_str(const_params, only_dyn=true) }})
{
struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx);
return at - ctx->at;
}
+
{% endfor %}
{# public tracing functions #}
{% for ert in dst.event_record_types | sort %}
-
{% include 'c/trace-func-proto.j2' %}
{
end:
return;
}
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
{% endfor %}
{% include 'c/open-func-proto.j2' %};
{% include 'c/close-func-proto.j2' %};
- {% for ert in dst.event_record_types | sort %}
+ {% for ert in dst.event_record_types | sort %}
{% include 'c/trace-func-proto.j2' %};
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
{% endfor %}
for ({{ var_name }} = 0; {{ var_name }} < (uint32_t) {{ length_src }}; ++{{ var_name }}) {
{% for subop in op.subops %}
{{ subop.serialize_str(dst=dst, ert=ert) | indent_tab(2) }}
-
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
}
}
{
{% for subop in op.subops %}
{{ subop.serialize_str(dst=dst, ert=ert) | indent_tab }}
-
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
}
for ({{ var_name }} = 0; {{ var_name }} < (uint32_t) {{ length_src }}; ++{{ var_name }}) {
{% for subop in op.subops %}
{{ subop.size_str(dst=dst, ert=ert) | indent_tab(2) }}
-
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
}
}
{
{% for subop in op.subops %}
{{ subop.size_str(dst=dst, ert=ert) | indent_tab }}
-
+ {% if not loop.last %}{{ '\n' }}{% endif %}
{% endfor %}
}