Skip to content

Commit 9efcf59

Browse files
glemcorostedt
authored andcommitted
tools/dot2c: Fix generated files going over 100 column limit
The dot2c.py script generates all states in a single line. This breaks the 100 column limit when the state machines are non-trivial. Change dot2c.py to generate the states in separate lines in case the generated line is going to be too long. Also adapt existing monitors with line length over the limit. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Tomas Glozar <tglozar@redhat.com> Cc: Juri Lelli <jlelli@redhat.com> Cc: Clark Williams <williams@redhat.com> Cc: John Kacur <jkacur@redhat.com> Link: https://lore.kernel.org/20250723161240.194860-4-gmonaco@redhat.com Suggested-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Gabriele Monaco <gmonaco@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 1160cca commit 9efcf59

File tree

2 files changed

+23
-11
lines changed
  • kernel/trace/rv/monitors/snep
  • tools/verification/rvgen/rvgen

2 files changed

+23
-11
lines changed

kernel/trace/rv/monitors/snep/snep.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ static const struct automaton_snep automaton_snep = {
4141
"schedule_exit"
4242
},
4343
.function = {
44-
{ non_scheduling_context_snep, non_scheduling_context_snep, scheduling_contex_snep, INVALID_STATE },
45-
{ INVALID_STATE, INVALID_STATE, INVALID_STATE, non_scheduling_context_snep },
44+
{
45+
non_scheduling_context_snep,
46+
non_scheduling_context_snep,
47+
scheduling_contex_snep,
48+
INVALID_STATE
49+
},
50+
{
51+
INVALID_STATE,
52+
INVALID_STATE,
53+
INVALID_STATE,
54+
non_scheduling_context_snep
55+
},
4656
},
4757
.initial_state = non_scheduling_context_snep,
4858
.final_states = { 1, 0 },

tools/verification/rvgen/rvgen/dot2c.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,30 @@ def __get_max_strlen_of_states(self):
152152
max_state_name = max(self.states, key = len).__len__()
153153
return max(max_state_name, self.invalid_state_str.__len__())
154154

155-
def __get_state_string_length(self):
156-
maxlen = self.__get_max_strlen_of_states() + self.enum_suffix.__len__()
157-
return "%" + str(maxlen) + "s"
158-
159155
def get_aut_init_function(self):
160156
nr_states = self.states.__len__()
161157
nr_events = self.events.__len__()
162158
buff = []
163159

164-
strformat = self.__get_state_string_length()
165-
160+
maxlen = self.__get_max_strlen_of_states() + len(self.enum_suffix)
161+
tab_braces = 2 * 8 + 2 + 1 # "\t\t{ " ... "}"
162+
comma_space = 2 # ", " count last comma here
163+
linetoolong = tab_braces + (maxlen + comma_space) * nr_events > self.line_length
166164
for x in range(nr_states):
167-
line = "\t\t{ "
165+
line = "\t\t{\n" if linetoolong else "\t\t{ "
168166
for y in range(nr_events):
169167
next_state = self.function[x][y]
170168
if next_state != self.invalid_state_str:
171169
next_state = self.function[x][y] + self.enum_suffix
172170

171+
if linetoolong:
172+
line += "\t\t\t%s" % next_state
173+
else:
174+
line += "%*s" % (maxlen, next_state)
173175
if y != nr_events-1:
174-
line = line + strformat % next_state + ", "
176+
line += ",\n" if linetoolong else ", "
175177
else:
176-
line = line + strformat % next_state + " },"
178+
line += "\n\t\t}," if linetoolong else " },"
177179
buff.append(line)
178180

179181
return self.__buff_to_string(buff)

0 commit comments

Comments
 (0)