Metadata-Version: 2.4
Name: xactflow-rtlgen
Version: 0.1.0
Summary: XactFlow exporter plugin that generates a SystemVerilog top-level module from an IP-XACT design.
License-Expression: LGPL-3.0-only
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: xactflow<0.6,>=0.4.0
Requires-Dist: ipxact-compiler>=0.2.0
Dynamic: license-file

# rtlgen

A [XactFlow](https://github.com/IP-XACT/XactFlow) exporter plugin that generates a
SystemVerilog top-level module from an IEEE 1685-2022 (IP-XACT) design.

It is being written step by step. Steps 1 to 10 are done: the plugin is registered with
XactFlow as the `rtl` subcommand, links the design against its library, names the module from
the component that holds the design, and writes the module with that component's ports and
one instance per subcomponent, each named after the module its component gives, with its
module parameters and their values in this design. Instances are wired to each other and to
the top ports through the design's ad hoc connections: one `wire` per net between instances,
and a net that reaches a top port, or a slice of one, is that port or slice. Bus
interconnections between two instances are wired too: one `wire` per logical port that both
ends map, named `<interconnection>_<logical port>` and numbered like the logical port. Ports
may be connected in parts (written as concatenations), tied to constants (`tiedValue`) or left
open; an input that only one end of a bus maps takes the abstraction definition's default
value. A hierarchical subcomponent gets a module of its own, generated from its design in the
same run by the same rules, and a bus interface of the top (`hierInterface`) is wired straight
to the instance's ports. Where the input gives no module name, the module is named after the
component's VLNV name. A module parameter's value may be a SystemVerilog package name
(`pkg::NAME`), written as it stands; ports of a packed struct type are declared with that type
and connected whole to a top port; and an output on several bus nets, or on a bus net and in an
ad hoc connection, drives the other nets with `assign`s. A module whose instances include
decoders, components described as transparent bridges, also gets `<module>_addr_map_pkg.sv`
with each window's base, size and end; a decoder takes its table from its own component's
expression, and a value wider than 32 bits is written as sized hex. With these, it generates the
standard top of the Triglav SoC and its address-map packages from standard IP-XACT.

## Use

```bash
pip install xactflow-rtlgen        # or, from a clone: pip install -e .
xactflow rtl <design.xml> --lib <dir> [--lib <dir> ...] --output <dir>
```

It writes `<module>.sv` into the output folder, and one more file for each hierarchical
subcomponent. It can also take a design straight from an
importer, with no XML file in between:

```bash
xactflow archidesc design.py --lib <dir> [--lib <dir> ...] --then rtl --output <dir>
```

Since XactFlow 0.5.0 this also writes the importer's IP-XACT XML into the same folder; add
`--no-xml` to get `<module>.sv` only.

rtlgen refuses, with a message, anything it does not handle yet (see `docs/decisions.md`):

- options, design configurations, a library that reports errors, a design that does not link, a
  module name it cannot find;
- an address window it cannot read: an opaque bridge (`subspaceMap`), a bridge to an interface
  that is not an initiator, an initiator with no address space or `baseAddress`, `addressUnitBits`
  other than 8, a base or range that is not a whole number, a negative base or a range of 0; and
  in the package, a constant name that is not an identifier or that two windows share, an end
  past 64 bits, or a package named like a module;
- a virtual subcomponent, one in a language other than SystemVerilog, an override naming no
  parameter of the component, a module parameter that is not typed or whose value cannot be
  worked out (a package name is passed on only as the whole value, and refused with a
  `minimum` or `maximum`), a negative value wider than 32 bits, parameters on the top or on any
  generated module;
- a hierarchical subcomponent it cannot generate: one that reaches its design only through a
  design configuration, has views referencing different designs or also a view naming only an
  RTL module, is given parameter values, or whose design is missing or does not link; two
  components that give one module name, a generated module named like a leaf module, or a
  hierarchy that loops;
- a top port it cannot declare: a transactional or array port, one with several vectors, or one
  named like an instance;
- a structured port it cannot write: anything but a packed struct `in` or `out` with no
  sub-ports or vectors and one type definition named `[pkg::]name[...]`; one in anything but an
  ad hoc connection joining it whole to one top port of the same type and direction; a
  structured input that nothing reaches;
- an instance port it cannot leave open: an input that nothing reaches, or bits of one, and a
  bus interface with `connectionRequired` that no interconnection uses;
- an ad hoc connection it cannot wire yet: whole ports of different widths, opposite bit orders,
  a phantom, array or transactional port, a sub-port, a part select it cannot take (indices,
  outside the port, against it, partly overlapping another), a net that joins two top ports or
  slices, an instance output driving a top input, a top output or bits of one that nothing
  drives, or a connection name that clashes with an instance or a top port or is used twice;
- a tie-off it cannot write: a value on an instance output or `inout` or on a top input or
  `inout`, `default` on a port with no default value or on part of a port, a value that does
  not fit the port or cannot be worked out, or a tied port in another connection;
- a bus interconnection it cannot wire yet: a monitor interconnection, more than two ends,
  modes other than an initiator with a target, no or several abstraction types, an excluded port
  no port map uses, a port map that is tied off (`logicalTieOff`), inverted or to a sub-port, an
  ascending logical range, ranges of unequal size, logical or physical bits mapped twice, a
  physical port that is missing, phantom, an array or not a wire, input bits that only one end
  maps, a logical port with `match` that only one end maps, a default it cannot write, two inputs
  or two outputs on the same bits, a net name that clashes, an interconnection name used twice,
  an input or `inout` bit on both a bus net and an ad hoc connection or on two bus nets, or an
  output on several nets that is only part of one of them or whose ad hoc net has another
  driver;
- a bus interface of the top (`hierInterface`) it cannot wire yet: one joined to more than one
  instance bus interface or to one of another mode (only an initiator with an initiator, or a
  target with a target), a port map of its own that the checks above refuse, an instance output
  on a top input or an instance input on a top output, top output bits that nothing drives, or a
  top port bit also reached another way.

## Docs

- `docs/decisions.md`: the decisions that shape the exporter, why they were made, and what
  would reopen them.
- `docs/scr-checks.md`: the checks rtlgen makes that an IEEE 1685 semantic consistency rule
  covers, each to be removed once XactFlow checks that rule (D35).

## Tests

The tests read the XactFlow author's example design, `soc_a`, from the clone that
`RTLGEN_EXAMPLE` names, and skip when it is not set or the generated files are missing (D3).
The example has no licence file, so nothing from it, nor generated from it, goes into this
repository: the generated files live in `build/`, which git ignores.

```bash
pip install -e . pytest xactflow-archidesc==0.4.0
git clone https://github.com/mtravaillard/example_XactFlow.git ../example_XactFlow
export RTLGEN_EXAMPLE=$(realpath ../example_XactFlow)

# The design and the component holding it, into build/soc_a. Rerun when the example changes.
OUT=$PWD/build/soc_a
cd "$RTLGEN_EXAMPLE/xml_to_design"
xactflow archidesc design.py --output "$OUT"
cd -

pytest -q
```

archidesc 0.4.0 needs XactFlow 0.5.0, and brings the `component` and `design` exporters that
write the two files. Before 0.3.1, archidesc wrote a component that D1 refuses.

## Licence

LGPL-3.0-only, see `LICENSE`.
