Technical data
2 
Working with the Target Language
2-26
appearing in an implementation file (from outside the specified file) only by 
using the 
GENERATE and GENERATE_TYPE special functions.
The 
GENERATE function takes two or more input arguments. The first argument 
must be a valid scope and the second a string containing the name of the 
function to call. The 
GENERATE function passes the first block argument and any 
additional arguments specified to the function being called. The return 
argument is the value (if any) returned from the function being called. Note 
that the Compiler automatically “scopes” or adds the first argument to the list 
of scopes searched as if it appears on a 
%with directive line. See %with in 
“Scoping” beginning on page 2-41. This scope is removed when the function 
returns.
The 
GENERATE_TYPE function takes three or more input arguments. It handles 
the first two arguments identically to the 
GENERATE function call. The third 
argument is the type; the type specified in the Simulink block is ignored. This 
facility is used to handle S-function code generation by the Real-Time 
Workshop. That is, the block type is 
S-function, but the Target Language 
Compiler generates it as the specific S-function specified by 
GENERATE_TYPE. 
For example, 
GENERATE_TYPE(block, "Output", "dp_read")
specifies that S-function block is of type dp_read.
The block argument and any additional arguments are passed to the function 
being called. Similar to the 
GENERATE built-in function, the Compiler 
automatically scopes the first argument before the 
GENERATE_TYPE function is 
entered and then removes the scope on return.
Within the file containing 
%implements, function calls are looked up first 
within the file and then in the global scope. This makes it possible to have 
hidden helper functions used exclusively by the current object.
Note:  It is not an error for the GENERATE and GENERATE_TYPE directives to find 
no matching functions. This is to prevent requiring empty specifications for all 
aspects of block code generation. Use the 
GENERATE_FUNCTION_EXISTS 
directive to determine if the specified function actually exists.










