Skip to content

FelipeACXavier/SimulinkParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simulink parser

This parser reads a folder which contains one or multiple Simulink models and outputs a JSON file using the knowledge representation outlined in Enabling Analysis and Reasoning on Software Systems through Knowledge Graph Representation (MSR'23)

To use the parser follow the steps below:

# Create and activate a virtual environment
python -m venv env
source env/bin/activate

# Install the dependencies
pip install -e .

# Run the help menu for further instructions
python simulink_parser.py

Structure

Since Simulink doesn't follow a common object oriented approach, some insights were necessary to make the representation work with it.

The mapping is shown below:

Matlab Representation
Ports Methods
Blocks Classes
Folders Packages
Block parameters Members

Since the Simulink descriptor does not provide the data type of the ports, each method, i.e., port, assumes a "matlab object" data type.

Based on the selected representation, when there is a signal between two blocks in Simulink, the communicating ports are connected through an "invokes" edge type.

Parsing C/C++

To parse the S-Function blocks, the parser requires the srcML tool that does a pretty good job of parsing these source codes. However, this tool needs to be compiled before it can be used. The complete list of dependencies for different operating systems is available in the official build instructions. To compile the tool, follow the instructions below:

# Clone the submodule
git submodule init
git submodule update

# cd into that directory
cd srcML

# Create build directory
mkdir build && cd build

# Prepare to build
cmake -DBoost_INCLUDE_DIR=../../include ../

# Build
make -j4

srcML outputs a specific flavour of XML that is much easier to parse compared to standard C/C++. This is the output used by our S-Function parser.

Known limitations

MathWorks like to change their file structure from time to time what makes it hard to ensure the correct parsing for all the innumerable Matlab/Simulink versions. Taking that in consideration, we decided to limit the scope of the parser to more recent versions. Therefore, the parser was only tested with versions 2018b to 2024b.

To Do

While a lot is already done, this is an ongoing project. The parser was tested with Simulink 2018b until 2024b.

  • Parse C functions embedded as S-Functions
  • Create link between S-Functions and the called C functions

About

This parser reads a folder which contains one or multiple Simulink models and outputs a JSON file using the knowledge representation outlined in this paper: https://doi.org/10.1109/MSR59073.2023.00029

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors