Engee documentation

Code Generator in Engee

Code generation via the graphical interface

Generating code for a subsystem

To generate code through the graphical interface Engee right-click on the subsystem (block Subsystem):

codegen subsystem ui en

In this way, you can generate code from any selected subsystem in the model.

The generated code is located in a directory named modelname_Subsystem_code in the same directory where the model is located (or in the current directory if the model has not yet been saved to disk). Here modelname is the name of the model, `Subsystem' is the name of the subsystem, and `code' is the suffix added to the name of the directory with the generated code. For example, for a block named Subsystem in the newmodel_1 model:

subsystem generated 1 en

After the generation is completed in the window model diagnostics model diagnosis main A notification about successful code generation will appear.

Generating code for the top level of the model

To create the code of the entire model in the graphical interface Engee click Generate code codegen icon 1, located on the workspace toolbar.

In the drop-down menu next to the generation button, the target platform Engee should be selected (selected by default).

Code generation button for the top level of the model

The generated code is located in a directory named modelname_code in the same directory where the model is located (or in the current directory if the model has not yet been saved to disk). Here modelname is the name of the model, and code is the suffix added to the name of the directory with the generated code. For example, for the newmodel_1 model (subsystem not selected):

model generated 1 en

Code generation via command line or interactive script

To generate code in Engee, use the command engee.generate_code in command prompt img 41 1 2 or script editor interactive script icon.

Generating code for a subsystem

To generate the subsystem code, specify the full path to the subsystem using the 'subsystem_name` argument. The full path to the subsystem includes its name in the model.

Function signature:

engee.generate_code(
    model_path::String,
    output_dir::String;
    subsystem_name::String = nothing,
    subsystem_id::String = nothing,
    target::String = "c",
    template_path::String = ""
)

Arguments:

  • path/to/modelname.engee::String: absolute or relative path to the model from which the code is generated. The argument can be a model object (an object of the model type obtained by the 'engee.gcm` function).

  • path/to/output_dir::String: absolute or relative path to the directory where the generated code will be saved. If the output_dir directory does not exist, it will be created automatically.

  • subsystem_name=path/to/subsystem::String: the full path to the atomic subsystem from which the code is generated.

  • subsystem_id = subsystem_id::String: unique identifier of the atomic subsystem from which the code is generated.

  • `target::String': specifies the language for code generation. The supported languages are `C' (by default) or `Verilog'.

  • template_path::String: path to the user’s .a jl template (for example, with the main function) used when generating code. If not specified, the by default template is used.

If the subsystem_name or subsystem_id parameters are specified, then code generation for the subsystem is performed. If none of them is specified, generation is performed for the entire model.

Example:

# Generation of C code for a subsystem
engee.generate_code("/user/newmodel_1.engee", "/user/newmodel_1/Subsystem")

# Code generation for an atomic subsystem by its id
engee.generate_code(
    "/user/newmodel_1.engee",
    "/user/newmodel_1/Subsystem";
    subsystem_name = "Subsystem",
    subsystem_id = "88275e0b-a049-4bb5-b8c7-057badd1b536"
)

If an incorrect subsystem_id is specified, the generation will fail with an error, even if `subsystem_name' is specified correctly. In such cases, Engee will not be able to find the subsystem, and the code will not be generated. Therefore, it is more reliable to use only subsystem_name (if it is unique in the model).

Generating code for the model

To generate code from the entire model, specify the path to the model and the directory to save the generated code. If the model is already open in Engee, you can pass the model object received using the function engee.gcm).

Function signature:

engee.generate_code(
    path/to/modelname.engee::String,
    path/to/output_dir::String;
    target::String
)

Arguments:

  • path/to/modelname.engee::String: absolute or relative path to the model from which the code is generated. The argument can be a model object (an object of the model type obtained by the 'engee.gcm` function).

  • path/to/output_dir::String: absolute or relative path to the directory where the generated code will be saved. If the output_dir directory does not exist, it will be created automatically.

  • `target::String': specifies the language for code generation. The supported languages are `C' (by default) or `Verilog'.

Example:

# The absolute path to the model
engee.generate_code("/user/newmodel_1.engee", "/user/newmodel_1/codegen_output")

# Relative path to the model
engee.generate_code("newmodel_1.engee", "newmodel_1/codegen_output")

# Getting the current open model and generating code from it
m = engee.gcm()
engee.generate_code(m, "/user/newmodel_1/codegen_output")