Commit Graph

44 Commits

Author SHA1 Message Date
John Demme 030c51010e
[PyCDE] Make systems feel more like modules (#1401)
- Adds customized naming
- The body_builder 'mod' input ports now return PyCDE values
2021-07-09 16:24:05 -07:00
John Demme 5ce156846a [PyCDE] Python code formatting fixes
Re-ran yapf since formatting issues slipped by while the CI check was broken.
2021-07-07 21:50:04 -07:00
John Demme e5993c4c25
[PyCDE] Misc usability features (#1390)
- Hide module parameterization function arguments beginning with '_' from operation parameters.
- Module `.output_values()` returns a dict of output ports to Values.
- `System.print` passes through args.
2021-07-07 21:47:42 -07:00
John Demme 16361c5675
[Py] [PyCDE] Use `bitcast` to convert structs to TypeAliasTypes and take advantage of aliases (#1382)
- Use a bitcast in StructCreateOp.create() if the result_type is specified.
- Take advantage of type aliases in naming.
- In creating OutputOps, automatically convert to an alias if the port is just a type aliased version of the value being returned.
- (Unrelated) add class name in _create_output_op messages.
2021-07-06 19:53:19 -07:00
John Demme 73d61f37cd
[Py] [PyCDE] More type checking in HWInstances and module instantiation (#1378)
- Adds type checking to PyCDE module instantiations.
- Corrects generate to use types defined in class rather than the example op.
- Adds type checking to Python bindings ModuleLike.create()
- Adds a safety check to ModuleLike.__getattr_() to avoid infinite recursion.
2021-07-06 16:15:42 -07:00
John Demme 08498549b2
[PyCDE] Improvements for TypeAlias and more location setting (#1377) 2021-07-06 15:22:28 -06:00
Mike Urbach 70e7402caf [PyCDE] Fix two minor issues after merging latest PRs.
First, some code that attempted to store into an instance variable
that no longer exists. This should have been included in the last PR.

Second, flush the stderr stream in the new struct fields test. This
may not have been necessary on its own before, but in my testing with
both PRs integrated, I was observing the struct fields showing up
after the other output, and FileCheck failing.

After these two minor fixes, the tests pass.
2021-07-05 21:58:08 -06:00
mikeurbach 26acd29cb6
[PyCDE] Add functionality to declare named types. (#1369)
This builds on the previous support to allow naming types through
PyCDE's types module. A new method will declare the registered type
aliases in a given mlir::ModuleOp. Multiple invocations will only emit
each alias once per module. This method is not intended to be exposed
to an end user, rather it is invoked automatically within a PyCDE
System during the user-facing method run_passes.
2021-07-05 21:41:21 -06:00
John Demme 2a7505c33f
[Py] [PyCDE] Add `get_fields` to struct type and use it in pycde (#1364)
PyCDE uses this for error checking and `.` access.
2021-07-05 20:36:54 -07:00
Mike Urbach 5184208162 [PyCDE][NFC] Move types test to another file.
Testing the types module within a file types.py was introducing a
circular import.
2021-07-02 15:44:58 -06:00
mikeurbach 340f1d069a
[PyCDE] Refactor global _Types module and support aliases. (#1363)
The _Types is now just a regular instance with instance methods. These
methods now take a possible alias to apply to the requested type. The
aliases are stored and checked to ensure the same alias isn't handed
out to different types.
2021-07-01 18:08:37 -06:00
John Demme f47fe6cc06
[PyCDE] Make `pycde.support.Value` get the PyType if not specified (#1355)
This involves a hack similar to the Attribute hack.
2021-06-30 20:50:39 -07:00
John Demme ae4f17b077 [PyCDE] Fixes and source locations for more ops 2021-06-30 16:51:34 -07:00
John Demme a8e645bf01
[PyCDE] Add source location info where we control operation creation (#1348)
For new module instances, set to the callsite. For misc creation a generator,
use the location of the generator. I think this is the best we can reasonably
do without upstream support.
2021-06-29 22:31:02 -07:00
John Demme f54b74fb87 [PyCDE] Fix the test I broke with the last commit 2021-06-29 18:32:33 -07:00
John Demme 5ab2aceccc [PyCDE] Don't print the IR on exceptions during generation
An exception during generation typically results from or in invalid IR, so
calling 'print' re-prints the IR validation error message followed by a lot of
generic IR. In short, this hasn't been terribly helpful and is annoying.
2021-06-29 18:21:02 -07:00
John Demme fedaca02bc
[PyCDE] Serialize class parameters to attributes (#1345)
Since we want/need to support classes (for sanity's sake in large configuration
spaces), we need to include their data in the MLIR parameters attribute to
avoid duplication.
2021-06-29 17:57:25 -07:00
John Demme c0dd170433
[PyCDE] Naming fixes and style changes (#1342)
- Fixes a duplicate definition bug: in the case of parameterized modules, multiple generators (per parameterization call) are created so we cannot store the generated_modules map in the instance. Instead, we look it up in the IR.
- If the module has parameters, append them regardless of potential conflicts. This makes for less confusing code in the common case of multiple parameterizations since the first parameterization doesn't get a special name.
- Add the "pycde." prefix so we don't create modules which have name conflicts with existing RTL modules.
2021-06-29 16:26:11 -07:00
John Demme 7f87e32441
[PyCDE] Treat extern modules differently (#1338)
- Extern modules' instances types don't always match the declared types. Allow instance creation to specify the result types.
- (Unrelated) check the return types when creating output ops.
- (Unrelated) ditch the PyCDE version of connect.
2021-06-29 13:05:40 -07:00
mikeurbach c77c67c231
[PyCDE] Clean up module key and use it as name when necessary. (#1339)
If the user doesn't specify a get_module_name or otherwise set the
module_name parameter, use the improved module key as the name.

This will skip renaming for: 1) the first time a module with
parameters is instantiated, and 2) modules that are unparameterized.

To be able to fully skip renaming when all instantiations of a
parameterized module are the same, we'll either need some global data
on the side, or to start putting the parameters into the HWModuleOp.
2021-06-29 00:21:40 -06:00
Andrew Young a29f82d02c
[Python][Seq] Fix integration test (#1315)
Verilog emission is now defaulting to print `always` instead of
`always_ff`.  These tests don't run in a PR and were missed during
the change.
2021-06-23 10:45:45 -07:00
mikeurbach 9dd73b174f
[PyCDE] Include parameters in generator registration and lookup. (#1298)
Previously, different parameterizations of the same module would end
up using the most-recently registered generator and the
parameterization used when it was registered.

This includes the parameterization in the registered mapping, and
looks for that same parameterization when looking up generators. This
is trivially supported since we already store the parameterization as
an attribute on the Operation.

Added a few lines to the polynomial integration test to ensure the
behavior.
2021-06-17 19:59:48 -06:00
Mike Urbach 99cc3a854d [PyCDE] Include lower-seq-to-sv pass for PyCDE Systems.
This supports lowering the `seq.CompRegOp` to SV operations before
exporting PyCDE Systems as SystemVerilog. The pass is already
registered, and just needs to be plugged in.
2021-06-17 19:15:28 -06:00
Mike Urbach 6d181189a7 [PyCDE] Add helper to get module output ports.
After significant restructuring in d52ef85d, a helper was added to
simply retrieve the module's inputs. This is the same for outputs. It
will be generally useful to some upcoming changes.
2021-06-17 17:14:42 -06:00
John Demme ebb66eed82
[PyCDE] Support result array/struct subscripting + misc. related improvements (#1286)
Enables subscripting result array and struct values:

```
a = ModuleWithArrayAndStructResults(clk=clk)
array1_idx0 = a.array1[0]
struct1_foo a.struct1["foo"]
```
2021-06-16 17:05:50 -07:00
John Demme 2fa15a18ef
[PyCDE] Add graphviz output (#1285) 2021-06-16 16:22:05 -07:00
John Demme d52ef85d61
[PyCDE] Declare parameterized modules in functions (#1241)
Require parameters, inputs, and outputs to be declared before operation construction. The supported way is to declare the class in a function then return it. This ensures that all the parameters are in scope for the generators, so they no longer need to be passed into it. This is a rather large refactor but this new way of parameterizing modules makes more sense.
2021-06-13 23:21:29 -07:00
John Demme ed6e065116
[PyCDE] Add `dim` function to create multidimensional array (#1251) 2021-06-11 17:54:56 -07:00
John Demme bcc0accbe4
[PyCDE] Set the module name to differentiate modules with different parameters (#1222) 2021-06-10 12:36:45 -07:00
John Demme d7714ddfbb
[PyCDE] Allow generators to ignore parameters (#1233) 2021-06-10 12:23:35 -07:00
mikeurbach a84c2eb7c7
[PyCDE] Add generator options to select a generator by name. (#1229)
The `generate` call accepts a list of candidate generators to run,
which defaults to empty.

When looking up a generator, the list is consulted. If it is empty,
and there is one generator, that is used by default. If it is present,
and it names one of the candidate generators, that is selected. If it
names multiple candidate generators, an error is raised.
2021-06-09 16:07:20 -06:00
mikeurbach ad745f0145
[PyCDE] Make `inputs` an explicit argument, and pass the other kwargs through. (#1221)
This more cleanly separates the mandatory input arguments from
arbitrary arguments to the user-defined constructor.
2021-06-09 14:11:53 -06:00
John Demme f6c76aa922
[PyCDE] Pass module parameters as generate function args (#1219)
We need the ability to convert Attributes back to python values for PyCDE. The MLIR conversation about this feature, however, isn't going anywhere fast. This includes a hack to get us unblocked until that conversation resolves.
2021-06-08 14:37:08 -07:00
John Demme 0cf566bace
[Py] Ditch `BuilderValue` in favor of unified `OpOperand` (#1216) 2021-06-08 09:16:00 -07:00
John Demme 0e74cf6c9b [PyCDE] Ignore python object attributes which begin with '_' 2021-06-07 21:02:32 -07:00
John Demme 652b050fa9
[PyCDE] Add @externmodule annotation (#1212)
To represent a hw.module.extern. Creates a generator to output the extern mod and the instance.
2021-06-07 15:32:50 -07:00
John Demme 53816e3942
[PyCDE] Add a types module to easily create MLIR types (#1210) 2021-06-07 15:00:29 -07:00
John Demme 268bd479a6 [Py] [PyCDE] Adding `inputs()` and IR dump on any sort of error
`inputs()` helps with interface construction for passthrough ports.
2021-06-07 13:18:23 -07:00
mikeurbach d8f4a5dd26
[PyCDE] De-duplicate modules that are structurally equivalent. (#1201)
This de-duplicates modules by the following properties:
  * The Operation name being generated
  * The Operation's Input names and types
  * The Operation's Output names and types
  * The Operation's Parameter names and values

This allows the same PyCDE operation to be instantiated multiple
times, without trying to define the module multiple times.
2021-06-03 18:12:09 -06:00
John Demme 10ac5685cc
[PyCDE] Store design parameters in the 'parameters' attribute (#1200)
All other attributes come from object members (which can be converted to
attributes) and get inherited by the instance.
2021-06-03 16:17:47 -07:00
John Demme 82799b2e4c
[PyCDE] Create 'System' to provide nicer interface to users (#1198)
Looks kind of like the ESI system. A bunch of the convenience stuff should
probably be moved into pycde at some point.
2021-06-03 13:42:42 -07:00
Mike Urbach 0eb3af159e [Python] Reformat all Python sources, NFC.
The format PR gate was previously broken, so some format issues
slipped in. This runs `yapf -i -r .` over the whole repo.
2021-06-03 12:00:44 -06:00
John Demme 28a47e93fc
[Py] Design entry: store and retrieve parameters as attributes (#1185) 2021-06-03 10:45:15 -07: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