 Using the code generator

The code generation window is automatically opened by the "Verify" and "Make" commands of the other ISaGRAF Workbench windows. The code generation window is not automatically closed when the requested code generation operation ends, so that the user still has access to all the code generation commands and options from the window menu.

Main commands

Compiler options

Producing C source code

Viewing information

Defining resources


Main commands

The "Files" menu contains the commands for program syntax checking and code generation.

Make application code

Program syntax checking

Simulating a modification

Double-clicking on the error message will open the program and locate the cursor on the error.


Make application code

The "Make" command constructs the entire code of the project. Before generating anything, this command checks the syntax of the declarations and programs. Any error that cannot be detected during single program compiling is detected during code generation. This applies to tables of conversion, I/O variable connections and links with the libraries. The code generation halts the compiling of a program when errors are detected. This program must be corrected before continuing the code generation. Programs which have already been checked (with no error detected) and that have not been modified since their last "Verify" operation are not re-compiled. Variable declaration verification and application coherence checking are always processed. During program checking, the "Make" operation can be aborted by hitting the ESCAPE key.

Note:	If the declaration of a local variable of a program has been modified, this program is verified. If a global variable has been modified, all the programs are verified.


Program syntax checking

The "Verify program" command allows the user to verify only one program. The selected program is compiled even if it has not been modified since its last verification. The "Verify dictionary" command allows the user to verify the declarations of all the variables of the project.

The "Verify all programs" checks the syntax of all the programs of the project, even if some of them have not been modified. This command does not stop when an error is detected in a program. It can be used to produce a complete listing of all the errors remaining in programs of the project. This command may be aborted by hitting the ESCAPE key.


Simulating a modification

The "Touch" command simulates a modification of all the project's programs, so that they are all verified during the next "Make" operation. The "Open" command is used to open the last verified program. This command is very useful to directly access a program where syntax errors have been detected.


Compiler options

 The "Compiler options" command is used to setup main parameters used by the ISaGRAF Code Generator to build and optimize the target code. The aim of this command is to select the type of code which has to be generated, according to corresponding ISaGRAF targets, and to setup the optimizer parameters according to the expected compiling time and application run-time requirements.

Selecting targets

SFC processing

Optimizer options

The "Upload" button opens a second dialog box with other options that enable the embedding of zipped source code to downloaded code, in order to enable the "Upload" feature. Refer to "Upload" documentation for further explanations.


Selecting targets

The upper list shows the list of available target codes which can be produced. The ">>" sign is used to indicate the selected target(s). The ISaGRAF Code Generator can produce up to 3 different codes in the same compiling operation. Use the "Select" and "Unselect" buttons to set the list of required target codes, according to your target hardware. Below are the standard ISaGRAF targets:

SIMULATE:	This code is dedicated to the ISaGRAF Simulator on the Workbench. The simulator cannot be run if this target is not selected to produce the application code.

ISA86M:	This is a TIC code (Target Independent Code) dedicated to ISaGRAF kernels installed on Intel based processors. The processor type only concerns byte ordering in the generated code.

ISA68M:	This is a TIC code (Target Independent Code) dedicated to ISaGRAF kernels installed on Motorola based processors. The processor type only concerns byte ordering in the generated code.

SCC:	Selecting this target leads ISaGRAF compiler to produce structured "C" language source code to be compiled and linked with ISaGRAF target kernel libraries to produce an embedded executable code.

CC86M:	Selecting this target leads ISaGRAF compiler to produce non structured "C" language source code to be compiled and linked with ISaGRAF target kernel libraries to produce an embedded executable code. This selection is provided for compatibility with ISaGRAF versions before V3.23, when structured "C" code generation and integration were not supported.

Refer to your hardware manual to know the type of ISaGRAF target kernel installed on your PLC.  Other target types (machine code, C source code...) may be supported in future releases of the ISaGRAF Workbench.


SFC processing

Check the "Use embedded SFC engine" box to enable the use of the ISaGRAF SFC engine. This mode should be preferred as it leads to higher run time performances. However, the target engine may be missing on some particular implementations of the ISaGRAF target, of more commonly on customized targets based on ISaGRAF code post-processing. In this case you may have to remove this option and let ISaGRAF compiler translate SFC charts into low level instructions. Refer to your hardware documentation for more information about the use of this option.


Optimizer options

Below are the parameters, used by the ISaGRAF Code Generator to optimize the target code, that can be set from the "Compiler options" dialog box. The "Default" button is used to remove all optimizing options, in order to reduce the compiling time.

When the "Run two optimizer passes" option is set, the ISaGRAF Code Optimizer is run twice. Optimizations made during the second pass are generally less significant than the ones made in the first pass.

When the "Evaluate constant expressions" option is set, constant expressions are evaluated by the compiler. For example, the numerical expression "2 + 3" is replaced by "5" in the target code. When this option is not set, constant expressions are calculated at run-time.

When the "Suppress unused labels" option is set, the Optimizer simplifies the system of jumps and labels of the programs, in order to suppress unused target labels or null jumps.

When the "Optimize variable copying" option is set, the use of temporary variables (used to store intermediate results) is optimized. This option is commonly used with the "Optimize expressions" option. When this option is set, the Optimizer re-uses the result of expressions and sub-expressions which are used more than once in the program.

When the "Suppress unused code" option is set, the Optimizer suppresses the code which is not significant. For example, if the following statements are programmed: "var := 1; var := X;", the corresponding generated code is only: "var := X;".

When the "Optimize arithmetic operations" option is set, the Optimizer simplifies arithmetic operations according to special operands. For example, the expression "A + 0" will be replaced by the "A". When the "Optimize boolean operations" option is set, the Optimizer simplifies boolean operations according to special operands. For example, the boolean expression "A & A" will be replaced by "A".

When the "Build binary decision diagrams" option is set, the Optimizer replaces the boolean equations (mixing AND, OR , XOR and NOT operators), by a reduced list of conditional jump operations. The translation is operated only if the expected execution time of the jump sequence is less than the one expected for the original expression.

The following table summarizes the expected optimization and requested compiling time corresponding to each parameter:

gain (performances)	compiling time

Run 2 passes	xxxx	(*)

Optimize constant expressions	xxxxxxxxxx	xxxx

Suppress unused labels	xxxx	xxxxxxxxxx

Optimize variable copying	xxxx	xxxxxxxxxx

Optimize expressions	xxxx	xxxxxxxxxx

Suppress unused code	xxxx	xxxxxxxxxx

Optimize arithmetic operations	xxxxxxxxxx	xxxx

Optimize boolean operations	xxxxxxxxxx	xxxx

Build binary decision diagrams	xxxxxxxxxxxxxxx	xxxxxxxxxxxxxxx

(*) the compiling time is also multiplied by 2.


Producing C source code

The ISaGRAF workbench enables the production of source code in "C" language. In this case, the whole contents of the application, including SFC chart description, data base definition and sequences of code are generated in "C" source code format. There are two possibilities, proposed as two styles of generated code:

CC86M (C source code - V3.04)	produces non structured "C" source code. This style should be selected if your target software is based on ISaGRAF release previous to 3.23.

SCC (structured C source code)	produces a structured "C" source code. This style should be preferred if your target software is based on ISaGRAF release 3.23 or later.

The following two files are created in the project directory:

APPLI.C	common source code of the application

APPLI.H	common "C" language definitions

In the case structured "C" source code generation, a ".C" source file and a ".H" definition file are created for each program of the application, in addition to common "APPLI.C" and "APPLI.H" files.

These files must be compiled and linked to the ISaGRAF target libraries in order to produce the final executable code. Refer to the "ISaGRAF I/O development toolkit User's Guide" for further information about recommended implementation techniques.

Note:	Some debugging features such as application downloading, on line modification and breakpoints are no more available when the ISaGRAF application is "C" compiled.


Viewing information

The "Edit" menu contains the commands for viewing the different text files built during code generation or syntax checking operations on the code generator window. The code generation window is a text area that contains messages during code generation or syntax checking operations. All information is stored on the disk so it can be examined using the "Edit" menu commands.

Editing commands

The "Clear Screen" command is used to clear the window text area. The window is automatically cleared before each code generation or syntax checking operation. The "Copy" command is used to copy the displayed text in the clipboard of Windows, so it can be used by other applications such as ISaGRAF text editors.

Viewing compiler output messages

The "Execution messages" command shows all the messages displayed during the last "Make" or "Verify" operation on the window text area. This applies to all the error messages.

Other choices of the "Edit" menu allow the user to monitor auxiliary text files created during syntax verification and code generation. These files are not usually used for a common ISaGRAF project.


Defining resources

The "Resources" command of the "Options" menu allows the user to define resources. A resource is any user defined data (network configuration, hardware setting...) of any format (file, list of values) which has to be merged with the generated code, in order to be downloaded with it in the target PLC. Such data is not directly operated by the ISaGRAF kernel, and is commonly dedicated to other software installed on the target PLC. Refer to your hardware manual for further information about available resources.

The resource definition file

Language reference

Example

Resource compiling

Implementation


The resource definition file

The resources are defined in a "Resource definition file" stored with other files of the ISaGRAF project. This is a pure ASCII text file, processed by the ISaGRAF Resource Compiler. This compiler is automatically run when the application code is built. This section explains the syntax of this file. The resource definition file uses lexical rules of the ST language. Comments, beginning with "(*" and ending with "*)" characters can be inserted anywhere in the text. Strings are delimited by single apostrophes. Refer to the second part of this manual for more explanations about the lexical formats used to enter numerical values.


Language reference

Below is the list of keywords and statements used in a resource definition file.

ULONGDATA

VARLIST

BINARYFILE

TEXTFILE

TARGET

ANYTARGET

FROM

TO


ULONGDATA

Meaning:	Specifies a resource which is a list of integer values. Values are stored in target code as unsigned 32 bit integers. Values are stored in the order specified in the resource definition file. Values must be separated by comas. The name of the resource cannot exceed 15 characters.

Syntax:	ULONGDATA '<resource_name>'

BEGIN

...target_selection...

...list of values...

END

Example:	ULongData 'MYDATA'

Begin

...

0, -1, 100_000,	(* decimal *)

16#A0B1, 2#1011_0101	(* hexadecimal, binary *)

End


VARLIST

Meaning:	Specifies a resource which is a list of variable addresses. Variables are identified by their name in the resource definition file. Variable addresses are stored in target code as unsigned 16 bit integers. Addresses are stored in the order specified in the resource definition file. Variables must be separated by comas. The name of the resource cannot exceed 15 characters.

Syntax:	VARLIST '<resource_name>'

BEGIN

...target_selection...

...list of variable names...

END

Example:	VarList 'LIST'

Begin

...

Var100, MyParameter, Command, Alarm

End


BINARYFILE

Meaning:	Specifies a Binary File resource. The source data is stored  in an MS-DOS file. The target resource definition is completed with a target pathname. End of line characters are not converted by the ISaGRAF Resource Compiler. The name of the resource cannot exceed 15 characters.

Syntax:	BINARYFILE '<resource_name>'

BEGIN

...target selection...

FROM '<source_pathname>'

TO '<destination_pathname>'

END

Example:	BinaryFile 'MYFILE'

Begin

...

From 'c:\user\config.bin'

To '/dd/user/appl/config.dat'

End


TEXTFILE

Meaning:	Specifies a Text File resource. The source data is stored in an ASCII file. The target resource definition is completed with a target pathname. End of line characters are converted by the ISaGRAF Resource Compiler according to the target host system conventions. The name of the resource cannot exceed 15 characters.

Syntax:	TEXTFILE '<resource_name>'

BEGIN

...target selection...

FROM '<source_pathname>'

TO '<destination_pathname>'

END

Example:	TextFile 'MYFILE'

Begin

...

From 'c:\user\config.bin'

To '/dd/user/appl/config.dat'

End


TARGET

Meaning:	Specifies the name of a target code that has to include the resource. Refer to the preceding section (compiler options) for further information about handled targets. The "Target" statement can appear more than once in the same resource block, in order to select several targets. This statement cannot be used if the "AnyTarget" statement is specified.

Syntax:	TARGET '<target_name>'

Example:	BinaryFile 'MYFILE'

Begin

Target 'ISA86M'

Target 'ISA68M'

...

End


ANYTARGET

Meaning:	Specifies that the resource must be merged to all the target codes built by the Code Generator. The ISaGRAF Code Generator can produce several target codes during the same "Make" command. This statement cannot be used if one or several "Target" statements are specified.

Syntax:	ANYTARGET

Example:	ULongData 'MYDATA'

Begin

AnyTarget

...

End


FROM

Meaning:	Specifies the source pathname (on the PC where the ISaGRAF Workbench is installed) of a BinaryFile or TextFile resource. The characters used to isolate the components of the pathname (drive, directory, prefix, suffix) must conform to the MS-DOS system conventions.

Syntax:	FROM '<target pathname>'

Example:	BinaryFile 'MYFILE'

Begin

...

From 'c:\user\config.dat'

To '/dd/user/appl/config.dat'

End


TO

Meaning:	Specifies the destination pathname (on the target system) of a BinaryFile or TextFile resource. The characters used to isolate the components of the pathname (drive, directory, prefix, suffix) must conform to the target host system conventions.

Syntax:	TO '<target pathname>'

Example:	TextFile 'MYFILE'

Begin

...

From 'c:\user\config.dat'

To '/dd/user/appl/config.dat'

End


Example

Below is a complete example of a resource definition file:

(* resource definition file *)

ULongData 'DATA1'	(* list of values *)

Begin

   Target 'ISA86M'	(* for this target only *)

   1, 0, 16#1A2B3C4D, +1, -1	(* numerical values *)

End

VarList 'VLIST1'	(* list of variables *)

Begin

   Target 'ISA86M'	(* for this target only *)

   Valve1, StateX, Command, Alrm1	(* variable names *)

End

BinaryFile 'FILE1'	(* binary file resource *)

Begin

   AnyTarget	(* dedicated to all targets *)

   From 'c:\user\updatef.bin'	(* source file on PC *)

   To 'updatef.cfg'	(* target file on PLC *)

End

TextFile 'FILE2'	(* text file resource *)

Begin

   Target 'ISA68M'

   From 'c:\nw\nwbd.txt'	(* source file on PC *)

   To '/nw/dat/nwbd'	(* target file on PLC *)

End


Resource compiling

If resources have been entered in resource definition file, a dialog box appears at the end of ISaGRAF code generation. Press the "Start compile" button to run resource compiler. Output messages and errors will be displayed in the main control. Press "Exit" to avoid resource compiling. In this case, resources will not be added to the ISaGRAF code.


Implementation

The number of resources, the size of data rows and files are not limited by ISaGRAF. Resources are stored at the end of the generated code, with a resource directory. Below is the format (using C notations) of the resource directory format:

__RESOURCE:

{

  long nbres;	/* number of defined resources */

  {

    char name[16];	/* resource name */

    long type;	/* resource data type */

    long size;	/* exact size of data block */

    uint32 data;

    uint32 path_offset;	/* points to a string */

  } /*nb of records */

}

Below are the possible values of the "type" field:

1 = binary file

2 = text file

3 = ulong data (path_offset field is not used in this case)

4 = variable list (path_offset field is not used in this case)

For text files, end of line characters are translated by the resource compiler, according to the target system conventions. All pointers are 32 bit offsets from the address of the corresponding structure. All resource names and pathnames are NULL terminated strings. Pathnames and data follow the resource directory.