Commit 8c967ea9 by Zachary Snow

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
parent b28a3cac
...@@ -442,10 +442,36 @@ addUsedPIs :: ModuleItem -> (ModuleItem, Idents) ...@@ -442,10 +442,36 @@ addUsedPIs :: ModuleItem -> (ModuleItem, Idents)
addUsedPIs item = addUsedPIs item =
(item, usedPIs) (item, usedPIs)
where where
usedPIs = execWriter $ usedPIs = execWriter $ evalScoperT
traverseNestedModuleItemsM (traverseIdentsM writeIdent) item writeDeclIdents writeModuleItemIdents writeGenItemIdents writeStmtIdents
writeIdent :: Identifier -> Writer Idents Identifier "" [item]
writeIdent x = tell (Set.singleton x) >> return x
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 -- visits all identifiers in a module item
traverseIdentsM :: Monad m => MapperM m Identifier -> MapperM m ModuleItem traverseIdentsM :: Monad m => MapperM m Identifier -> MapperM m ModuleItem
......
...@@ -27,7 +27,7 @@ traverseDeclM :: Decl -> Scoper Type Decl ...@@ -27,7 +27,7 @@ traverseDeclM :: Decl -> Scoper Type Decl
traverseDeclM decl = do traverseDeclM decl = do
decl' <- case decl of decl' <- case decl of
Variable _ t x _ _ -> do Variable _ t x _ _ -> do
details <- lookupElemM x details <- lookupLocalIdentM x
if isPrefixOf "sv2v_cast_" x && details /= Nothing if isPrefixOf "sv2v_cast_" x && details /= Nothing
then return $ Variable Local t DuplicateTag [] Nil then return $ Variable Local t DuplicateTag [] Nil
else insertElem x t >> return decl else insertElem x t >> return decl
...@@ -122,7 +122,7 @@ traverseExprM = ...@@ -122,7 +122,7 @@ traverseExprM =
return $ Number $ Decimal (fromIntegral size) True val' return $ Number $ Decimal (fromIntegral size) True val'
where val' = val `mod` (2 ^ size) where val' = val `mod` (2 ^ size)
convertCastWithSigningM s e sg = do convertCastWithSigningM s e sg = do
details <- lookupElemM $ castFnName s sg details <- lookupLocalIdentM $ castFnName s sg
when (details == Nothing) $ injectItem $ MIPackageItem $ castFn s sg when (details == Nothing) $ injectItem $ MIPackageItem $ castFn s sg
let f = castFnName s sg let f = castFnName s sg
let args = Args [e] [] let args = Args [e] []
......
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
module top;
initial $display("%b", 2'b11);
generate
if (1) begin : blk2
initial $display("%b", 3'b111);
end
endgenerate
endmodule
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() { ...@@ -51,13 +51,8 @@ assertConverts() {
ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v
$SV2V $ac_tmpa 2> /dev/null > $ac_tmpb $SV2V $ac_tmpa 2> /dev/null > $ac_tmpb
assertTrue "2nd conversion of $ac_file failed" $? assertTrue "2nd conversion of $ac_file failed" $?
if [ -n "$(diff $ac_tmpa $ac_tmpb)" ]; then diff $ac_tmpa $ac_tmpb > /dev/null
ac_tmpc=$SHUNIT_TMPDIR/ac-conv-tmpc.v assertTrue "conversion of $ac_file not stable after the first iteration" $?
$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
$SV2V -v $ac_file 2> /dev/null > /dev/null $SV2V -v $ac_file 2> /dev/null > /dev/null
assertTrue "verbose conversion of $ac_file failed" $? assertTrue "verbose conversion of $ac_file failed" $?
# using sed to remove quoted strings # using sed to remove quoted strings
......
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