| Crates.io | yarig |
| lib.rs | yarig |
| version | 0.16.1 |
| created_at | 2025-01-12 05:55:18.336018+00 |
| updated_at | 2025-08-21 09:12:44.082958+00 |
| description | A register interface generator |
| homepage | |
| repository | https://github.com/TheClams/yarig |
| max_upload_size | |
| id | 1512972 |
| size | 894,828 |
YARIG is a code generation tool to describe register interface of an IP or ASIC/FPGA design.
This allows to have one common source to describes registers for all the different views:
More details on targets are available in hardware targets and other targets.
YARIG uses its own file format named .rif to describe the registers.
The objectives when designing the language were:
Complete details are available in the syntax page
Here is a simple RIF definition:
rif: test_rif
addrWidth: 8
dataWidth: 16
- Main:
registers:
- ctrl: "Basic control register"
- en = 0 0:0 "Block enable"
- start = 0 0:0 pulse "Start block"
- version = 0x12 15:8 ro "Block version"
hw na
- interrupt: "Interrupt register"
interrupt rising en=0x13 mask=0x37 pending w1clr
enable.description "Enable interrupt"
mask.description "Mask interrupt"
pending.description "Pending interrupt"
- gen = 0 7:0 rw "Generic Events"
- busy = 0 8:8 "Busy"
- ready = 0 9:9 "Ready"
- status: "Status register"
- state 3:0 "Current state"
- success 4:4 "Last operation succeed"
- failed 5:5 "Last operation failed"
instances: auto
Highlighting for SublimeText is available on github and for VScode on the marketplace
Of all existing approach, I think that only SystemRDL comes close to covering all the features I need. The idea of separating register definition and instance is key to allow re-use among different project. But the main weakness of SystemRDL (in my opinion) is that the syntax is neither easy to read nor easy to write.
How simpler is the RIF syntax compare to the SystemRDL is quite subjective, but like can be seen in the syntax example it is quite compact when defining simple register, with default behavior that should feel intuitive. For example, if there is no reset value an no hardware/software defined, then it is assumed this is a read-only register driven by hardware.
In term of features missing from SystemRDL, the main one I have identified are:
But I think RIF has a few improved featured (in no particular order) :
Fine control over both the hardware register structure and its software mapping: instead of defining a whole register structure which is then mapped automatically on address aligned with the software bus, the definition of register must be aligned on the software bus, but each register can have a group name so that they appear in the same structure in hardware.
Fine control of clock/reset used per register/field: there is still the hypothesis that all clock are synchronous but it is easy to have fields driven by different clock/reset.
Pulse field can be defined as combinatorial or register
Password field: allows to set high an internal signal only when a given value is written. This allows to protect some register against write access until the password is written, useful for critical register related to power or clock tree for example.
Limit property: allows to ensure only a subset of value can be written in a register
Enum can have a representation value on top of their encoded integer value. (for example CR_1_2 = 1 (0.5) "Coderate 1/2" )
Defining number of fractional bits associated with a field: allows to define reset value in a more intuitive way when the register represent fixed-point values
Visibility control: when generating documentation for public purposes, sometimes is is useful to hide some register,
some part of the description, or automatically rename fields as reserved_xx to allow access without exposing the full meaning behind the register
Generics, i.e. HDL compile-time parameter
A configuration file allows to specify many options of the generators like the RIF file, a list of target, the output path for each targets, ...
All available options are described in the config page.
Here is an example:
filename = "my_chip.rif"
gen_inc = ["*"]
targets = ["py", "sv", "html", "latex", "c"]
[suffixes.spi]
name = "full"
pkg = true
[outputs]
doc = "../yarig/doc"
c = "../yarig/c"
py = "../yarig/py"
rtl = "../yarig/rtl"
sim = "../yarig/sim"
vhdl = "../yarig/vhdl"
Most settings from the configuration file can be overridden by command-line arguments. Run yarig -h to list all available options.
To streamline the development of new output targets, the library contains three generator traits, which basically go through the different elements of the structure and apply the visibility checks (public/private). The exact behavior of each traits can be tweaked with some associated constants/functions.
All generator are based on the struct GeneratorCore and trait GeneratorBase.
The core offers some basic information/features needed by most generator:
push_stash to add string to a stashpop_stash to move a stash content to the main bufferpop_stash_to to move a stash content to another stashThe GeneratorBase trait is required by all three specialized traits (Hardware/Software/Documentation) and basically gives access to the GeneratorCore features. It has an associated constant to define the file extension wanted and provides two functions (filename_rif/rifmux) to get consistent output file naming (when no name is provided by the user).
To avoid boilerplate when defining a new generator, the derive macro add_gen_core("ext")
automatically add a field core: GeneratorCore to a structure and implements the GeneratorBase trait for this struct.
All generators are based on one of the three available traits and can serve as good example of how to develop a new generator. Code is located in src/generator.
This trait creates a view of the components from the software point of view.
It is highly configurable and supports both typed and untyped output:
The following associated constant allows to tweak the generated output:
HAS_ENUM : Declare enum typeSINGLE_FILE : Generate a single file for the rifmux and all its RIF definitionHAS_UNUSED : Unused part of the register also have field declarationINST_BY_PAGE : Create one structure per page instead of grouping all register and ignoring the page structureINC_PAGENAME : Include pagename inside basename of registersINST_ARRAY : Create only one register instance per array (false to create instance per element)IS_HIERARCHICAL : Instantiate rifmux instead of flatenning all rifs instanceHAS_REG_DECL : Create register type declaration before register instanceThis trait is used by the generators for C, IPXact, JSON, Python, UVM RAL and SVD.
This trait creates a view of the components from the hardware point of view.
It creates a package for type/enum/constant definition and a second file containing the actual hardware implementation.
For RIF component, the following constant are declared
has_const_reg() is true: address and reset value of all registershas_const_field() is true: mask, LSB/MSB and reset value of each fieldsFor RIFMux, he constant in the package are the address of all RIF components.
The following associated constant allows to tweak the generated output:
SUPPORT_INTF : Support SystemVerilog like interfacesSUPPORT_IMPL_BIND : Support implicit binding of ports (.* in SystemVerilog)This trait is used by the generators for SV and VHDL.
This trait shows a component description with multiple table with links:
The following associated constant allows to tweak the generated output:
HAS_LAYOUT : Display register layout tableSHOW_RESET : Show reset in the register summarySHOW_TYPE : Show type name in both summary tables (top/register)SHOW_SINGLE_REG : Show register instance table even when there is only one instanceSHOW_UNUSED : Unused part of a register are displayed as reserved in the field tableThis trait is used by the generators for AsciiDoc, HTML, Latex and Mif (FrameMaker).