Intel® Simics® Simulator for Intel® FPGAs: User Guide

ID 784383
Date 7/08/2024
Public
Document Table of Contents

8.1.8.2. Variables in Script Branches

Variable references in CLI are evaluated when accessed. This is important to remember when writing script branches since some commands are executed when the branch has been suspended, and variables may have been changed. To make sure that CLI variables in script branches are untouched by other scripts, they must be made local.

The following example demonstrates how the use of global variables within a branch may cause an undesired behavior.

#Intel Simics simulator CLI 
script-branch "sample script branch" {
    $foo = 20
    system.board.fpga.soc_inst.hps_subsys.
    agilex_hps.core[0].bp-wait-for-step 10
    echo "foo is " + $foo
}
$foo = 15
run
foo is 15
#Intel Simics simulator CLI 
script-branch "sample script branch" {
    local $foo = 20
    system.board.fpga.soc_inst.hps_subsys.
    agilex_hps.core[0].bp-wait-for-step 10
    echo "foo is " + $foo
}
$foo = 15
run
foo is 20

The example at the left uses $foo variable as global. When the script branch is run, the first line is executed assigning a value of 20 and then the script waits there until 10 instructions get executed. The script continues the execution outside of the script branch where the value of 15 is assigned to $foo variable. The run command is executed which makes the CPU execute the 10 steps that the branch is waiting for. When this occurs, the echo command in the branch prints the last value of $foo which is 15 and not the 20 that you may expect.

This problem is fixed in the example at the right, using the $foo local variable, which now is independent of the global variable used outside of the branch. In this case, the value printed is 20 as expected.