Main Content

createAndAddImplementationArg

Create implementation argument from specified properties and add to implementation arguments for code replacement table entry

Description

example

arg = createAndAddImplementationArg(hEntry,argType,varargin) creates an implementation argument from specified properties and adds the argument to the implementation arguments for a code replacement table entry.

Implementation arguments must describe fundamental numeric data types, such as double, single, int32, int16, int8, uint32, uint16, uint8, boolean, or 'logical' (not fixed-point data types).

Examples

collapse all

This example shows how to use thecreateAndAddImplementationArg function with the createAndSetCImplementationReturn function to specify the output and input arguments for an operator implementation.

op_entry = RTW.TflCOperationEntry;
% .
% .
% .
createAndSetCImplementationReturn(op_entry, 'RTW.TflArgNumeric', ...
    'Name',       'y1', ...
    'IOType',     'RTW_IO_OUTPUT', ...
    'IsSigned',   true, ...
    'WordLength', 32, ...
    'FractionLength', 0);
                                  
createAndAddImplementationArg(op_entry, 'RTW.TflArgNumeric',...
    'Name',       'u1', ...
    'IOType',     'RTW_IO_INPUT',...
    'IsSigned',   true,...
    'WordLength', 32, ...
    'FractionLength', 0 );
                               
createAndAddImplementationArg(op_entry, 'RTW.TflArgNumeric',...
    'Name',       'u2', ...
    'IOType',     'RTW_IO_INPUT',...
    'IsSigned',   true,...
    'WordLength', 32, ...
    'FractionLength', 0 );

These examples show some common type specifications using createAndAddImplementationArg.

hEntry = RTW.TflCOperationEntry;
% .
% .
% .
% uint8:
createAndAddImplementationArg(hEntry, 'RTW.TflArgNumeric', ...
    'Name',           'u1', ... 
    'IOType',         'RTW_IO_INPUT', ...
    'IsSigned',       false, ...
    'WordLength',     8, ...
    'FractionLength', 0 );

% single:
createAndAddImplementationArg(hEntry, 'RTW.TflArgNumeric', ...
    'Name',         'u1', ... 
    'IOType',       'RTW_IO_INPUT', ...
    'DataTypeMode', 'single' );

% double:
createAndAddImplementationArg(hEntry, 'RTW.TflArgNumeric', ...
    'Name',         'u1', ... 
    'IOType',       'RTW_IO_INPUT', ...
    'DataTypeMode', 'double' );

% boolean:
createAndAddImplementationArg(hEntry, 'RTW.TflArgNumeric', ...
    'Name',         'u1', ... 
    'IOType',       'RTW_IO_INPUT', ...
    'DataTypeMode', 'boolean' );

This example shows how to add an input argument that is a numeric constant to the implementation function. The actual value of the constant is set during code generation.

hEntry = RTW.TflCOperationEntry;
% .
% .
% .
createAndAddImplementationArg(hEntry, 'RTW.TflArgNumericConstant', ... 
    'Name',       'fl_in1', ...
    'IOType',     'RTW_IO_INPUT', ...
    'IsSigned',   false, ...
    'WordLength', 32, ...
    'FractionLength', 0, ...
    'Value',       0);

This example shows how to create an input argument that is a two-dimensional matrix of size 2-by-1 or larger.

hEntry = RTW.TflCOperationEntry;
% .
% .
% .
createAndAddImplementationArg(hEntry, 'RTW.TflArgMatrix', ... 
    'Name',       'mat_in1', ...
    'IOType',     'RTW_IO_INPUT', ...
    'DimRange',   [2 1; Inf Inf]);

Input Arguments

collapse all

The hEntry is a handle to a code replacement table entry previously returned by instantiating a code replacement entry class, such as hEntry = RTW.TflCFunctionEntry or hEntry = RTW.TflCOperationEntry.

Example: op_entry

Argument type to create, specified as a character vector or string scalar. Specify one of these types of arguments.

  • 'RTW.TflArgNumeric' — numeric argument

  • 'RTW.TflArgNumericConstant' — numeric constant argument

  • 'RTW.TflArgMatrix' — matrix argument

  • 'RTW.TflArgComplex' — complex argument

  • 'RTW.TflArgChar' — character argument

  • 'RTW.TflArgVoid' — void argument

Example: 'Name','u1'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Name','u1'

Example: 'Name','u1'

Use 'RTW_IO_INPUT' for input.

Example: 'IOType','RTW_IO_INPUT'

Boolean value that, when set to true, indicates that the argument is signed.

Example: 'IsSigned',true

Example: 'WordLength',16

You can specify either DataType (with Scaling) or DataTypeMode, but do not specify both.

Example: 'DataTypeMode','Fixed-point: binary point scaling'

Example: 'DataType','Fixed'

Use 'BinaryPoint' for binary-point scaling or 'SlopeBias' for slope and bias scaling.

Example: 'Scaling','BinaryPoint'

You can optionally specify either this parameter or a combination of the SlopeAdjustmentFactor and FixedExponent parameters, but do not specify both.

Example: 'Slope',1.0

You can optionally specify either the Slope parameter or a combination of this parameter and the FixedExponent parameter, but do not specify both.

Example: 'SlopeAdjustmentFactor',1.0

You can optionally specify either the Slope parameter or a combination of this parameter and the SlopeAdjustmentFactor parameter, but do not specify both.

Example: 'FixedExponent',0

Example: 'Bias',0.0

Example: 'FractionLength',0

Use this parameter only to set the value of injected constant input arguments, such as arguments that pass fraction-length values or flag values, in an implementation function signature. Do not use it for standard generated input arguments, such as u1u2. You can supply a constant input argument that uses this parameter anywhere in the implementation function signature, except as the return argument.

You can inject constant input arguments into the implementation signature for code replacement table entries. If the argument values or the number of arguments required depends on compile-time information, you can use custom matching. For more information, see Customize Match and Replacement Process.

Example: 'Value',0

Output Arguments

collapse all

Specifying the return argument in the createAndAddImplementationArg function call is optional.

Version History

Introduced in R2007b