Full Library / Defining_Flow / Basic Processing / If_Else
Block Name: If_Else

Code File Location: VisualSim/actor/lib/DS_If_Else_K

Description

This is a programming if-else operation. If the condition in the "If_Statement" equates to a true or 1, then the lines numbers listed in the "if_Execute" are executed. If the condition in the "If_Statement" equates to a false or 0, then the lines numbers listed in the "else_Execute" are executed. The Field_Statements of this block follow the format of the Data Structure Expression Language. The modified incoming Data Structure is sent on the true port if the "IF_Statement" is true/1 and is sent on the false port if the statement is false/0. This block performs an functional if-else operations on data structure fields and memories. 

The format for the If Statement is: (name1 operator name2 || name3 operator name4). 

The middle expression can be AND (&&) or an OR (||). If the statement is true, i.e., an 'if', then the line numbers on the 'if_execute' line are executed in sequence. If the statement is false, i.e., an 'else', then the line numbers on the 'else_execute' line are executed in sequence. The list of line numbers in the 'if_execute' and 'else_execute' need not be unique and are a comma-separated list. In addition, if the statement is true, then the incoming Data Structure is sent on the 'output_true' port and if the statement is false, then the incoming data structure is sent on the 'output_false' port. Type conversions prior to comparison is not performed. The if_statement is not a string parameter. Hence it needs double quotes. If the statement must exceed the standard "x op y &&/|| z op a", then the operations of x, y, z and a must be processed in the previous block or in a parameter.

The If_Else_Statement block can perform many operations on a single data structure field, plus multiple operations on a single data structure, using progressive field updates. 

User Model

This block is used to route the Data Structure based on a decision. Examples of a decision can be to check if the CRC and the Data are equal for error checking and then send it to a Ack or Nack transmission, or if the priority of the incoming Data Structure has a higher priority than a threshold then send it to a different processor. 

Expression Language Syntax: X Op Y, or X = Y Op Z

Where X can be a Memory or Field, OP os the Operator (See below), Y can be Memory, Field, Time, Parameter or Value and Z can be Memory, Parameter, Field, Time or Value.

TYPES

int, long, double, string, binary, boolean and data structure.

OPERATORS

For the format of X Op Y, Operators are: =, +=, -=, *=, /=, 1/=, %=, !, ^, sqrt, ~, &, |, xor.

For the format of Y Op Z, Operators are: +, -, *, /, 1/, %, &, |, xor.

Additional operators include binary functions for Y Op Z: & (AND), | (OR), ~ (NOT), ! and 'xor' (Exclusive OR).  

Additional operators include binary functions for Y Op Z: '&=', '|=', '~=', 'xor='.

Other operators are for Y Op Z: <<', '<<=', '>>', '>>='.

Random: irand(lower, upper), rand(lower, upper), exp(mean), norm(mean, stdev).

This block can also be used to define a memory as: MyMemL local 0, MyMemG global 1.0.

TIME

DSNow, TNow, TLast, TDelta, TReal, TRealLast and TRealDelta.

NOTE

Binary and shift operators can be applied only on int, binary and binary strings.

The Use Model for the Data Structure Blocks is to modify user-defined data structures or memories to implement an architectural abstraction, or cycle accurate model. Data Structure Blocks provide for communication between model flows via memory elements (DS Blocks or Memory BLocks) and with composite Data Structures to quickly and efficiently implement a modeling abstraction. One can think of Data Structure Blocks as operating on Data Structures, similar to individual EXCEL spreadsheets with flow oriented operators (DS Blocks).

Refer Statement_if_else Demo Model.



Parameter Explanation TypeExample
If_Statement The format for the If Statement is: name1 operator name2 || name3 operator name4. Names can be a data structure field, memory or value (int, double); the operator  can be ==, !=, <, >, <=, >=. In addition, a single '||' or '&&' can be used to create a compound statement.    String"Name_X == Name_Y"
If_Execute If Execute identifies the Field_Statement_n's to be executed, assuming the 'if' statement is true. String"1, 2"
Else_ExecuteElse Execute identifies the Field_Statement_n's to be executed, assuming the 'if' statement is false.String"3, 4"
Field_Statement_1 The field description 1 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here. The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. StringName_X Assign Name_Y OP Name_Z
Field_Statement_2 The field description 2 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here.  The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. StringName_X Assign Name_Y OP Name_Z
Field_Statement_3 The field description 3 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here.  The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value. StringName_X Assign Name_Y OP Name_Z
Field_Statement_4The field description 4 (op_x, assign, op_y, op, op_z) is a string that utilizes the DS Expression language. op_x represents the result of the asssignment (assign) operator, typically '='. The expression formats, operators, types and Time values listed in the summary section can be used here.  The assignment operator can also be '+=', '-=', '*=', '/=', etc. similar to C/C++. The assign can also be 'local' or 'global' for declaring memories. op_x can be a memory (local, global), composite data structure field, or combination 'memory:field'. op_x cannot be a constant or numerical value, like C/C++. op_y, op_z can be a memory, composite data structure field, 'memory.field', constant, or numerical value.StringName_X Assign Name_Y OP Name_Z
Random_SeedRandom Number Seed.String123457L


Port Explanation Type
Input It is used to accept the incoming Data Structure. General
output_true
It is used to sent the modified Data Structure out if the expression evaluates to 'true'.  General
output_falseIt is used to sent the modified Data Structure out if the expression evaluates to 'true'. General