Top Up Prev Next Bottom Contents Index Search

18.2 Data structure for galaxy and stars


In the global declaration section of the generated code, we declare data structures for stars. At early design stage of CGC domain, we use struct construct of C language to declare the data structure of the program. This way, we could assign unique memory locations to variables very easily. But, the length of a variable gets large as the hierarchy of the graph grows. Furthermore, we reduce significant amount of compiler optimization possibility. Therefore, we invented a scheme to generate unique symbols for variables (sanitizedFullName of CGCTarget class) without using "struct" construct.

virtual void galDataStruct(Galaxy& galaxy, int level = 0);
virtual void starDataStruct(CGCStar* block, int level = 0);
The above methods are protected methods of CGCTarget class to be called in frameCode method to declare data structures of galaxy and stars. The second argument of both methods indicates the depth of hierarchy which the first argument block resides in, thus advising the amount of indents in the generated code. By default, it is set 0. The first method calls the second method for each component star if it is not a Fork star. We do not generate code nor declare data structure for Fork stars.

The data structure for a star consists of four fields:

1. Comments to indicate that the following declarations corresponds to what star: sectionComment method.

StringList sectionComment(const char* string); 
This is a protected method of CGCTarget class to generate a comment line, string in the generated code.

2. Declare buffers associated with portholes. We do not declare input portholes. If an output porthole is EMBEDDED, we declare a pointer to the embedding buffer, by prepending '*' in front of the buffer name. Otherwise, it declare a regular buffer.

3. Declare index pointers to the buffer if static buffering is not used and the size of buffer is greater than 1 . Portholes will use these index pointers to locate the buffer position. For a regular buffer, we declare an index pointer, named after the buffer name appended by "_ix". The name of index porthole is given by offsetName method of CGCTarget class.

StringList offsetName(const CGCPortHole* p); 
This is a public method to assign an index pointer to the argument porthole. It appends '_' followed by "ix" at the end of the porthole name, by calling the following public method of CGCTarget class:

StringList appendedName(const NamedObj& p, const char* add); 
This method is used to append '_' followed by add to the name of the object p.

4. Finally, we declare referenced states. A State is called referenced only when we use $ref macro for the state at most once. CGCStar class has the following members for referenced states:

StateList referencedStates; 
void registerState(const char* name);
The first is a public member to store the list of referenced states in this Star. The second is a protected method to add the state with given name to the list of referenced states if not inserted.

We traverse the list of referenced states to declare variables. Unlike portholes, the size of a state variable is given. If the size of state is 1, we both declare and initialize the state. If the state is an array state, we both declare and initialize the state using array initialization unless the state is declared inside a function. If we declare an array state inside a function, we have to write explicit initialization code. Class CGCTarget has the following public method to tell whether we are working inside a function or not.

int makingFunc(); 
Returns TRUE if we are defining a function.

18.2.1 Buffer initialization

We initialize buffers and index pointers as follows.

1. If the buffer is EMBEDDED, we assign a pointer to the embedded buffer and set the pointer to the starting address of the embedding buffer, from which the buffer is embedded. If the size of the embedding buffer is 1, we assign the pointer of the embedding buffer.

2. For the regular buffer, we initialize with 0s in case the buffer size is greater than 1.

3. We initialize an index pointer of a buffer to the offset pointer of the porthole associated with that index pointer.



Top Up Prev Next Bottom Contents Index Search

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