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_FILENAME is 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)
  • -basic allows 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:
    ParametersDescription
    -hTo display help information
    -helpTo display help information
    -versionTo display version information

Examples:

swan_cg.exe -h
swan_cg.exe -version
swan_cg.exe config_cg.json
where 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:
Property KeywordsDescriptionBasic Mode
filesRequired. 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
rootsRequired. 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
targetTarget 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:

  • All the operators expanded
    [ "ExpandAll"],
  • A list of operators to be expanded
    [
     "Expand",
     ["Module1::operator2","Module2::operator3"]
    ],
  • A list of operators not to be expanded
    [
     "NoExpand",
       [ "Module1::operator2", "Module2::operator3"]
    ],
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_lengthSet the maximum length of C identifiers. 200 by default.Not available
significance_lengthSet 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_prefixSpecify a prefix (string) for C global identifiers. “” by default.Not available
metadataMetadata for this file (timestamp generation, etc.) . Ignored by the code generator.Available
The associated schema is specified using JSON Schema, see details in the Appendices.
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
The log file description is presented in the log file chapter, and the definition of failures and errors in the dedicated chapter.