Commit Graph

18 Commits

Author SHA1 Message Date
John Demme 965f6b0407 [Python] Add module name to backedges remaining error message 2024-06-11 03:43:25 +00:00
Andrew Lenharth 164dbaf9cd
[HW] Change printer for modules (#6205)
This is quite invasive.  This converts from the functiontype printer to the moduletype printer.

---------

Co-authored-by: Mike Urbach <mikeurbach@gmail.com>
2023-09-28 16:30:15 -05:00
John Demme 04e91881a5
[Python] Use the "private namespace" approach for mlir dep (#4546)
Closes #3475. Also switch to relative imports in the hope that other projects (ie PyCDE) can include the CIRCT bindings privately.
2023-01-13 17:34:08 -08:00
Morten Borup Petersen 041a5dc6a4 [PyCDE] Clarify BackedgeBuilder error message
Presumably, this error message stems from when BackedgeBuilder was initially used solely for creating backedges to top-level port assignments when creating a new module instance. However, the `BackedgeBuilder` is also used for other operations (and useful as a general tool), wherein 'port' may be misleading. Changing this to `Backedge` makes it explicit that a backedge was created, and was expected to be assigned to.
2022-07-18 15:21:52 +02:00
Morten Borup Petersen d66cbfe9ea
[PyCDE,CAPI] Add support for the FSM dialect (#3400)
This is an initial commit for adding a CAPI for FSM as well as PyCDE support for constructing these.

See `test_fsm.py` for usage.

FSMs are constructed in a similar manner to PyCDE modules through a decorator on a class describing the FSM.
The FSM class may contain inputs (no outputs for now) and must provide
- A dictionary containing the states and their transitions
- A default state

State transitions may be either always taken, or taken based on some guard. This guard is defined by a function provided to the transition, which (like `@generator` functions) acts on the ports of the FSM.

The FSM will then be constructed with an output for each state, asserted when that state is active.

One important implementation note is the fact that the `fsm.machine` operation is treated as a PyCDE Module - there was surprisingly little friction slotting it into the current code and everything works as expected wrt. referencing `fsm.machine` in/out arguments through the transition guard functions.
However, modules instantiating the FSM expect a hardware-like interface, this being the ports of the `fsm.machine` operation + clock and reset signals. An `fsm.machine` op does not have these signals at the top level, since these are added during hardware lowering. To me, this is a sensible design choice, seeing that the FSM dialect should be applicable to both software and hardware representations (...eventually).

To get around this, the user will specify the intended name of the `clock` and optional `reset` signal of an FSM. A wrapper module is then created that provides the correct interface to the instantiating module, as well as instantiating the FSM through a `fsm.hw_instance` operation, doing the proper hoop-jumping to attach the clock signal (see `fsm_wrapper_class`).

There's still some work to do on the CIRCT side of the FSM dialect to clean it up a bit + make it a viable target for a front-end, but this commit represents the brunt of work on the PyCDE side.
2022-06-27 16:14:38 +02:00
John Demme 51639cad29
[PyCDE] Moving the most opinionated python out of bindings (#1179) (#1195)
- Creating new frontends top level directory which contains frontends which are optionally included.
- Moving @module and @Generator into PyCDE frontend.
- Keeping connect in the bindings since it's used in the bindings tests.
- Fixing the integration tests.

Closes #1179.
2021-06-03 09:43:02 -07:00
mikeurbach 7a2fa8d6da
[Python] Update all create methods to accept keyword arguments. (#1167)
This makes the API more natural compared to an explicit dictionary of
input ports to set by name.
2021-05-27 17:57:40 -06:00
mikeurbach 6de40d2b87
[Python] Add a helper to create constants given a type and value. (#1165)
This still requires an explicit type from the end user, but it hides
the fact that an Attribute must be constructed under the hood.
2021-05-27 15:44:39 -06:00
John Demme ea49031dc5
[Py] Adding named input/output args/results to body_builder (#1124)
Create an `OutputOp` out of the return value from `body_builder`. Eliminate input ports as `construct` args. Move all of the `module.entry_block.arguments[1]` ugliness to the new `module.foo` syntax.
2021-05-24 17:08:16 -07:00
John Demme fefdabc28f [Py] Fixing integration tests
`circt` no longer imports `design_entry` into its namespace.
2021-05-21 18:27:07 -07:00
mikeurbach 04e9699ab3
[Python] Add generic connect API that works with builders. (#1106)
This adds `circt.connect` to "connect" two values. It sets the
destination OpOperand to the new value.

To integrate with the builder approach, this updates the
InstanceBuilder to return a wrapper BuilderValue around any Values
accessed through `__getattr__`. This works with the connect API to
pass around the needed index to ultimately set the Value and erase any
temporary backedges the builder created.

As the builder approach is generalized to other ops, the connect API
should work in exactly the same manner.
2021-05-21 17:09:48 -06:00
Mike Urbach 80a08ac9e8 [Python][NFC] Remove unused module parameter to create call.
This is no longer needed now that the BackedgeBuilder is implicit.

This change also includes some whitespace updates to line things up
after the RTL->HW name change.
2021-05-21 16:29:08 -06:00
John Demme 83116dc2e1
[Py] Make BackedgeBuilder more general and keep a stack (#1119)
Divorces the support BackedgeBuilder from InstanceBuilder (so it can be used
elsewhere). Stores some extra information in the edge instead of digging it up
later in an InstanceBuilder-specific way.

Keep a stack of BackedgeBuilders in a contextvar. Provide a static method to
get the top.
2021-05-21 09:37:19 -07:00
Chris Lattner 53b1c077d6 [RTL->HW] Rename C++ namespace, command line flags and a bunch of other stuff. 2021-05-15 14:33:45 -07:00
Chris Lattner e31e8a3e3d [RTL->HW] Rename the rtl dialect to hw dialect in MLIR syntax. 2021-05-15 14:24:43 -07:00
Chris Lattner 4d43103122 [RTL->HW] Rename the string "RTL" to "HW"
This makes sure not to rename FIRRTL to HWRTL :-), and I spot checked a
many things to avoid changing general references to RTL (e.g. when referring
to external tools) but I suspect that I missed some.  Please let me know (or
directly correct) any mistakes in this mechanical patch.
2021-05-15 12:44:05 -07:00
mikeurbach 25ddbddc2d
Python rtl block args (#1021)
This mirrors the syntax exposed for RTL instances by the
InstanceBuilder.
2021-05-06 19:10:41 -06:00
mikeurbach 6febae58f5
[RTL][Python] Add InstanceBuilder for constructing instances. (#940)
Python. The builder accepts a name for the instance and optional
values to assign to the input ports. The InstanceBuilder supports
attribute getters and setters for the ports.

When ports are not set on creation, temporary operations are inserted
into the IR via a BackedgeBuilder. The BackedgeBuilder can be used as
a context manager, and checks the temporary operations are all
resolved on exit. This is wrapped around the body_builder of modules
to ensure all instances are wired up after the body_builder exits.

A create method is added to RTLModuleOp, which constructs and returns
an InstanceBuilder for an instance of that module.
2021-05-05 13:12:18 -06:00