Skip to content

Commit

Permalink
Make In_IO_State function public
Browse files Browse the repository at this point in the history
Closes #1155
  • Loading branch information
senier committed Aug 29, 2022
1 parent 24f18c1 commit 091f0df
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Generator:
- Add precondition `Uninitialized` to procedure `Initialize` (#788)
- Add operators for `Length` and `Index` types (#1070)
- Overwrite symlinks when creating files
- Make `In_IO_State` session function public (#1155)

PyRFLX:

Expand Down
42 changes: 27 additions & 15 deletions rflx/generator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def is_global(identifier: ID) -> bool:
unit += self._create_reset_messages_before_write_procedure(self._session, is_global)

unit += self._create_tick_procedure(self._session, has_reads)
unit += self._create_run_procedure(self._session)
unit += self._create_in_io_state_function(self._session)
unit += self._create_run_procedure()
unit += self._create_state_function()

if has_writes:
Expand Down Expand Up @@ -1134,7 +1135,7 @@ def _create_tick_procedure(self, session: model.Session, has_writes: bool) -> Un
)

@staticmethod
def _create_run_procedure(session: model.Session) -> UnitPart:
def _create_in_io_state_function(session: model.Session) -> UnitPart:
io_states = [
state
for state in session.states
Expand All @@ -1148,6 +1149,30 @@ def _create_run_procedure(session: model.Session) -> UnitPart:
)
)
]
in_io_state_specification = FunctionSpecification(
"In_IO_State",
"Boolean",
[Parameter(["Ctx" if io_states else "Unused_Ctx"], "Context'Class")],
)
return UnitPart(
[
SubprogramDeclaration(in_io_state_specification),
],
[
ExpressionFunctionDeclaration(
in_io_state_specification,
In(
Variable("Ctx.P.Next_State"),
ChoiceList(*[Variable(f"S_{state.identifier}") for state in io_states]),
)
if io_states
else FALSE,
),
],
)

@staticmethod
def _create_run_procedure() -> UnitPart:
specification = ProcedureSpecification("Run", [InOutParameter(["Ctx"], "Context'Class")])
return UnitPart(
[
Expand All @@ -1162,19 +1187,6 @@ def _create_run_procedure(session: model.Session) -> UnitPart:
Pragma("Warnings", [Variable("On"), String('subprogram "Run" has no effect')]),
],
[
ExpressionFunctionDeclaration(
FunctionSpecification(
"In_IO_State",
"Boolean",
[Parameter(["Ctx" if io_states else "Unused_Ctx"], "Context'Class")],
),
In(
Variable("Ctx.P.Next_State"),
ChoiceList(*[Variable(f"S_{state.identifier}") for state in io_states]),
)
if io_states
else FALSE,
),
SubprogramBody(
specification,
[],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Unused_Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ is

pragma Warnings (On, "subprogram ""Tick"" has no effect");

function In_IO_State (Ctx : Context'Class) return Boolean;

pragma Warnings (Off, "subprogram ""Run"" has no effect");

procedure Run (Ctx : in out Context'Class) with
Expand Down

0 comments on commit 091f0df

Please sign in to comment.