The Code Generator (Tutorial)
RTflow can generate C, C++, Java and VHDL code from the model, so that it can be implemented in both software and hardware in a real-world application. First of all, you must supply a code generation template in the target language with special keys (e.g. %OUTPUT_UPDATE_EQUATIONS%) indicating where the generated information should be inserted. The code generator reads the template file and makes a copy of it, but where all keys have been replaced with the corresponding information or code. Default template files for all four target languages are supplied with RTflow and can be found under the Templates folder in the application folder.
Generate C++ code
- First open the file Templates/Template.cpp in any text editor. Notice that it is a valid C++ file with the exception for the code generation keys with their % characters.
- In RTflow, choose Project:Generate Code or press F10.
- When asked to set up code generation, choose OK.
- The Code Generation page of the Project Settings dialog appears. In the Code Generator drop-down list, choose C/C++/Java.
- In the Top-Level Node drop-down list, choose Counter as the schematic from which code should be generated.
- Click Browse... to the right of the Template File edit box and choose Templates/Template.cpp in the file selector that appears.
- Select a suitable output folder and enter Generated.cpp in the Output File edit box.
- Leave the three remaining checkboxes unchanged and click OK.
- Open the generated file Generated.cpp in any text editor and examine the results.
Generate VHDL code
- Now open the file Template/Template.vhd in the text editor. Notice that it is a valid VHDL file with the exception for the code generation keys with their % characters.
- In RTflow, choose Project:Settings... to open the Project Settings dialog and click the Code Generation tab.
- In the Code Generator drop-down list, choose VHDL.
- Click Browse... to the right of the Template File edit box and choose Templates/Template.vhd in the file selector that appears.
- Select a suitable output folder and enter Generated.vhd in the Output File edit box.
- Leave the two remaining checkboxes unchanged and click OK.
- Choose Project:Generate Code or press F10 to generate the code.
- Open the generated file Generated.vhd in any text editor and examine the results.