summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-16 10:26:58 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-03-17 18:35:11 +0100
commita90129557a396280018ce1055dc94c522bcf2a56 (patch)
tree63fa25215c0617e87dc69168bb9b0329ba90c07c
parentvalidation: Add post-condition expressions (diff)
downloadrtems-central-a90129557a396280018ce1055dc94c522bcf2a56.tar.bz2
validation: Further reduce source code/rodata size
-rw-r--r--rtemsspec/tests/test_validation.py101
-rw-r--r--rtemsspec/validation.py57
2 files changed, 90 insertions, 68 deletions
diff --git a/rtemsspec/tests/test_validation.py b/rtemsspec/tests/test_validation.py
index 3c8614ae..5a0f165b 100644
--- a/rtemsspec/tests/test_validation.py
+++ b/rtemsspec/tests/test_validation.py
@@ -620,55 +620,59 @@ typedef struct {
#define E( x0, x1, x2, x3, x4, x5) { x0, x1, x2, x3, \\
Directive_Post_Status_##x4, Directive_Post_Id_##x5 }
+#define EZ( x0, x1) { 0, 0, 0, 0, Directive_Post_Status_##x0, \\
+ Directive_Post_Id_##x1 }
+
static const Directive_Entry
Directive_Map[] = {
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, Self ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, LocalTask ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, Self ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, LocalTask ),
+ EZ( InvAddr, NullPtr ),
#if defined(RTEMS_MULTIPROCESSING)
- E( 0, 0, 0, 0, Ok, RemoteTask ),
+ EZ( Ok, RemoteTask ),
#else
- E( 0, 0, 0, 0, InvName, Nop ),
+ EZ( InvName, Nop ),
#endif
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, InvName, Nop ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, LocalTask ),
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
+ EZ( InvAddr, NullPtr ),
+ EZ( InvName, Nop ),
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, LocalTask ),
+ EZ( InvAddr, NullPtr ),
#if defined(RTEMS_MULTIPROCESSING)
- E( 0, 0, 0, 0, Ok, RemoteTask ),
+ EZ( Ok, RemoteTask ),
#else
- E( 0, 0, 0, 0, InvName, Nop ),
+ EZ( InvName, Nop ),
#endif
- E( 0, 0, 0, 0, InvAddr, NullPtr ),
- E( 0, 0, 0, 0, Ok, LocalTask )
+ EZ( InvAddr, NullPtr ),
+ EZ( Ok, LocalTask )
};
#undef E
+#undef EZ
static size_t Directive_Scope( void *arg, char *buf, size_t n )
{
@@ -2119,20 +2123,22 @@ typedef struct {
#define E( x0, x1, x2, x3, x4, x5) { x0, x1, x2, x3, Action2_Post_A_##x4, \\
Action2_Post_B_##x5 }
+#define EZ( x0, x1) { 0, 0, 0, 0, Action2_Post_A_##x0, Action2_Post_B_##x1 }
+
static const Action2_Entry
Action2_Map[] = {
- E( 0, 0, 0, 0, A1, B0 ),
- E( 0, 0, 0, 0, A1, B0 ),
- E( 0, 0, 0, 0, A1, B0 ),
+ EZ( A1, B0 ),
+ EZ( A1, B0 ),
+ EZ( A1, B0 ),
E( 0, 1, 0, 0, A1, NA ),
E( 0, 1, 0, 0, A1, NA ),
E( 0, 1, 0, 0, A1, NA ),
- E( 0, 0, 0, 0, A2, B0 ),
- E( 0, 0, 0, 0, A2, B0 ),
- E( 0, 0, 0, 0, A2, B0 ),
- E( 0, 0, 0, 0, A2, B0 ),
- E( 0, 0, 0, 0, A2, B0 ),
- E( 0, 0, 0, 0, A3, B0 ),
+ EZ( A2, B0 ),
+ EZ( A2, B0 ),
+ EZ( A2, B0 ),
+ EZ( A2, B0 ),
+ EZ( A2, B0 ),
+ EZ( A3, B0 ),
E( 0, 1, 0, 0, A1, NA ),
E( 0, 1, 0, 0, A1, NA ),
E( 0, 1, 0, 0, A1, NA ),
@@ -2142,6 +2148,7 @@ Action2_Map[] = {
};
#undef E
+#undef EZ
static size_t Action2_Scope( void *arg, char *buf, size_t n )
{
diff --git a/rtemsspec/validation.py b/rtemsspec/validation.py
index ae4b2c9d..6c2af084 100644
--- a/rtemsspec/validation.py
+++ b/rtemsspec/validation.py
@@ -813,16 +813,24 @@ class TransitionMap:
return transition_map
def _get_entry(self, variant: Transition) -> str:
- args = ", ".join(
- itertools.chain(
- [str(variant.skip)], map(str, variant.pre_cond_na),
- (self._post_co_idx_st_idx_to_st_name[co_idx][st_idx]
- for co_idx, st_idx in enumerate(variant.post_cond))))
+ skip_pre_cond_na = (variant.skip, ) + variant.pre_cond_na
+ for value in skip_pre_cond_na:
+ if value != 0:
+ text = "E( " + ", ".join(
+ itertools.chain(
+ map(str, skip_pre_cond_na),
+ (self._post_co_idx_st_idx_to_st_name[co_idx][st_idx]
+ for co_idx, st_idx in enumerate(variant.post_cond))))
+ break
+ else:
+ text = "EZ( " + ", ".join(
+ self._post_co_idx_st_idx_to_st_name[co_idx][st_idx]
+ for co_idx, st_idx in enumerate(variant.post_cond))
wrapper = textwrap.TextWrapper()
wrapper.initial_indent = " "
wrapper.subsequent_indent = " "
wrapper.width = 75
- return "\n".join(wrapper.wrap("E( " + args)) + " ),"
+ return "\n".join(wrapper.wrap(text)) + " ),"
def _get_entry_bits(self) -> int:
bits = self._pre_co_count + 1
@@ -830,6 +838,25 @@ class TransitionMap:
bits += math.ceil(math.log2(len(st_idx_to_st_name)))
return 2**max(math.ceil(math.log2(bits)), 3)
+ def _add_entry_macro(self, content: CContent, ident: str, name: str,
+ pre_count_0: int, pre_count_1: int) -> None:
+ # pylint: disable=too-many-arguments
+ entry = f"#define {name}( "
+ entry += ", ".join(
+ f"x{index}" for index in range(pre_count_0 + self._post_co_count))
+ entry += ") { "
+ entry += ", ".join(
+ itertools.chain(
+ (f"x{index}" for index in range(pre_count_0)),
+ ("0" for index in range(pre_count_1)),
+ (f"{ident}_Post_{condition['name']}_##x{pre_count_0 + co_idx}"
+ for co_idx, condition in enumerate(self["post-conditions"]))))
+ wrapper = textwrap.TextWrapper()
+ wrapper.initial_indent = ""
+ wrapper.subsequent_indent = " "
+ wrapper.width = 77
+ content.add(" \\\n".join(wrapper.wrap(entry)) + " }")
+
def add_map(self, content: CContent, ident: str) -> None:
""" Adds the transition map definitions to the content. """
entries = []
@@ -859,24 +886,12 @@ class TransitionMap:
f"uint{bits}_t Post_{condition['name']} : {state_bits};")
content.add(f"}} {ident}_Entry;")
pre_count = 1 + self._pre_co_count
- entry = "#define E( "
- entry += ", ".join(f"x{index}"
- for index in range(pre_count + self._post_co_count))
- entry += ") { "
- entry += ", ".join(
- itertools.chain(
- (f"x{index}" for index in range(pre_count)),
- (f"{ident}_Post_{condition['name']}_##x{pre_count + co_idx}"
- for co_idx, condition in enumerate(self["post-conditions"]))))
- wrapper = textwrap.TextWrapper()
- wrapper.initial_indent = ""
- wrapper.subsequent_indent = " "
- wrapper.width = 77
- content.add(" \\\n".join(wrapper.wrap(entry)) + " }")
+ self._add_entry_macro(content, ident, "E", pre_count, 0)
+ self._add_entry_macro(content, ident, "EZ", 0, pre_count)
content.add([f"static const {ident}_Entry", f"{ident}_Map[] = {{"])
entries[-1] = entries[-1].replace("),", ")")
content.append(entries)
- content.append(["};", "", "#undef E"])
+ content.append(["};", "", "#undef E", "#undef EZ"])
def get_post_entry_member(self, co_idx: int) -> str:
"""