codeStringLists
by addStream
method. It has makeNew
method defined.
IntState doCompile;If this state is set NO, we only generate code, not compiling the code.
StringState hostMachine;The
StringState funcName;
StringState compileCommand;
StringState compileOptions;
StringState linkOptions;
hostMachine
state 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 funcName
state 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:
compileCommand
compileOptions
fileName linkOptions
There are some other states defined in this class.
IntState staticBuffering;If this state is set YES, we increase the
wasteFactor
of 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
initCode
method of all stars. Before generating initialization code, we switch the myCode
pointer of stars to the mainInit
code stream so that addCode
method called inside the initCode
method puts the string into the mainInit
code stream.
void compileRun(SDFScheduler* s);Before calling
compileRun
method of the SDFScheduler, which will call run
method of stars in the scheduled order, we switch the myCode
pointer of stars back to the myCode
code stream of the target. After code generation, we switch the pointer of stars to the mainClose
code stream for wrapup stage.
int wormLoadCode();If the
doCompile
state 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
galId
, curId
indices for unique symbol generation. It also generate indices for stars and portholes. Then, it calls CGTarget :: setup
for normal setup procedure.
void wrapup();This method displays the generated code stored in
myCode
stream. If the galaxy is not inside a wormhole, it calls wormLoadCode
method 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
hostMachine
does not indicate the local-host, we use remote shell.
int runCode();This method runs the code. If the
hostMachine
is not the local-host, we use rshSystem
function.
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);
while
loop (if repetitions
is negative) or for
loop (otherwise). After that it appends the wormIn
code stream to the myCode
stream before stars fill the loop body. The wormIn
code stream is already filled. The second method close the loop. Just before closing the loop, it appends the wormOut
code stream to the myCode
at the end of the loop body.
void setHostName(const char* s);The above methods set and get the
const char* hostName();
hostName
state.
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 useStaticBuffering();
staticBuffering
state.
int incrementalAdd(CGStar* s, int flag = 1);We add the code for the argument star,
s,
during code generation step. If flag
is 0, we add the main body of the star (go
method 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 :: insertGalaxyCode
to 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);
n.