mirror of https://github.com/zachjs/sv2v.git
cast function generated output stability
- cast functions in separate scopes are no longer omitted or removed - package item reordering excludes locally declared names - test runner ensures output is stable after first iteration
This commit is contained in:
parent
b28a3cac0d
commit
8c967ea9c7
|
|
@ -442,10 +442,36 @@ addUsedPIs :: ModuleItem -> (ModuleItem, Idents)
|
|||
addUsedPIs item =
|
||||
(item, usedPIs)
|
||||
where
|
||||
usedPIs = execWriter $
|
||||
traverseNestedModuleItemsM (traverseIdentsM writeIdent) item
|
||||
writeIdent :: Identifier -> Writer Idents Identifier
|
||||
writeIdent x = tell (Set.singleton x) >> return x
|
||||
usedPIs = execWriter $ evalScoperT
|
||||
writeDeclIdents writeModuleItemIdents writeGenItemIdents writeStmtIdents
|
||||
"" [item]
|
||||
|
||||
type IdentWriter = ScoperT () (Writer Idents)
|
||||
|
||||
writeDeclIdents :: Decl -> IdentWriter Decl
|
||||
writeDeclIdents decl = do
|
||||
case decl of
|
||||
Variable _ _ x _ _ -> insertElem x ()
|
||||
Param _ _ x _ -> insertElem x ()
|
||||
ParamType _ x _ -> insertElem x ()
|
||||
CommentDecl{} -> return ()
|
||||
traverseDeclIdentsM writeIdent decl
|
||||
|
||||
writeModuleItemIdents :: ModuleItem -> IdentWriter ModuleItem
|
||||
writeModuleItemIdents = traverseIdentsM writeIdent
|
||||
|
||||
writeGenItemIdents :: GenItem -> IdentWriter GenItem
|
||||
writeGenItemIdents =
|
||||
traverseGenItemExprsM $ traverseExprIdentsM writeIdent
|
||||
|
||||
writeStmtIdents :: Stmt -> IdentWriter Stmt
|
||||
writeStmtIdents = traverseStmtIdentsM writeIdent
|
||||
|
||||
writeIdent :: Identifier -> IdentWriter Identifier
|
||||
writeIdent x = do
|
||||
details <- lookupElemM x
|
||||
when (details == Nothing) $ tell (Set.singleton x)
|
||||
return x
|
||||
|
||||
-- visits all identifiers in a module item
|
||||
traverseIdentsM :: Monad m => MapperM m Identifier -> MapperM m ModuleItem
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ traverseDeclM :: Decl -> Scoper Type Decl
|
|||
traverseDeclM decl = do
|
||||
decl' <- case decl of
|
||||
Variable _ t x _ _ -> do
|
||||
details <- lookupElemM x
|
||||
details <- lookupLocalIdentM x
|
||||
if isPrefixOf "sv2v_cast_" x && details /= Nothing
|
||||
then return $ Variable Local t DuplicateTag [] Nil
|
||||
else insertElem x t >> return decl
|
||||
|
|
@ -122,7 +122,7 @@ traverseExprM =
|
|||
return $ Number $ Decimal (fromIntegral size) True val'
|
||||
where val' = val `mod` (2 ^ size)
|
||||
convertCastWithSigningM s e sg = do
|
||||
details <- lookupElemM $ castFnName s sg
|
||||
details <- lookupLocalIdentM $ castFnName s sg
|
||||
when (details == Nothing) $ injectItem $ MIPackageItem $ castFn s sg
|
||||
let f = castFnName s sg
|
||||
let args = Args [e] []
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
module top;
|
||||
parameter CONST = 1;
|
||||
localparam WIDTH = CONST * 2;
|
||||
localparam VALUE = WIDTH'(1'sb1);
|
||||
initial $display("%b", VALUE);
|
||||
if (1) begin : blk2
|
||||
localparam WIDTH = CONST * 3;
|
||||
localparam VALUE = WIDTH'(1'sb1);
|
||||
initial $display("%b", VALUE);
|
||||
end
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
module top;
|
||||
initial $display("%b", 2'b11);
|
||||
generate
|
||||
if (1) begin : blk2
|
||||
initial $display("%b", 3'b111);
|
||||
end
|
||||
endgenerate
|
||||
endmodule
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
module top;
|
||||
parameter YES = 1;
|
||||
if (YES) begin
|
||||
function automatic [31:0] help;
|
||||
input [31:0] inp;
|
||||
help = inp + 1;
|
||||
endfunction
|
||||
initial $display("A %0d", help(0));
|
||||
end
|
||||
function automatic [31:0] help;
|
||||
input [31:0] inp;
|
||||
help = inp + 2;
|
||||
endfunction
|
||||
initial $display("B %0d", help(0));
|
||||
endmodule
|
||||
|
|
@ -51,13 +51,8 @@ assertConverts() {
|
|||
ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v
|
||||
$SV2V $ac_tmpa 2> /dev/null > $ac_tmpb
|
||||
assertTrue "2nd conversion of $ac_file failed" $?
|
||||
if [ -n "$(diff $ac_tmpa $ac_tmpb)" ]; then
|
||||
ac_tmpc=$SHUNIT_TMPDIR/ac-conv-tmpc.v
|
||||
$SV2V $ac_tmpb 2> /dev/null > $ac_tmpc
|
||||
assertTrue "3rd conversion of $ac_file failed" $?
|
||||
diff $ac_tmpb $ac_tmpc > /dev/null
|
||||
assertTrue "conversion of $ac_file not stable after the second iteration" $?
|
||||
fi
|
||||
diff $ac_tmpa $ac_tmpb > /dev/null
|
||||
assertTrue "conversion of $ac_file not stable after the first iteration" $?
|
||||
$SV2V -v $ac_file 2> /dev/null > /dev/null
|
||||
assertTrue "verbose conversion of $ac_file failed" $?
|
||||
# using sed to remove quoted strings
|
||||
|
|
|
|||
Loading…
Reference in New Issue