Transformations between bus signals and legacy C structures involving pointers in C S-functions

1 view (last 30 days)
Hello, I am implementing our legacy C Code into C MEX S-functions. The legacy functions take as a general rule pointer to structures involving pointer to further structures, example legacy code:
func.h:
typedef struct {
double* param;
}T_DATA_1;
typedef struct {
double in;
double out;
T_DATA_1* pParam;
}T_DATA_2;
func.c:
void func(T_DATA_2 *pData){
pData->out = pData->in + *(pData->pParam->param);
}
I already know that I can wrap manually, e.g., the input bus signal to the legacy structure in the C S-fucntion just like in the following code segment:
void wrap_BussignalToLegacy(T_DATA_2 *pLegacy, T_DATA_2__BUSOBJ *pInput){
pLegacy->in = pInput->in;
pLegacy->out = pInput->out;
*(pLegacy->pParam->param) = pInput->pParam.param;
}
with an appropriate structure for the bus signal removing all pointer declarations.
typedef struct {
double param;
}T_DATA_1__BUSOBJ;
typedef struct {
double in;
double out;
T_DATA_1 pParam;
}T_DATA_2__BUSOBJ;
Of course I have to write a similiar function to wrap the legacy structure back to the output bus signal.
Using this method manually just works fine but for the case that structures are becoming larger with increasing amount of pointers to further structures, it will take a tremendous time to write appropriate signal wrappers.
One idea involves writing, e.g., a MATLAB parser which analyzes the legacy structures and generates C Code which is called in the C S-functions.
Does anyone already know that such a parser and code generator exists open source?
The workaround to iterate over all structure fields via pointer arithmetic will fail because memory size is not known beforehand. As an alternative to iterations, X-Macros can be used but would still depend on a parser and code generator.
Does anyone know further workarounds to handle legacy pointer structures including pointer to further structures?
Thanks for any help!

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!