Batch Code Generation
Swan code generator can be run in batch mode.
Introduction
The Swan code generator executable
SWAN-CG is named:
- swan_cg.exe on Windows platform
- swan_cg on Linux platform
Command Line Syntax
SWAN-CG CONFIG_FILENAME [-basic]
SWAN-CG [parameters]
where:
- SWAN-CG is in <Scade One installation>\tools
CONFIG_FILENAMEis the JSON configuration file containing the options of the code generator (see details in the Appendices and in the table describing the property keywords later)-basicallows to generate code in the basic mode limiting the availability of several options (see details in the table describing the property keywords later)parameters, optional argument, are defined below:Parameters Description -h To display help information -help To display help information -version To display version information
Examples:
swan_cg.exe -h
swan_cg.exe -version
swan_cg.exe config_cg.jsonwhere config_cg.json is the
JSON configuration file provided in the example next section.Property Keywords of the JSON Configuration File
The following table describes the property keywords available for the JSON
configuration file:
The associated schema is specified using JSON Schema, see details in the
Appendices.
| Property Keywords | Description | Basic Mode |
|---|---|---|
files | Required. List of input files (Swan files of the input model with extension .swan or .swani, absolute paths or path relative to the configuration file). | Available |
roots | Required. List of paths to the root declarations of the input model (operators, types, constants, sensors). | Available |
target_dir |
Path to the directory where SWAN-CG generates its outputs. Can be relative, relative paths are relative to the configuration file directory. By default, output files are generated in a sub-directory named swan in the working directory. | Available |
target | Target language of the generated code. Available value:
"C". If '"target" option
is absent, no code is generated. | Available |
expansion |
Expansion of operators, set one of the following:
| Available |
keep_asserts | "true" = keep assume/guarantees in generated code. "false" by default. | Not available |
short_circuit | "true" = generate short-circuit Boolean operators. "false" by default. | Not available |
wrap_c_ops | "true" = generate macro calls for predefined operators. "false" by default. | Not available |
name_length | Set the maximum length of C identifiers. 200 by default. | Not available |
significance_length | Set the number of significant initial characters of C identifiers. 31 by default. | Not available |
static_locals | "true" = declare C local variables as static. "false" by default. | Not available |
globals_prefix | Specify a prefix (string) for C global identifiers. “” by default. | Not available |
metadata | Metadata for this file (timestamp generation, etc.) . Ignored by the code generator. | Available |
Example:
{
"files": [
"C:\\MyFirstModelWithSwan\\Final\\WeatherStation\\assets\\Station.swan",
"C:\\MyFirstModelWithSwan\\Final\\WeatherStation\\assets\\Thermometer.swan",
"C:\\MyFirstModelWithSwan\\Final\\WeatherStation\\assets\\Utils.swan",
"C:\\libraries\\Sources\\assets\\Sources.swan",
"C:\\libraries\\Math\\assets\\Math.swan",
"C:\\libraries\\Time\\assets\\Time.swan",
"C:\\libraries\\Piecewise\\assets\\Piecewise.swan"
],
"roots": [ "Thermometer::ToCelsius", "Thermometer::ToFarenheit" ],
"target_dir":
"C:\\MyFirstModelWithSwan\\Final\\WeatherStation\\jobs\\codegen_25bac60\\out",
"target": "C",
"expansion": [
"NoExpand", ["Thermometer::ToCelsius", "Thermometer::ToFarenheit" ]
],
"keep_asserts": true,
"short_circuit": true,
"wrap_c_ops": true,
"name_length": 250,
"significance_length": 50,
"static_locals": true,
"globals_prefix": "Weather",
"metadata": {
"date": "2023-10-30T10:44:58.6494792Z"
}
}Outputs
SWAN-CG returns an exit status defined as follows:
- if the log file cannot be written: 4
- or, if there are some failures: 3
- or, if there are some errors: 2
- otherwise: 0