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

ID 784383
Date 7/08/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

8.1.3. Control Flow Commands

The CLI scripting supports common flow control commands such as:

  • if
  • else
  • while
  • foreach

The following captures show examples of the use if command:

#Intel Simics simulator CLI 

#Simple if condition
simics> $val = 10
simics> if $val > 5 {echo "Larger than 5!"}

Larger than 5!
# if/else used as part of a command
simics> $numCores = 4

simics> echo (if $numCores > 1 { "multi-"} else {"single-"}) + "core"

multi-core
simics> $numCores = 1
simics> echo (if $numCores > 1 { "multi-"} else {"single-"}) + "core"

single-core
simics> $b = 0

# if/else if/else used
simics> if $b == 1 {

....... echo "one"

....... } else if $b == 0 {

....... echo "zero"

....... } else {

....... echo "other"

....... }

zero
Note: Multi-line if-else statements must have } else { on the same line.

The following capture shows an example of a while loop:

#Intel Simics simulator CLI  

# while loop example
simics> $loop = 3
simics> while $loop {
....... echo "Val:" + $loop

....... $loop -= 1
....... }

Val:3
0x2
Val:2
0x1
Val:1
0x0
Note: When using loop in scripts to automate a process or for device modeling, you must be cautious to prevent falling into an infinite loop condition as it leads to simulation hangs blocking the Intel® Simics® CLI to accept any command.

The following capture shows some examples of a foreach loop. The first one uses the range command to define elements to iterate. This command returns a list of integers that goes from 0 to 2.

The second example uses an actual list of objects that includes the CPUs that belong to the arm-cortex-a55 class which is retrieved with the list-objects command.

The third example creates the list explicitly using [ ] keys.

#Intel Simics simulator CLI  

#1st example. 
simics>  foreach $loop in (range 3) {

....... echo $loop

....... }

0x0
0x1
0x2
#2nd example. 
simics> foreach $cpu in (list-objects -all arm-cortex-a55){
....... echo "Cycles on " + ($cpu->name) + ": " + ($cpu.print-time -c)
....... }

Cycles on system...agilex_hps.core[0]: 1475824027943
Cycles on system...agilex_hps.core[1]: 1475824027400
Cycles on system...agilex_hps.core[2]: 1475824027400
Cycles on system...agilex_hps.core[3]: 1475824027400
#3rd example
simics> foreach $loop in [1, 2, 3] {
....... echo $loop
....... }

0x1
0x2