You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A struct is a collection of unrelated types, similar to a `struct` in C/C++ or Verilog. Structs are declared using the `struct` keyword. Struct names must begin with a capital letter. Struct members can begin with either lowercase or uppercase; in the former, the member is mutable and in the former the member is const. Struct members may be any type, including other structs.
246
+
247
+
Struct declarations do _not_ need to be followed by a semicolon (as they are in C/C++).
248
+
249
+
.example Struct
250
+
[source,idl]
251
+
----
252
+
struct TranslationResult {
253
+
Bits<PHYS_ADDR_WIDTH> paddr; # a bit vector
254
+
Pbmt pbmt; # an enum
255
+
PteFlags pte_flags; # another enum
256
+
}
257
+
----
258
+
259
+
Structs can be the return value of a function. Structs, like every other variable in IDL, are always passed-by-value.
260
+
243
261
==== Arrays
244
262
245
263
Fixed-size arrays of other data types may also be created in IDL. The size of the array must be known at compile time (_i.e._, there are no unbounded arrays like in C/C++).
@@ -592,7 +610,7 @@ Bitfields can be converted to a `Bits<N>` type, where N is the width of the bitf
592
610
593
611
== Casting
594
612
595
-
There are two explicit cast operators in IDL: `$isigned` and `$bits`.
613
+
There are four explicit cast operators in IDL: `$signed`, `$bits`, `$enum`, and `$enum_to_a`.
596
614
597
615
Unsigned Bits<N> values may be cast to signed values using the `$signed` cast operator.
The `$enum` cast will convert a `Bits<N>` type into an enum.
652
+
653
+
[source,idl]
654
+
----
655
+
$enum(RoundingMode, 1'b1) # => RoundingMode::RTZ
656
+
----
657
+
658
+
The `$enum_to_a` cast will convert an enumeration type into an array of the enumeration values. The values will in the declaration order of the enum members.
659
+
660
+
[source,idl]
661
+
----
662
+
$enum_to_a(RoundingMode) # => [0, 1, 2, 3, 4]
663
+
----
664
+
665
+
== Builtins
666
+
667
+
IDL provides a several builtins to access implicit machine state or query data structure properties.
668
+
669
+
=== Implicit Machine State
670
+
671
+
The current program counter (virtual address of the instruction being executed) is available in `$pc` in Instruction and CSR scope. `$pc` is not available in function scope or global scope.
672
+
673
+
The current instruction encoding (of the instruction being executed) is available in `$encoding` in Instruction and CSR scope. `$encoding` is not available in function scope or global scope.
674
+
675
+
=== Data Type Queries
676
+
677
+
The size (number of members) of an enum can be found with `$enum_size`.
678
+
679
+
[source,idl]
680
+
----
681
+
$enum_size(RoundingMode) # => 5
682
+
----
683
+
684
+
The size of an enum element (the number of bits needed to represent the largest enum value) can be
685
+
found with `$enum_element_size`.
686
+
687
+
[source,idl]
688
+
----
689
+
$enum_element_size(RoundingMode) # => 3
690
+
----
691
+
692
+
The size (number of elements) of an array can be found with `$array_size`.
693
+
694
+
[source,idl]
695
+
----
696
+
Bits<32> array [13];
697
+
$array_size(array) # => 13
698
+
----
699
+
633
700
== Control flow
634
701
635
702
IDL provides if/else and for loops for control flow.
@@ -926,22 +993,3 @@ mstatus:
926
993
reset_value(): |
927
994
return (M_MODE_ENDIANESS == "big") ? 1 : 0;
928
995
----
929
-
930
-
== Compilation order
931
-
932
-
The order of declaration is important in IDL (like C/C++, unlike Verilog). A variable, constant, or function must be declared *before* it is used.
933
-
934
-
.Compilation order
935
-
[source,idl]
936
-
----
937
-
function mod {
938
-
...
939
-
body {
940
-
# (-, remainder) = divmod(value); # compilation error: divmod not defined
0 commit comments