Kazoo

From TASTE
Revision as of 12:56, 13 December 2019 by Kgrochowski (talk | contribs)
Jump to: navigation, search

Kazoo is a part of the TASTE toolchain responsible for generating code and build scripts from AADL models.

Overview

Kazoo is a a command line tool which processes input AADL models and produces derived models, code and scripts used to build complete system. It facilitates Ocarina for AADL parsing and templates-parser for templates processing and files generation. Standard library of components used by templates is defined by TASTE common models from ocarina_components.aadl file, which includes supported processors, devices, drivers etc. Generated build scripts apart from calling code compilers also run other tools like ocarina and aadl2glueC to create rest of the source code.

Installation and updating

Updating sources

To update kazoo run the following commands in the terminal:

$ cd ~/tool-src/kazoo
$ git checkout master

When command succeeds, kazoo needs to be rebuild to complete installation.

Rebuilding from source

To build kazoo from sources so run the following commands in the terminal:

$ cd ~/tool-src/kazoo
$ make install

Using kazoo

Kazoo is a command line tool, executed from terminal and configured by a list o parameters.

Basic usage

Run the following commands in the terminal.

$ kazoo --output=out --gw --glue --polyorb-hi-c

Kazoo will read the default input AADL models and generate code to the selected output directory. Parameter --output chooses the output directory for generated files (out), --gw enables models and code skeletons generation, --glue enables glue code generation and --polyorb-hi-c turns on use of PolyORB-HI-C runtime.

In the result directory out will be created and filled with generated models and source files.

To build the generated system run following commands in the terminal:

$ cd out
$ make

The output binary files will be located in the directory out/binaries.

Kazoo example

Kazoo comes with a lot of helpful examples.The examples are located in the directory tool-src/kazoo/test/. Every example project contains Makefile, which simplifies the process of the build. For an example, to build project Demo_C run following commands in the terminal:

$ cd ~/tool-src/kazoo/test/Demo_C
$ make

Kazoo help

To obtain complete list of kazoo parameters and options type kazoo --help.

Input files

Kazoo used default TASTE AADL models as input:

  • InterfaceView.aadl
  • DeploymentView.aadl
  • DataView.aadl (+ .asn/.acn models)

New templates for kazoo

To create new set of templates to be used by kazoo copy existing template subdirectory. For example to create new Concurrency View template, execute the following commands:

$ cd ~/tool-src/kazoo/templates/concurrency_view
$ cp -r aadl_2_threads <new subdirectory>

Edit newly created templates and rebuild kazoo. For more details see note about adding new target to TASTE.

Templates locations:

  • Code skeletons: tool-src/kazoo/templates/skeletons
  • Glue code: tool-src/kazoo/templates/glue/language_wrappers
  • Concurrency View: tool-src/kazoo/templates/concurrency_view

Adding new platform to TASTE using Kazoo

The steps required to add new platform to the TASTE was described in the article: Kazoo and FreeRTOS.

Code generation

Kazoo uses provided models to generate four major parts of the final system implementation:

  • Build script - script responsible for final step of code generation and compilation,
  • Code skeletons - actual implementation of functions and their provided interfaces,
  • Glue code - the source code responsible for exchanging parameters and results between interfaces according to DataView.aadl,
  • Concurrency View - the system.aadl and main.aadl files, which will be later used by Ocarina to generate code during build script execution.

Build script

Build script is a single file named build-script.sh which is generated from build-script.tmplt template file. The template files: build-script-gen.tmplt, build-script-func.tmplt and build-script-zip.tmplt are evaluated earlier, and their output is passed to main template as parameters.

Code skeletons

For each function defined in Interface View Kazoo will process each skeleton template (each containing multiple template files). From each processing a one 'Makefile' and one 'implementation' file can be generated (both are optional outputs). This processing algorithm is presented in more detail in the pseudocode below:

for function in InterfaceView:
    for skeleton_template_subdirectory in skeleton_directory:
        makefile_filename = evaluate_optional_template_file("makefile-filename.tmplt")
        function_filename = evaluate_optional_template_file("function-filename.tmplt")
        if evaluate_template_file("trigger.tmplt") is "TRUE":
            for interface in function.required_interfaces:
                evaluate_template_file("interface.tmplt")
            for interface in function.provided_interfaces:
                evaluate_template_file("interface.tmplt")
            if makefile_filename is not empty:
                evaluate_template_file("makefile.tmplt") and save as makefile_filename
            evaluate_template_file("function.tmplt") and (save as function_filename if function_filename is not empty)
    if context_parameters in function:
        evaluate_template_file("context_parameters.tmplt") and save as "<function name>/<implementation lang>/Context-<function name>.asn"

The skeletons templates are responsible for creating code skeletons, which are a placeholders for actual implementation of the functions, provided by the user.

Kazoo uses code skeletons to generate files in folder created according to <function name>/<language>/<src>/ scheme.

Available code skeletons templates

Currently kazoo provides the following code skeletons templates (each stored in separate subdirectory of tool-src/kazoo/templates/skeletons):

  • ada-body
  • ada-source
  • blackbox-c-body
  • blackbox-c-header
  • c-body
  • c-header
  • cpp-body
  • cpp-body-instance
  • cpp-body-type
  • cpp-context
  • cpp-header
  • cpp-header-instance
  • cpp-header-type
  • gui-body
  • gui-enum-defs
  • gui-header
  • gui-runtime-body
  • gui-runtime-debug-body
  • gui-runtime-debug-header
  • gui-runtime-header
  • opengeode-process-body
  • opengeode-structure
  • pragmadev_process_rdd
  • pragmadev_process_rdp
  • pragmadev_scheduled
  • pragmadev_sys_process_rdd
  • simulink
  • timer-manager-body
  • timer-manager-header
  • vdm-body
  • vdm-header

Glue code

For each function defined in Interface View Kazoo will process each glue template (each containing multiple template files). From each processing a one 'Makefile' and one 'implementation' file can be generated (both are optional outputs). This processing algorithm is presented in more detail in the pseudocode below:

for function in InterfaceView:
    for skeleton_template_subdirectory in skeleton_directory:
        makefile_filename = evaluate_optional_template_file("makefile-filename.tmplt")
        function_filename = evaluate_optional_template_file("function-filename.tmplt")
        if evaluate_template_file("trigger.tmplt") is "TRUE":
            for interface in function.required_interfaces:
                evaluate_template_file("interface.tmplt")
            for interface in function.provided_interfaces:
                evaluate_template_file("interface.tmplt")
            if makefile_filename is not empty:
                evaluate_template_file("makefile.tmplt") and save as makefile_filename
            evaluate_template_file("function.tmplt") and (save as function_filename if function_filename is not empty)

Available glue templates

Currently kazoo provides the glue code templates (each stored in separate subdirectory of tool-src/kazoo/templates/glue) listed in table:

Template name Generates
invoke_ri-body build/<function name>/<language>/<function name>_invoke_ri.c
mini-cv build/<function name>/<language>/<function name>_mini_cv.c
system_config build/<function name>/<language>/<function name>_system_config.h
vm_if-body build/<function name>/<language>/<function name>_vm_if.c
vm_if-header build/<function name>/<language>/<function name>_vm_if.h


Concurrency View generation

Kazoo concurrency view templates are processed according to the presented algorithm in pseudocode:

for every subdirectory
    for every node from ConcurrencyView
        evaluate template filesys.tmplt
        evaluate template filenode.tmplt
        evaluate template trigger.tmplt
        if result is equal to “TRUE” then
            for every partition from node:
                evaluate template filepart.tmplt
                evaluate template thread.tmplt and optionally save output to the file
                evaluate template filethread.tmplt
                evaluate template fileblock.tmplt
                evaluate template pi.tmplt
                evaluate template pi.tmplt (with other parameters)
                evaluate template ri.tmplt
                evaluate template block.tmplt and optionally save output to file
                evaluate template partition.tmplt and optionally save output to file
        evaluate template node.tmplt and optionally save output to file
    evaluate template system.tmplt and optionally save output to file

Existing Concurrency View subdirectories

aadl_2_threads

This subdirectory creates file build/system.aadl, which is used by ocarina to create source code of Concurrency View. This subdirectory is processed always.

aadl_3_main

This subdirectory creates file build/main.aadl, which is used by ocarina to create source code of Concurrency View. This subdirectory is processed always.

aadl_4_makefile

This subdirectory creates file build/Makefile.taste. This subdirectory is processed always.

ada_pohi_gpr

This subdirectory creates following files:

  • for every node file with name Makefike.<node name>
  • for every partition file with name <partition name>.gpr

This subdirectory is processed when option -p or --polyorb-hi-c was not used.

ada_wrappers_body

This subdirectory creates files with name build/<partition name>/<partition name>_taste_interface.adb for every partition This subdirectory is processed when option -p or --polyorb-hi-c was not used.

ada_wrappers_source

This subdirectory creates files with name build/<partition name>/<partition name>_taste_interface.ads For every partition. This subdirectory is processed when option -p or --polyorb-hi-c was not used.

air_cgpr

This subdirectory creates files with name build/<node name>/air.cgpr for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

air_gpr

This subdirectory creates files with name build/<node name>/<parition name>_air.gpr for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

air_makefile

This subdirectory creates file build/Makefile.air. This subdirectory is processed when option -p or --polyorb-hi-c was used.

air_port_polling

This subdirectory creates files with name build/<node name>/<partition name>/air_polling.c for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

c_pohi_gpr

This subdirectory creates following files:

  • For every node build/<node name>/Makefile.<node name>
  • For every partition build/<node name>/<partition name>.gpr

This subdirectory is processed when option -p or --polyorb-hi-c was used.

c_pohi_rtems_with_ada_cgpr

This subdirectory creates files with name build/<node name>/rtems_ada.cgpr for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

c_pohi_rtems_with_ada_gpr

This subdirectory creates files with name build/<node name>/<partition name>_rtems_ada.gpr for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

drivers_config

This subdirectory creates file build/drivers_config.asn. This subdirectory is processed always.

pohic_makefile_workaround

This subdirectory creates files with name build/<node name>/gather_<partition name>_filelist.sh for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

pohic_wrappers_body

This subdirectory creates files with name build/<node name>/<partition name>/<partition name>_polyorb_interface.c for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.

pohic_wrappers_header

This subdirectory creates files with name build/<node name>/<partition name>/<partition name>_polyorb_interface.h for every partition. This subdirectory is processed when option -p or --polyorb-hi-c was used.


Under the hood

Kazoo uses Ocarina library to parse input AADL models. The internal representation of system consists of three major structures:

  • InterfaceView
  • DeploymentView
  • ConcurrencyView

The InterfaceView representation contains of list of functions. Every function contains provided and required interfaces. Optionally a function may contain context parameters. The InterfaceView representation contains also connections between provided interfaces and required interfaces. The InterfaceView representation is used to create skeletons and glue code. See Code skeletons generation and Glue code generation.

The DeploymentView constists of Nodes, Buses and connections between them. The Node contains Partitions, Processors and Drivers. The Partition contains a list of bounded functions. The DeploymentView is not directly used for code generation.

The ConcurrencyView is generated from DeploymentView. The ConcurrencyView consists of list of Nodes. Every Node consists of list of Partitions and list of Drivers. Every Partition consists of list of Threads. Every Thread has a list of assigned functions from InterfaceView.

The ConcurrencyView is used for generation of rest of glue code and also middleware integration. See Concurrency View generation.