Commit 756dbbb8 by Zachary Snow

support stream within mux

parent 81d82256
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* Added support for attributes in unary, binary, and ternary expressions * Added support for attributes in unary, binary, and ternary expressions
* Added support for shadowing interface names with local typenames * Added support for shadowing interface names with local typenames
* Added support for streaming concatenations within ternary expressions
* Added support for passing through `wait` statements * Added support for passing through `wait` statements
### Bug Fixes ### Bug Fixes
......
...@@ -47,7 +47,7 @@ traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem ...@@ -47,7 +47,7 @@ traverseModuleItemM :: ModuleItem -> Scoper () ModuleItem
traverseModuleItemM (Assign opt lhs (Stream StreamL chunk exprs)) = traverseModuleItemM (Assign opt lhs (Stream StreamL chunk exprs)) =
injectItem (MIPackageItem func) >> return (Assign opt lhs expr') injectItem (MIPackageItem func) >> return (Assign opt lhs expr')
where where
fnName = streamerFuncName $ shortHash lhs fnName = streamerFuncName $ shortHash (lhs, chunk, exprs)
t = TypeOf $ lhsToExpr lhs t = TypeOf $ lhsToExpr lhs
arg = Concat exprs arg = Concat exprs
func = streamerFunc fnName chunk (TypeOf arg) t func = streamerFunc fnName chunk (TypeOf arg) t
...@@ -56,12 +56,25 @@ traverseModuleItemM (Assign opt (LHSStream StreamL chunk lhss) expr) = ...@@ -56,12 +56,25 @@ traverseModuleItemM (Assign opt (LHSStream StreamL chunk lhss) expr) =
traverseModuleItemM $ traverseModuleItemM $
Assign opt (LHSConcat lhss) Assign opt (LHSConcat lhss)
(Stream StreamL chunk [expr]) (Stream StreamL chunk [expr])
traverseModuleItemM (Assign opt lhs (Mux cond expr@Stream{} other)) = do
(lhs', expr') <- indirectAssign lhs expr
return $ Assign opt lhs' $ Mux cond expr' other
traverseModuleItemM (Assign opt lhs (Mux cond other expr@Stream{})) = do
(lhs', expr') <- indirectAssign lhs expr
return $ Assign opt lhs' $ Mux cond other expr'
traverseModuleItemM (Assign opt lhs expr) = traverseModuleItemM (Assign opt lhs expr) =
traverseExprM expr' >>= return . Assign opt lhs' traverseExprM expr' >>= return . Assign opt lhs'
where Asgn AsgnOpEq Nothing lhs' expr' = where Asgn AsgnOpEq Nothing lhs' expr' =
traverseAsgn (lhs, expr) (Asgn AsgnOpEq Nothing) traverseAsgn (lhs, expr) (Asgn AsgnOpEq Nothing)
traverseModuleItemM item = return item traverseModuleItemM item = return item
indirectAssign :: LHS -> Expr -> Scoper () (LHS, Expr)
indirectAssign lhs expr = do
let item = Assign AssignOptionNone lhs expr
item' <- traverseModuleItemM item
let Assign AssignOptionNone lhs' expr' = item'
return (lhs', expr')
traverseStmtM :: Stmt -> Scoper () Stmt traverseStmtM :: Stmt -> Scoper () Stmt
traverseStmtM (Subroutine fn (Args args [])) = do traverseStmtM (Subroutine fn (Args args [])) = do
args' <- traverseCall fn args args' <- traverseCall fn args
...@@ -190,6 +203,12 @@ traverseAsgn (LHSStream StreamL chunk lhss, expr) constructor = ...@@ -190,6 +203,12 @@ traverseAsgn (LHSStream StreamL chunk lhss, expr) constructor =
lhs = LHSConcat lhss lhs = LHSConcat lhss
lhsSize = sizeof $ lhsToExpr lhs lhsSize = sizeof $ lhsToExpr lhs
exprSize = sizeof expr exprSize = sizeof expr
traverseAsgn (lhs, Mux cond e1@Stream{} e2) constructor =
traverseAsgn (lhs, e1) constructor'
where constructor' lhs' e1' = constructor lhs' $ Mux cond e1' e2
traverseAsgn (lhs, Mux cond e1 e2@Stream{}) constructor =
traverseAsgn (lhs, e2) constructor'
where constructor' lhs' e2' = constructor lhs' $ Mux cond e1 e2'
traverseAsgn (lhs, expr) constructor = traverseAsgn (lhs, expr) constructor =
constructor lhs expr constructor lhs expr
......
...@@ -124,4 +124,15 @@ module top; ...@@ -124,4 +124,15 @@ module top;
#1 in = 24'h12E3B8; #1 in = 24'h12E3B8;
end end
logic [31:0] mux1, mux2, mux3, mux4, mux5, mux6;
initial $monitor("%b %b %b %b %b %b", mux1, mux2, mux3, mux4, mux5, mux6);
assign mux1 = i ? {<<1 {in}} : 32'b0;
assign mux2 = i ? {>>1 {in}} : {<<1 {in}};
assign mux3 = i ? {<<1 {in}} : {<<1 {m}};
always @* begin
mux4 = i ? {<<1 {in}} : 32'b0;
mux5 = i ? {>>1 {in}} : {<<1 {in}};
mux6 = i ? {<<1 {in}} : {<<1 {m}};
end
endmodule endmodule
...@@ -141,4 +141,23 @@ module top; ...@@ -141,4 +141,23 @@ module top;
#1 in = 24'h12E3B8; #1 in = 24'h12E3B8;
end end
function automatic [31:0] reverse;
input [31:0] inp;
integer i;
for (i = 0; i < 32; i = i + 1)
reverse[i] = inp[31 - i];
endfunction
wire [31:0] mux1, mux2, mux3;
reg [31:0] mux4, mux5, mux6;
initial $monitor("%b %b %b %b %b %b", mux1, mux2, mux3, mux4, mux5, mux6);
assign mux1 = i ? reverse(in) : 32'b0;
assign mux2 = i ? in << 8 : reverse(in);
assign mux3 = i ? reverse(in) : reverse(m);
always @* begin
mux4 = i ? reverse(in) : 32'b0;
mux5 = i ? in << 8 : reverse(in);
mux6 = i ? reverse(in) : reverse(m);
end
endmodule endmodule
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment