Skip to content

Get inst verilog #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/test_verilog/foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import magma as m


class T(m.Product):
x = m.Bit
y = m.Bits[2]


class Baz(m.Circuit):
io = m.IO(I=m.In(T), O=m.Out(T))
io.O @= io.I


class Bar(m.Circuit):
io = m.IO(I=m.In(T), O=m.Out(T))
io.O @= Baz(name="baz")(io.I)


class Foo(m.Circuit):
io = m.IO(I=m.In(T), O=m.Out(T))
io.O @= Bar(name="bar")(io.I)


m.compile("build/Foo", Foo)
32 changes: 32 additions & 0 deletions tests/test_verilog/test_get_inst_verilog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import magma as m


class T(m.Product):
x = m.Bit
y = m.Bits[2]


def test_get_inst_verilog():
dirname = os.path.abspath(os.path.dirname(__file__))
os.system(f"cd {dirname} && python foo.py")
# TODO: Need API to load with a symbol table
# Also, would be nice to derive a wrapper (e.g. reconstruct the tuples)
Foo = m.define_from_verilog_file(f"{dirname}/build/Foo.v")[0]

class Main(m.Circuit):
io = m.IO(I=m.In(T), O=m.Out(T))
foo = Foo()
# TODO: If we can reconstruct the original tuple for foo, we can just
# pass the packed tuple rather than x, y individually
io.O @= T(*foo(io.I.x, io.I.y))
# TODO: Need API to refer to instance nested inside a verilog imported
# module (resolved using the symbol table)
# Proposed API is to pass a name for instances, hierarchical reference
# using a variable number of string arguments
# Then the instance reference provides attributes for magma's standard
# type syntax (e.g. dot notation tuples, subscript for arrays)
ref = foo.get_instance("bar", "baz").O.x[1]
m.inline_verilog('assert ({A} == 1) else $error("ERROR");', A=ref)

m.compile("build/Main", Main)