Skip to content

Commit

Permalink
Add support for project files to code optimizer
Browse files Browse the repository at this point in the history
Ref. eng/recordflux/RecordFlux#1766
  • Loading branch information
treiher committed Aug 29, 2024
1 parent 42ec1b0 commit dfb5354
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 196 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Vim and Neovim syntax highlighting support (eng/recordflux/RecordFlux#1749)
- Project file support in code optimizer (eng/recordflux/RecordFlux#1766)

### Changed

- CLI subcommand `rflx optimize` expects project file instead of directory containing generated code (eng/recordflux/RecordFlux#1766)
- Improve generation of predicate for single-field messages (eng/recordflux/RecordFlux#1761)

### Removed

- CLI flag `--optimize` of `rflx generate` subcommand (eng/recordflux/RecordFlux#1766)
- CLI option `--timeout` of `rflx generate` and `rflx optimize` subcommands (eng/recordflux/RecordFlux#1766)

## [0.23.0] - 2024-08-23

### Changed
Expand Down
3 changes: 3 additions & 0 deletions doc/user_guide/20-overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ As only successfully verified specifications are guaranteed to lead to provable
SPARK source files are generated into the directory specified by the `-d` switch on the command line.
The result can be included in the list of source directories and analyzed by `gnatprove` as usual (see the `SPARK User’s Guide <https://docs.adacore.com/live/wave/spark2014/html/spark2014_ug/>`_ for details).

The Optimizer reduces the size of the generated state machine code.
In order to use the Optimizer, a project file for the SPARK code must be provided by the user and passed as an argument to `rflx optimize`.

The Validator is available through the `rflx validate` subcommand on the command line.
It can be used to check whether a message specification correctly formalizes real-world data, or vice versa, whether a given data sample corresponds to the specification.
Two types of samples can be used: valid samples which must be accepted by a specification (passed with the `-v` option) and invalid samples which must be rejected (passed with the `-i` option).
Expand Down
6 changes: 1 addition & 5 deletions doc/user_guide/90-rflx-generate--help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ usage: rflx generate [-h] [-p PREFIX] [-n] [-d OUTPUT_DIRECTORY]
[--debug {built-in,external}]
[--ignore-unsupported-checksum]
[--integration-files-dir INTEGRATION_FILES_DIR]
[--reproducible] [--optimize] [--timeout TIMEOUT]
[--reproducible]
[SPECIFICATION_FILE ...]

positional arguments:
Expand All @@ -21,7 +21,3 @@ options:
--integration-files-dir INTEGRATION_FILES_DIR
directory for the .rfi files
--reproducible ensure reproducible output
--optimize optimize generated state machine code (requires
GNATprove)
--timeout TIMEOUT prover timeout in seconds for code optimization
(default: 1)
7 changes: 3 additions & 4 deletions doc/user_guide/90-rflx-optimize--help.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
usage: rflx optimize [-h] [--timeout TIMEOUT] DIRECTORY
usage: rflx optimize [-h] PROJECT_FILE

positional arguments:
DIRECTORY directory containing the generated code
PROJECT_FILE project file

options:
-h, --help show this help message and exit
--timeout TIMEOUT prover timeout in seconds (default: 1)
-h, --help show this help message and exit
33 changes: 7 additions & 26 deletions rflx/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,6 @@ def main( # noqa: PLR0915
action="store_true",
help="ensure reproducible output",
)
parser_generate.add_argument(
"--optimize",
action="store_true",
help="optimize generated state machine code (requires GNATprove)",
)
parser_generate.add_argument(
"--timeout",
type=int,
default=1,
help="prover timeout in seconds for code optimization (default: %(default)s)",
)
parser_generate.add_argument(
"files",
metavar="SPECIFICATION_FILE",
Expand All @@ -258,18 +247,13 @@ def main( # noqa: PLR0915
help="optimize generated state machine code",
)
parser_optimize.add_argument(
"--timeout",
type=int,
default=1,
help="prover timeout in seconds (default: %(default)s)",
)
parser_optimize.add_argument(
"directory",
metavar="DIRECTORY",
"project_file",
metavar="PROJECT_FILE",
type=Path,
help="directory containing the generated code",
help="project file",
)
parser_optimize.set_defaults(func=optimize)

parser_graph = subparsers.add_parser("graph", help="generate graphs")
parser_graph.add_argument(
"-f",
Expand Down Expand Up @@ -523,15 +507,12 @@ def generate(args: argparse.Namespace) -> None:
top_level_package=args.prefix == DEFAULT_PREFIX,
)

if args.optimize:
optimizer.optimize(args.output_directory, args.workers, args.timeout)


def optimize(args: argparse.Namespace) -> None:
if not args.directory.is_dir():
fail(f'directory not found: "{args.directory}"')
if not args.project_file.is_file():
fail(f'project file not found: "{args.project_file}"')

optimizer.optimize(args.directory, args.workers, args.timeout)
optimizer.optimize(args.project_file)


def parse(
Expand Down
3 changes: 3 additions & 0 deletions rflx/generator/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from rflx.common import file_name
from rflx.identifier import ID

GENERATED_BY_RECORDFLUX: Final = "Generated by RecordFlux"

REFINEMENT_PACKAGE = ID("Contains")
STATE_MACHINE_PACKAGE = ID("FSM")

ARITHMETIC_PACKAGE = ID("RFLX_Arithmetic")
BUILTIN_TYPES_CONVERSIONS_PACKAGE = ID("RFLX_Builtin_Types.Conversions")
Expand Down
4 changes: 2 additions & 2 deletions rflx/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,7 @@ def _license_header(self) -> str:
common.comment_box(
[
"",
"Generated by RecordFlux",
const.GENERATED_BY_RECORDFLUX,
"",
"Copyright (C) AdaCore",
"",
Expand All @@ -1591,7 +1591,7 @@ def _license_header(self) -> str:
common.comment_box(
[
"",
f"Generated by RecordFlux {__version__} on {today}",
f"{const.GENERATED_BY_RECORDFLUX} {__version__} on {today}",
"",
f"Copyright (C) 2018-{today.year} AdaCore",
"",
Expand Down
Loading

0 comments on commit dfb5354

Please sign in to comment.