Commit db21869e by Zachary Snow

fix premature conversion of casts containing dimension queries

parent d46e1f24
...@@ -84,8 +84,6 @@ traverseExprM = ...@@ -84,8 +84,6 @@ traverseExprM =
sizesMatch = numberToInteger s == Just (numberBitLength n) sizesMatch = numberToInteger s == Just (numberBitLength n)
fallback = convertCastM (Number s) (Number n) fallback = convertCastM (Number s) (Number n)
num = return . Number num = return . Number
convertExprM (orig @ (Cast (Right DimsFn{}) _)) =
return orig
convertExprM (Cast (Right (Ident x)) e) = do convertExprM (Cast (Right (Ident x)) e) = do
typeMap <- get typeMap <- get
-- can't convert this cast yet because x could be a typename -- can't convert this cast yet because x could be a typename
...@@ -93,7 +91,9 @@ traverseExprM = ...@@ -93,7 +91,9 @@ traverseExprM =
then return $ Cast (Right $ Ident x) e then return $ Cast (Right $ Ident x) e
else convertCastM (Ident x) e else convertCastM (Ident x) e
convertExprM (Cast (Right s) e) = convertExprM (Cast (Right s) e) =
convertCastM s e if isSimpleExpr s
then convertCastM s e
else return $ Cast (Right s) e
convertExprM (Cast (Left (IntegerVector _ Signed rs)) e) = convertExprM (Cast (Left (IntegerVector _ Signed rs)) e) =
convertCastWithSigningM (dimensionsSize rs) e Signed convertCastWithSigningM (dimensionsSize rs) e Signed
convertExprM (Cast (Left (IntegerVector _ _ rs)) e) = convertExprM (Cast (Left (IntegerVector _ _ rs)) e) =
...@@ -121,6 +121,17 @@ traverseExprM = ...@@ -121,6 +121,17 @@ traverseExprM =
let args = Args [e] [] let args = Args [e] []
return $ Call (Ident f) args return $ Call (Ident f) args
isSimpleExpr :: Expr -> Bool
isSimpleExpr =
null . execWriter . collectNestedExprsM collectUnresolvedExprM
where
collectUnresolvedExprM :: Expr -> Writer [Expr] ()
collectUnresolvedExprM (expr @ PSIdent{}) = tell [expr]
collectUnresolvedExprM (expr @ CSIdent{}) = tell [expr]
collectUnresolvedExprM (expr @ DimsFn{}) = tell [expr]
collectUnresolvedExprM (expr @ DimFn {}) = tell [expr]
collectUnresolvedExprM _ = return ()
castFn :: Expr -> Signing -> Description castFn :: Expr -> Signing -> Description
castFn e sg = castFn e sg =
PackageItem $ PackageItem $
......
package P;
function automatic logic [7:0] f(input logic [2:0] p);
logic [7:0] r;
r = '0;
r[p+:2] = '1;
return r;
endfunction
endpackage
module top;
logic [2:0] p;
logic [7:0] q;
assign q = P::f(p);
initial begin
$monitor("%0d, p=%b q=%b", $time, p, q);
#1 p = 0;
while (p != 7)
#1 p = p + 1;
end
endmodule
module top;
function automatic [7:0] f;
input [2:0] p;
begin
f = 7'b0;
f[p+:2] = 2'b11;
end
endfunction
reg [2:0] p;
wire [7:0] q;
assign q = f(p);
initial begin
$monitor("%0d, p=%b q=%b", $time, p, q);
#1 p = 0;
while (p != 7)
#1 p = p + 1;
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