procedures,CGCTarget class maintains 9 more code streams (all protected). These code streams will be stitched together to make the final code in
frameCodemethod. There are two schemes to organize a code in general. One scheme would be to put code strings to a single CodeStream in order. For example, we put global declarations, main function declaration, initialization, and main loop into a single
myCodestream in order. For single processor code generation, it would be feasible. For multiprocessor case, however, the parent target may add some extra code strings. Therefore, we assign different code streams to different section of code. On the other hand, if we have too many code streams, it would be arduous to remember all.
CodeStream globalDecls;These three code streams will be placed in the global scope of the final code. The galaxy declaration (
galStruct)is separated from
globalDeclsbecause we need to put galaxy declaration inside a function if we want to define a function from a galaxy (for example, recursion construct). A programmer can provide strings to
includeby using the following protected CGCStar methods in a star definition:
int addGlobal(const char* decl, const char* name = NULL);In the first method, we use
int addInclude(const char* decl);
declstrings as the name if the second argument is given NULL, to make a global declaration unique. The argument of the second method is the name of a file to be included, for example <stream.h> or "DataStruct.h".
CodeStream mainDecls;These three code streams will be placed in the main function before the main loop: declaration in the main function, initialization code, and initialization code for communication stars. We separated
mainInitsince communication stars are inserted by the parent multiprocessor target. A programmer can provide strings to the first two code streams by using the following protected CGCStar methods.
int addDeclaration(const char* decl, const char* name = NULL);The first method uses
int addMainInit(const char* decl, const char* name = NULL);
declstring as the name of the string if
nameis given NULL.
CodeStream wormIn;The first two streams contain code sections to support wormhole interface to the host machine. They will be placed at the beginning of the main loop and at the end of the main loop. The last code stream will be placed after the main loop in the main function.
Recall that using
addCodemethod defined in CGStar class, we can put code strings to any code stream .
These nine code streams are initialized by the following protected method of CGCTarget class.:
virtual void initCodeStrings();Note that code streams are not initialized in
setupmethod of the target since the parent target may put some code before calling the
setupmethod of the target. We initialize code streams after we stitch them together and copy the final code in
frameCodemethod. We do not initialize
myCodestream in the above method.
void frameCode();This method put all code streams together and copy the resulting code to