-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
327 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* External Modules | ||
module or ( | ||
input I0, | ||
input I1, | ||
output O | ||
); | ||
endmodule // or | ||
*/ | ||
/* External Modules | ||
module invert ( | ||
input I, | ||
output O | ||
); | ||
endmodule // invert | ||
*/ | ||
/* External Modules | ||
module and ( | ||
input I0, | ||
input I1, | ||
output O | ||
); | ||
endmodule // and | ||
*/ | ||
module Test ( | ||
input I0, | ||
input I1, | ||
output O, | ||
input S | ||
); | ||
|
||
|
||
wire and_inst0__I0; | ||
wire and_inst0__I1; | ||
wire and_inst0__O; | ||
and and_inst0( | ||
.I0(and_inst0__I0), | ||
.I1(and_inst0__I1), | ||
.O(and_inst0__O) | ||
); | ||
|
||
wire and_inst1__I0; | ||
wire and_inst1__I1; | ||
wire and_inst1__O; | ||
and and_inst1( | ||
.I0(and_inst1__I0), | ||
.I1(and_inst1__I1), | ||
.O(and_inst1__O) | ||
); | ||
|
||
wire invert_inst0__I; | ||
wire invert_inst0__O; | ||
invert invert_inst0( | ||
.I(invert_inst0__I), | ||
.O(invert_inst0__O) | ||
); | ||
|
||
wire or_inst0__I0; | ||
wire or_inst0__I1; | ||
wire or_inst0__O; | ||
or or_inst0( | ||
.I0(or_inst0__I0), | ||
.I1(or_inst0__I1), | ||
.O(or_inst0__O) | ||
); | ||
|
||
assign and_inst0__I0 = S; | ||
|
||
assign and_inst0__I1 = I1; | ||
|
||
assign or_inst0__I0 = and_inst0__O; | ||
|
||
assign and_inst1__I0 = invert_inst0__O; | ||
|
||
assign and_inst1__I1 = I0; | ||
|
||
assign or_inst0__I1 = and_inst1__O; | ||
|
||
assign invert_inst0__I = S; | ||
|
||
assign O = or_inst0__O; | ||
|
||
|
||
endmodule // Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import magma as m | ||
from magma.testing import check_files_equal | ||
|
||
# Stub operators for test | ||
m.BitType.__and__ = \ | ||
lambda x, y: m.DeclareCircuit("and", "I0", m.In(m.Bit), | ||
"I1", m.In(m.Bit), | ||
"O", m.Out(m.Bit))()(x, y) | ||
m.BitType.__or__ = \ | ||
lambda x, y: m.DeclareCircuit("or", "I0", m.In(m.Bit), | ||
"I1", m.In(m.Bit), | ||
"O", m.Out(m.Bit))()(x, y) | ||
m.BitType.__invert__ = \ | ||
lambda x: m.DeclareCircuit("invert", "I", m.In(m.Bit), | ||
"O", m.Out(m.Bit))()(x) | ||
|
||
|
||
def test_new_style_simple_mux(): | ||
class Test(m.Circuit): | ||
io = m.IO( | ||
S=m.In(m.Bit), | ||
I0=m.In(m.Bit), | ||
I1=m.In(m.Bit), | ||
O=m.Out(m.Bit), | ||
) | ||
|
||
io.O <= (io.S & io.I1) | (~io.S & io.I0) | ||
print(repr(Test)) | ||
assert repr(Test) == """\ | ||
Test = DefineCircuit("Test", "S", In(Bit), "I0", In(Bit), "I1", In(Bit), "O", Out(Bit)) | ||
or_inst0 = or() | ||
and_inst0 = and() | ||
and_inst1 = and() | ||
invert_inst0 = invert() | ||
wire(and_inst0.O, or_inst0.I0) | ||
wire(and_inst1.O, or_inst0.I1) | ||
wire(Test.S, and_inst0.I0) | ||
wire(Test.I1, and_inst0.I1) | ||
wire(invert_inst0.O, and_inst1.I0) | ||
wire(Test.I0, and_inst1.I1) | ||
wire(Test.S, invert_inst0.I) | ||
wire(or_inst0.O, Test.O) | ||
EndCircuit()\ | ||
""" | ||
|
||
m.compile('build/test_new_style_simple_mux', Test, output="coreir-verilog") | ||
assert check_files_equal(__file__, f"build/test_new_style_simple_mux.v", | ||
f"gold/test_new_style_simple_mux.v") | ||
|
||
|
||
def test_new_style_nested(): | ||
Top = m.DefineCircuit("Top", "S", m.In(m.Bit), "I0", m.In(m.Bit), | ||
"I1", m.In(m.Bit), "O", m.Out(m.Bit),) | ||
|
||
# Begin definition of Mux while in the middle of defining Top. | ||
class Mux(m.Circuit): | ||
io = m.IO( | ||
S=m.In(m.Bit), | ||
I0=m.In(m.Bit), | ||
I1=m.In(m.Bit), | ||
O=m.Out(m.Bit), | ||
) | ||
|
||
io.O <= (io.S & io.I1) | (~io.S & io.I0) | ||
|
||
# Continue defining Top. | ||
mux = Mux() | ||
mux.I0 <= Top.I0 | ||
mux.I1 <= Top.I1 | ||
mux.S <= Top.S | ||
Top.O <= mux.O | ||
m.EndDefine() | ||
|
||
assert repr(Mux) == """\ | ||
Mux = DefineCircuit("Mux", "S", In(Bit), "I0", In(Bit), "I1", In(Bit), "O", Out(Bit)) | ||
or_inst0 = or() | ||
and_inst0 = and() | ||
and_inst1 = and() | ||
invert_inst0 = invert() | ||
wire(and_inst0.O, or_inst0.I0) | ||
wire(and_inst1.O, or_inst0.I1) | ||
wire(Mux.S, and_inst0.I0) | ||
wire(Mux.I1, and_inst0.I1) | ||
wire(invert_inst0.O, and_inst1.I0) | ||
wire(Mux.I0, and_inst1.I1) | ||
wire(Mux.S, invert_inst0.I) | ||
wire(or_inst0.O, Mux.O) | ||
EndCircuit()\ | ||
""" | ||
assert repr(Top) == """\ | ||
Top = DefineCircuit("Top", "S", In(Bit), "I0", In(Bit), "I1", In(Bit), "O", Out(Bit)) | ||
Mux_inst0 = Mux() | ||
wire(Top.S, Mux_inst0.S) | ||
wire(Top.I0, Mux_inst0.I0) | ||
wire(Top.I1, Mux_inst0.I1) | ||
wire(Mux_inst0.O, Top.O) | ||
EndCircuit()\ | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters