Top Up Prev Next Bottom Contents Index Search

14.2 Code Generation Methods

The addCode method is context sensitive so that it will `do the right thing' when invoked from within the initCode, go, and wrapup methods of CGCStar. Refer to "Writing Code Generation Stars" on page 13-2 for documentation on addCode, including context sensitive actions and conditional code generation. There are several additional code-generation methods defined in the CGC domain. The addInclude method is used to generate #include file directives. The addDeclaration method is used to declare local variables within the main function. The addGlobal method is used to declare global variables outside the main function. As with addCode, these methods return TRUE if code was generated for the appropriate stream and FALSE otherwise. These methods are member functions of the CGCStar class.

int addInclude (const char* file)
Generate the directive #include file in the include stream. The string file must include quotation marks ("file") or angle brackets (<file>) around the name of the file to be included. Only one #include file directive will be generated for the file, even if addInclude is invoked multiple times with the same argument. Return TRUE if a new directive was generated.
int addDeclaration (const char* text, const char* name = NULL) Add text to the mainDecls stream. Use name as the identifying key for the code fragment if it is provided, otherwise use text itself as the key. Code will be added to the stream only the first time that a particular key is used.
int addGlobal (const char* text, const char* name = NULL)
Add text to the globalDecls stream. Use name as the identifying key for the code fragment if it is provided, otherwise use text itself as the key. Code will be added to the stream only the first time that a particular key is used.
int addCompileOption (const char* text)
Add options to be used when compiling a C program. The options are collected in the compileOptionsStream stream.
int addLinkOption (const char* text)
Add options to be used when linking a C program. The options are collected in the linkOptionsStream stream.
The following streams, which are used by the code generation methods just described, are defined as members of the CGCTarget class in addition to the streams defined by the CGTarget class.

CodeStream include
Include directives are added to this stream by the addInclude method of CGCStar.
CodeStream mainDecls
Local declarations for variables are added to this stream by the addDeclaration method of CGCStar.
CodeStream globalDecls
Global declarations for variables and functions are added to this stream by the addGlobal method of CGCStar.
CodeStream mainInit
Initialization code is added to this stream when the addCode method is invoked from within the initCode method.
CodeStream mainClose
Code generated when the addCode method is invoked from within the wrapup method of stars is placed in this stream.
CodeStream compileOptionsStream
Options to be passed to the C compiler which have been added using the CGCStar::addCompileOption method.
CodeStream linkOptionsStream
Options to be passed to the linker which have been added using the CGCStar::addLinkOption method.


Top Up Prev Next Bottom Contents Index Search

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