gclib's program downloader provides a preprocessor for DMC code. The preprocessor modifies the program prior to download providing a number of language features not present in native DMC code.
The preprocessor is invoked in the following two ways.
preprocessor
argument. Downloading code with null for the preprocessor argument uses defaults.preprocessor
argumentGProgramDownload() and GProgramDownloadFile() can be called with a string passed to the preprocessor
argument. The program will be modified based on this string prior to download. See Preprocessor Options below for syntax.
DMC code can be written with special markup to signal the preprocessor to take actions prior to download.
For example, the following program will invoke the in-band preprocessor. The specifics are described below.
REM
CommentLines beginning with the string REM
are removed prior to download. REM
comments are always removed regardless of whether the other preprocessor options are enabled or not.
Most preprocessor statements begin with a double hash, ##
. When proceeded by a space, the double hash acts like a REM
comment.
When proceeded by a character other than space, ##
is interpreted as a preprocessor directive. For example, see ##option
below.
In order to enable the in-band preprocessor, the first two lines of the DMC program must start with a double hash. This syntax of using two lines with double hashmarks is called a quad hash.
Content may follow the hash marks. For example, a good code writing style is to use double hash comments as a comment header showing author, project name, etc.
With the preprocessor enabled, C-style comments may be used with the //
prefix. These comments are very similar to REM
comments. The primary advantage of using this comment over REM
is that //
comments may occur anywhere in a line. This is helpful for line comments such as the following.
Strings containing //
are not interpreted as comments.
//
comments are removed from the program only when the preprocessor is enabled with a quad hash.##option
The option
directive allows passing switches directly to the preprocessor with the same syntax as the preprocessor
argument in GProgramDownload() and GProgramDownloadFile(). The syntax of the option
directive is the following.
For example, the following line will disable compression in the program.
See Preprocessor Options below for other switches.
##include
The include
directive provides a way to include the contents of another DMC file in the current program. This is useful for reusing code such as automatic subroutines, homing operations, or controller initilization routines.
The contents of the file will be inserted in place of the include
line. The insertion occurs prior to code compression.
The syntax of the include
directive is the following.
For example,
To write more portable code, use the include
directive with just the file name, no absolute path. The path to find the file on the system is set depending on usage.
--search
or -I
switch as defined below.--search
or -I
switch in the preprocessor
argument.##gclib
Galil Design Kit uses the ##gclib
directive in GDK Macros. gclib ignores this directive.
In addition to gclib, Galil Design Kit supports the preprocessor. Proper preprocessor usage will be colored in the Editor's syntax highlighter. If the quad hash is not present, preprocessor syntax will be colored differently to indicate improper usage.
The preprocessor is not supported in software prior to GDK/gclib. DMC code downloads using the in-band preprocessor in prior generation software (e.g. GalilTools or SmartTerm) will fail with a TC code of 61, Duplicate or bad label.
--min
, --max
--max
n provides compression up to and including level n. Only the necessary compression will be performed up to level n.--min
n will compress at least up to and including n. n defined as with --max
.REM
.\
) character on a line other than a preprocessor line will result in an error.--insert
--insert
arg invokes the insert option of the firmware's DL command. arg can be one of the following.100
. Program insertion will occur on the line after the line specified.myvar
. Program insertion will occur on the line after the line equal to the value of the variable.#mylabel
. Program insertion will occur on the line after the label.#
symbol. Program insertion will occur on the line after the last line in the program buffer.--max
and --min
are followed.--insert
operation, e.g. DMC-30010. See the DL command for support.--insert
option.--search
, -I
##include
directive will attempt to open its string argument directly. The open will succeed if the argument is the absolute path, or if the argument is in the executable's path, e.g. in the same directory.--search
path allows the user to specify a directory or directories to be searched for the include
file in case the first open fails.-I
is shorthand for --search
.-I
directives.-I
must be specified prior to the include.-I
is to specify only the filename in the DMC source code and use the preprocessor
argument during download to specify the path to the files. This allows the files to be moved without a change to source code.##include
argument is checked first as-is.-I
argument in the preprocessor
argument, in the order specified.##option
directives in the DMC file, in the order specified.--define
, -D
--define
provides a way to substitute one token for another. This is useful for writing code that is generic until program download. Wherever the token is found in code, it is substituted by the replacement. The replacement occurs right before code compression.-D
is shorthand for --define
.-D
switch.In this example, an axis is defined at download time. Specifying the following for the preprocessor argument
would cause the following code
to be downloaded as
This causes the A axis to be addressed.
\pid\
is reserved for exclusive use by GDK.--ifdef
, --ifndef
To specify a preprocessor directive should be executed only if a macro is defined, use --ifdef
.
To specify a preprocessor directive should be executed only if a macro is NOT defined, use --ifndef
.
preprocessor
text box in the Editor settings page to set the desired preprocessor setting for developing in GDK's editor.