myCode
and procedures,
CGCTarget class maintains 9 more code streams (all protected). These code streams will be stitched together to make the final code in frameCode
method. 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 myCode
stream 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 (
CodeStream galStruct;
CodeStream include;
galStruct)
is separated from globalDecls
because 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 globalDecls
and include
by 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);
decl
strings 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
CodeStream mainInit;
CodeStream commInit;
commInit
from mainInit
since 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);
decl
string as the name of the string if name
is 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.
CodeStream wormOut;
CodeStream mainClose;
Recall that using
addCode
method 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
setup
method of the target since the parent target may put some code before calling the setup
method of the target. We initialize code streams after we stitch them together and copy the final code in myCode
stream in frameCode
method. We do not initialize myCode
stream in the above method.
void frameCode();This method put all code streams together and copy the resulting code to
myCode
stream.