addStreammethod. It has
IntState doCompile;If this state is set NO, we only generate code, not compiling the code.
hostMachinestate indicates where the generated code is compiled and run. If this state does not indicate the current host,, we will use remove shell command for compilation and execution. The
funcNamestate is by default set "main". For multiprocessor code generation case, we may want to give different function name for the generated code. The next three states determines the compilation command:
There are some other states defined in this class.
IntState staticBuffering;If this state is set YES, we increase the
wasteFactorof geodesics to use static buffering as much as possible, which is default.
StringState saveFileName;We save the generated code in this file if the file name is given.
StringArrayState resources;This state displays which resources this target has. By default, the CGCTarget has the standard I/O (
STDIO)resource. If a derived target does not support the standard I/O, it should clear this state.
int codeGenInit();This method generates initialization code: buffer initialization, and
initCodemethod of all stars. Before generating initialization code, we switch the
myCodepointer of stars to the
mainInitcode stream so that
addCodemethod called inside the
initCodemethod puts the string into the
void compileRun(SDFScheduler* s);Before calling
compileRunmethod of the SDFScheduler, which will call
runmethod of stars in the scheduled order, we switch the
myCodepointer of stars back to the
myCodecode stream of the target. After code generation, we switch the pointer of stars to the
mainClosecode stream for wrapup stage.
int wormLoadCode();If the
doCompilestate is set NO, we just return TRUE, doing nothing. Otherwise, we compile and run the generated code. Return FALSE if any error occurs.
StringList sectionComment(const char* s);This method makes a comment statement with the given string in C code.
void wormInputCode(PortHole& p);The above methods just print out comments. We haven't supported wormhole interface for CGC domain yet (Sorry!).
void wormOutputCode(PortHole& p);
void setup();This method initialize
curIdindices for unique symbol generation. It also generate indices for stars and portholes. Then, it calls
CGTarget :: setupfor normal setup procedure.
void wrapup();This method displays the generated code stored in
myCodestream. If the galaxy is not inside a wormhole, it calls
wormLoadCodemethod to compile and run the code.
int compileCode();This method compiles the generated code. The compile command is generated by the following method:
virtual StringList compileLine(const char* fName);The argument for this method is the file name to be compiled. If the
hostMachinedoes not indicate the local-host, we use remote shell.
int runCode();This method runs the code. If the
hostMachineis not the local-host, we use
void headerCode();Is redefined to generate a valid C comment with the target name.
void beginIteration(int repetitions, int depth);The first method generates the starting line of
void endIteration(int repetitions, int depth);
repetitionsis negative) or
forloop (otherwise). After that it appends the
wormIncode stream to the
myCodestream before stars fill the loop body. The
wormIncode stream is already filled. The second method close the loop. Just before closing the loop, it appends the
wormOutcode stream to the
myCodeat the end of the loop body.
void setHostName(const char* s);The above methods set and get the
const char* hostName();
void writeCode(const char* name = NULL);If the argument is NULL, we use the galaxy name as the file name. This method saves the code to the file.
void wantStaticBuffering();These methods set and get the
int incrementalAdd(CGStar* s, int flag = 1);We add the code for the argument star,
s,during code generation step. If
flagis 0, we add the main body of the star (
gomethod only). Otherwise, we initialize the star, allocate memory, and generate initialization code, main body, and wrapup code.
int insertGalaxyCode(Galaxy* g, SDFScheduler* s);We insert the code for the argument galaxy during code generation procedure. We give the unique index for the galaxy and set the indices of stars inside the galaxy. Then, it calls
CGTarget :: insertGalaxyCodeto generate code. After all, we declare the galaxy.
void putStream(const char* n, CodeStream* cs);The above methods put and remove a code stream named
CodeStream* removeStream(const char* n);