Top Up Prev Next Bottom Contents Index Search

18.6 Other CGCTarget members

CGCTarget is derived from HLLTarget class which is the base target class for high level language code generation. It has a constructor with three argument like its base target classes. In the constructor, we initialize code streams and put them into the codeStringLists by addStream method. It has makeNew method defined.

18.6.1 Other CGCTarget protected members

CGCTarget class has many states guiding the compilation procedure.

IntState doCompile; 
If this state is set NO, we only generate code, not compiling the code.

StringState hostMachine; 
StringState funcName;
StringState compileCommand;
StringState compileOptions;
StringState linkOptions;
The 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);
void wormOutputCode(PortHole& p);
The above methods just print out comments. We haven't supported wormhole interface for CGC domain yet (Sorry!).

18.6.2 Other CGCTarget public members

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); 
void endIteration(int repetitions, int depth);
The first method generates the starting line of 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);
const char* hostName();
The above methods set and get the 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(); 
int useStaticBuffering();
These methods set and get the 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); 
CodeStream* removeStream(const char* n);
The above methods put and remove a code stream named n.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.