Both sides previous revisionPrevious revisionNext revision | Previous revision |
language:langs:chp [2023/04/07 12:20] – [Syntactic replication] rajit | language:langs:chp [2025/05/01 17:04] (current) – [Debugging during simulation] rajit |
---|
| |
In the published literature, non-deterministic selections are usually written using a thin bar ''|'' rather than the thick bar ''[]''. However, this can create some ambiguities in parsing. For example, consider the statement ''[ a -> y:=b | c | d -> skip ]''. This can be parsed in a number of ways, and it is not clear which one was the intended option. | In the published literature, non-deterministic selections are usually written using a thin bar ''|'' rather than the thick bar ''[]''. However, this can create some ambiguities in parsing. For example, consider the statement ''[ a -> y:=b | c | d -> skip ]''. This can be parsed in a number of ways, and it is not clear which one was the intended option. |
| |
| ===== Arrays: dynamic v/s non-dynamic indices ===== |
| |
| Suppose an array ''x'' has been declared as: |
| <code act> |
| int x[10]; |
| </code> |
| |
| Now when ''x'' is accessed in CHP, it could be accessed with an array index that is a run-time constant, or an index that is computed at run-time. For example, the CHP program |
| <code act> |
| chp { |
| ... |
| x[0] := x[0] + 1; |
| ... |
| } |
| </code> |
| uses ''x'' with a constant index. As opposed to this, the program |
| <code act> |
| chp { |
| ... |
| x[i] := x[i] + 1; |
| ... |
| } |
| </code> |
| uses ''x'' with an index that is computed using the run-time value of ''i''. This second category of arrays are referred to as //dynamic arrays//---not because the array size is dynamic, but because the element of the array accessed depends on a value that is computed by the circuit. Such dynamic arrays have to be translated into memory structures, or other circuits where the element being accessed has to be specified at run-time. Arrays with constant references can be directly mapped to circuit implementations of asynchronous registers, since the element to be accessed can be determined statically. |
| |
| |
===== Loops ===== | ===== Loops ===== |
| |
===== Advanced expression syntax ===== | ===== Advanced expression syntax ===== |
| |
| ==== Bitslice assignment ==== |
| |
| For integer-valued variables, one can assign to some of the bits. The syntax for this is: |
| |
| <code act> |
| int<8> x; |
| ... |
| chp { |
| ... |
| x{4..2} := 4; |
| ... |
| } |
| </code> |
| This will update three bits of ''x'' based on the bit-pattern of the right hand side (in this case ''100''). |
| |
| |
| |
==== Channels in expressions ==== | ==== Channels in expressions ==== |
</code> | </code> |
where ''N'' is the number of channels in the ''I'' array. This approach ensures that index for the array ''I[]'' is always a constant. | where ''N'' is the number of channels in the ''I'' array. This approach ensures that index for the array ''I[]'' is always a constant. |
| |
| ===== Debugging and other support functions for simulation ===== |
| |
| When running CHP simulations, it is often helpful to print debugging output during CHP development. To support this, the CHP language includes the ''log()'' command. |
| |
| <code act> |
| ... |
| chp { |
| ... |
| log ("Hello!"); |
| ... |
| } |
| </code> |
| The statement above will display ''Hello!'' on the [[tools:actsim|''actsim'']] output. The ''log'' statement can include variables and expressions as well: |
| |
| <code act> |
| int x; |
| ... |
| chp { |
| ... |
| log ("Hello, got: ", x+3, " and that's that."); |
| log ("%x This is hex: ", x+3); |
| log ("%b This is binary", x+3); |
| ... |
| } |
| </code> |
| |
| Booleans are displayed as integers, with ''0'' corresponding to false, ''1'' corresponding to true. Integers can also be displayed in hexadecimal, binary, or decimal (the default). The integer display mode can be changed with a prefix in a string, as shown in the example above. |
| |
| Other support functions of this type are: |
| * ''warn(string)'' : displays a warning |
| * ''assert(expr,string)'' : the first argument has to be an expression, and if it is non-zero then an assertion failed message is displayed. |
| * In the standard ''log'', a single line is displayed based on the items in the argument list. To split this into multiple ''log'' commands, use: |
| * ''log_st()'' : start a log message |
| * ''log_p(item,item,item...)'' : append to the output message, with the same syntax as the ''log()'' command. |
| * ''log_nl()'' : new line |
| |
| |
| |
====== The chp-txt sublanguage ====== | ====== The chp-txt sublanguage ====== |