I am starting a project to convert a medium size Matlab codebase (~100 files, total of ~10K LOC) into C/C++. (That is, the end product needs to be runnable without Matlab.) I have been reading documentation and tutorials about using MATLAB Coder to generate C code, but all of these seem to be based on converting just one or two files, not a large code base.
Some notes about the codebase:
The call graph is a tree, with a single root (the "main function"). The "main function" processes data in a data file and outputs some results.
It is easy for me to generate test data files, and run it through the program to get results. However, the codebase currently has no unit tests.
After conversion, the C/C++ code will have to be maintained. It will no longer be necessary to continue maintaining the Matlab code.
I have some questions about best practices for converting a codebase from Matlab to C++.
It appears that when you tell MATLAB Coder to convert a particular file, it will convert that file as well as all files that are called by it. This means that if you tell MATLAB Coder to convert the "main function" it will effectively convert the entire project. (Do I have this right?) In general, is it best to (a) convert the entire codebase at once this way, or (b) convert the functions one at a time, starting at the leaves of the call graph, re-running the test data each time to ensure nothing changes? (And, if we use (b), that means that at the intermediate phases, we will need a way to call the C functions from Matlab. What is the best way to do this?)
Some of the code contains global variables. Is there anything special that you ahve to do when converting code from Matlab to C that uses global variables?
If there is a problem with the conversion I will want to know which function the problem is in. One way I was thinking to do this is to run the test data sets on the Matlab code, and each time a function is called, record the inputs to the function and the outputs. Then when a function is converted to C, I could run that function with the "recorded" inputs and see if I get the same outputs back (to ensure the new function behave the same way as the old function). Are there any automated tools that do this? (Or is there a feature in MATLAB Coder that provides similar functionality?)
Are there any other particular pitfalls to be aware of when converting a large codebase using MATLAB Coder?
What resources are there to learn more about best practices for converting a codebase from one language to another language in general?
Aucun commentaire:
Enregistrer un commentaire