CLI tool for transforming Simulink-like XML models into deterministic C code (nwocg_run.c).
The tool parses blocks and connections, builds a dependency graph, computes a topological order, and generates a C runtime with struct, init(), step(), and external port descriptors.
InportOutportSumGainUnitDelay
- C++17 compiler: GCC 9+, MSVC 2019+, Clang 10+
- CMake: 3.16+
- pugixml: v1.14 (fetched automatically via
FetchContent)
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildcmake -B build -G "Visual Studio 17 2022"
cmake --build build --config ReleaseTests are built automatically if tests/CMakeLists.txt exists.
Generate C code from XML model:
./build/Release/dsl-codegen model.xml > nwocg_run.cCompile generated code:
gcc -Wall -Wextra -c nwocg_run.c -o nwocg_run.o<System>
<Block Name="In1" SID="1" BlockType="Inport"/>
<Block Name="Sum1" SID="2" BlockType="Sum" Inputs="+-"/>
<Block Name="Kp" SID="3" BlockType="Gain">
<P Name="Gain">1.5</P>
</Block>
<Block Name="Out1" SID="4" BlockType="Outport"/>
<Line><P Name="Src">1#out:1</P><P Name="Dst">2#in:1</P></Line>
<Line><P Name="Src">2#out:1</P><P Name="Dst">3#in:1</P></Line>
<Line><P Name="Src">3#out:1</P><P Name="Dst">4#in:1</P></Line>
</System>Generated C file contains four sections:
- Includes
#include "nwocg_run.h"
#include <stddef.h>
#include <math.h>
- Static struct
static struct {
double sig1;
double sig2;
} nwocg;
All signals are stored as fields.
UnitDelay fields are placed before their first reader.
- Init & Step functions
void nwocg_generated_init()- resets UnitDelay statesvoid nwocg_generated_step()- executes blocks in topological order + UnitDelay flush pass
- External Ports
ext_ports[]
nwocg_generated_ext_ports
nwocg_generated_ext_ports_size
| Return Code | Meaning |
|---|---|
0 |
Success |
1 |
XML parsing, graph, scheduler, or code generation error |
Errors are printed to stderr:
[ERROR] <Module>: <message>. SID=<N>
CLI-утилита для преобразования Simulink-подобных XML-моделей в детерминированный C-код (nwocg_run.c).
Инструмент парсит блоки и соединения, строит граф зависимостей, вычисляет топологический порядок и генерирует runtime с struct, init(), step() и описателями внешних портов.
InportOutportSumGainUnitDelay
- Компилятор C++17: GCC 9+, MSVC 2019+, Clang 10+
- CMake: 3.16+
- pugixml: v1.14 (подтягивается автоматически через
FetchContent)
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildcmake -B build -G "Visual Studio 17 2022"
cmake --build build --config ReleaseТесты собираются автоматически при наличии tests/CMakeLists.txt.
Генерация C-кода из XML:
./build/Release/dsl-codegen model.xml > nwocg_run.cКомпиляция сгенерированного файла:
gcc -Wall -Wextra -c nwocg_run.c -o nwocg_run.o<System>
<Block Name="In1" SID="1" BlockType="Inport"/>
<Block Name="Sum1" SID="2" BlockType="Sum" Inputs="+-"/>
<Block Name="Kp" SID="3" BlockType="Gain">
<P Name="Gain">1.5</P>
</Block>
<Block Name="Out1" SID="4" BlockType="Outport"/>
<Line><P Name="Src">1#out:1</P><P Name="Dst">2#in:1</P></Line>
<Line><P Name="Src">2#out:1</P><P Name="Dst">3#in:1</P></Line>
<Line><P Name="Src">3#out:1</P><P Name="Dst">4#in:1</P></Line>
</System>Сгенерированный C-файл содержит 4 секции:
- Includes
- Static struct — все сигналы как поля структуры
- Функции Init & Step
nwocg_generated_init()- обнуление UnitDelaynwocg_generated_step()- вычисления + flush pass
- External Ports
ext_ports[]nwocg_generated_ext_portsnwocg_generated_ext_ports_size
| Код возврата | Значение |
|---|---|
0 |
Успех |
1 |
Ошибка парсинга XML, графа, планировщика или генерации |
Ошибки выводятся в stderr:
[ERROR] <Модуль>: <сообщение>. SID=<N>