Commit 5b063ec9 by Zachary Snow

pack task and function arguments

parent 2f712842
......@@ -37,13 +37,14 @@ convertDescription other = other
-- tracks multi-dimensional unpacked array declarations
traverseDeclM :: [Identifier] -> Decl -> ST Decl
traverseDeclM _ (decl @ (Variable _ _ _ [] _)) = return decl
traverseDeclM ports (decl @ (Variable _ _ x _ e)) = do
traverseDeclM _ (decl @ (Variable _ _ _ [] e)) =
traverseExprArgsM e >> return decl
traverseDeclM ports (decl @ (Variable dir _ x _ e)) = do
insertElem x decl
if elem x ports || e /= Nil
if dir /= Local || elem x ports || e /= Nil
then flatUsageM x
else return ()
return decl
traverseExprArgsM e >> return decl
traverseDeclM ports decl @ Net{} =
traverseNetAsVarM (traverseDeclM ports) decl
traverseDeclM _ other = return other
......@@ -89,12 +90,24 @@ traverseStmtM :: Stmt -> ST Stmt
traverseStmtM =
traverseStmtLHSsM traverseLHSM >=>
traverseStmtExprsM traverseExprM >=>
traverseStmtAsgnsM traverseAsgnM
traverseStmtAsgnsM traverseAsgnM >=>
traverseStmtArgsM
traverseStmtArgsM :: Stmt -> ST Stmt
traverseStmtArgsM stmt @ (Subroutine _ (Args args [])) =
mapM_ flatUsageM args >> return stmt
traverseStmtArgsM stmt = return stmt
traverseExprM :: Expr -> ST Expr
traverseExprM (Range x mode i) =
flatUsageM x >> return (Range x mode i)
traverseExprM other = return other
traverseExprM expr = traverseExprArgsM expr
traverseExprArgsM :: Expr -> ST Expr
traverseExprArgsM expr @ (Call _ (Args args [])) =
mapM_ (traverseExprArgsM >> flatUsageM) args >> return expr
traverseExprArgsM expr =
traverseSinglyNestedExprsM traverseExprArgsM expr
traverseLHSM :: LHS -> ST LHS
traverseLHSM x = flatUsageM x >> return x
......
module top;
function automatic [31:0] flatten;
input byte inp [4];
return {inp[0], inp[1], inp[2], inp[3]};
endfunction
task dump;
input byte inp [4];
$display("t(%b)", {inp[0], inp[1], inp[2], inp[3]});
endtask
byte arr1 [4];
byte arr2 [4];
wire integer unsigned flat = flatten(arr1) | 1'b1;
initial begin
#1 arr1[0] = 1;
#1 arr1[1] = 3;
#1 arr1[2] = 9;
#1 arr1[3] = 7;
#1 arr2[0] = 1; dump(arr2);
#1 arr2[1] = 3; dump(arr2);
#1 arr2[2] = 9; dump(arr2);
#1 arr2[3] = 7; dump(arr2);
end
endmodule
module top;
function automatic [31:0] flatten;
input [0:3][7:0] inp;
flatten = {inp[0], inp[1], inp[2], inp[3]};
endfunction
task dump;
input [0:3][7:0] inp;
$display("t(%b)", {inp[0], inp[1], inp[2], inp[3]});
endtask
reg [0:3][7:0] arr1, arr2;
wire [31:0] flat = flatten(arr1) | 1'b1;
initial begin
#1 arr1[0] = 1;
#1 arr1[1] = 3;
#1 arr1[2] = 9;
#1 arr1[3] = 7;
#1 arr2[0] = 1; dump(arr2);
#1 arr2[1] = 3; dump(arr2);
#1 arr2[2] = 9; dump(arr2);
#1 arr2[3] = 7; dump(arr2);
end
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