Commit 67c0d22a by Zachary Snow

handle functions with unpacked return typenames

parent 8a554113
......@@ -477,8 +477,12 @@ scopeModuleItemT declMapper moduleItemMapper genItemMapper stmtMapper =
redirectTFDecl :: Type -> Identifier -> ScoperT a m (Type, Identifier)
redirectTFDecl typ ident = do
res <- declMapper $ Variable Local typ ident [] Nil
let Variable Local newType newName [] Nil = res
return (newType, newName)
let Variable Local newType newName newRanges Nil = res
return $ if null newRanges
then (newType, newName)
else
let (tf, rs2) = typeRanges newType
in (tf $ newRanges ++ rs2, newName)
wrappedModuleItemMapper :: ModuleItem -> ScoperT a m ModuleItem
wrappedModuleItemMapper item = do
......
module mod(
input logic clk,
input byte row, col,
output logic [47:0] flat
);
typedef byte T [2][3];
function automatic T f;
input T inp;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 3; j++)
f[i][j] = (i + 1) * (j + 1) * inp[i][j];
endfunction
byte arr [2][3];
byte res [2][3];
assign flat =
{ res[1][2], res[1][1], res[1][0]
, res[0][2], res[0][1], res[0][0] };
initial
{ arr[1][2], arr[1][1], arr[1][0]
, arr[0][2], arr[0][1], arr[0][0] } = 0;
always @(posedge clk) begin
arr[row][col] += 1;
res = f(arr);
end
endmodule
`define IDX(a, r, c) a[(r * 3 + c) * 8 +: 8]
module mod(
input clk,
input [7:0] row, col,
output [47:0] flat
);
function automatic [47:0] f;
input [47:0] inp;
integer i, j;
for (i = 0; i < 2; i = i + 1)
for (j = 0; j < 3; j = j + 1)
`IDX(f, i, j) = (i + 1) * (j + 1) * `IDX(inp, i, j);
endfunction
reg [47:0] arr;
reg [47:0] res;
assign flat = res;
initial arr = 0;
always @(posedge clk) begin
`IDX(arr, row, col) = `IDX(arr, row, col) + 1;
res = f(arr);
end
endmodule
module top;
reg clk;
initial begin
clk = 0;
forever
#1 clk = ~clk;
end
reg [7:0] row, col;
wire [47:0] flat;
mod m(clk, row, col, flat);
integer i, j;
initial begin
$monitor("%3d %0d %0d %b", $time, row, col, flat);
repeat (10)
for (row = 0; row < 2; row = row + 1)
for (col = 0; col < 3; col = col + 1)
#2;
$finish;
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