mirror of https://github.com/zachjs/sv2v.git
keyword args conversion covers tasks
This commit is contained in:
parent
14644cd1ed
commit
2f8ee303de
|
|
@ -24,11 +24,13 @@ convert = map $ traverseDescriptions convertDescription
|
||||||
|
|
||||||
convertDescription :: Description -> Description
|
convertDescription :: Description -> Description
|
||||||
convertDescription description =
|
convertDescription description =
|
||||||
traverseModuleItems
|
traverseModuleItems (convertModuleItem tfs) description
|
||||||
(traverseExprs $ traverseNestedExprs $ convertExpr tfs)
|
where tfs = execWriter $ collectModuleItemsM collectTF description
|
||||||
description
|
|
||||||
where
|
convertModuleItem :: TFs -> ModuleItem -> ModuleItem
|
||||||
tfs = execWriter $ collectModuleItemsM collectTF description
|
convertModuleItem tfs =
|
||||||
|
(traverseExprs $ traverseNestedExprs $ convertExpr tfs) .
|
||||||
|
(traverseStmts $ convertStmt tfs)
|
||||||
|
|
||||||
collectTF :: ModuleItem -> Writer TFs ()
|
collectTF :: ModuleItem -> Writer TFs ()
|
||||||
collectTF (MIPackageItem (Function _ _ f decls _)) = collectTFDecls f decls
|
collectTF (MIPackageItem (Function _ _ f decls _)) = collectTFDecls f decls
|
||||||
|
|
@ -44,12 +46,22 @@ collectTFDecls name decls =
|
||||||
getInput _ = Nothing
|
getInput _ = Nothing
|
||||||
|
|
||||||
convertExpr :: TFs -> Expr -> Expr
|
convertExpr :: TFs -> Expr -> Expr
|
||||||
convertExpr _ (orig @ (Call _ (Args _ []))) = orig
|
convertExpr tfs (Call expr args) =
|
||||||
convertExpr tfs (Call (Ident func) (Args pnArgs kwArgs)) =
|
convertInvoke tfs Call expr args
|
||||||
|
convertExpr _ other = other
|
||||||
|
|
||||||
|
convertStmt :: TFs -> Stmt -> Stmt
|
||||||
|
convertStmt tfs (Subroutine expr args) =
|
||||||
|
convertInvoke tfs Subroutine expr args
|
||||||
|
convertStmt _ other = other
|
||||||
|
|
||||||
|
convertInvoke :: TFs -> (Expr -> Args -> a) -> Expr -> Args -> a
|
||||||
|
convertInvoke tfs constructor (Ident func) (Args pnArgs (kwArgs @ (_ : _))) =
|
||||||
case tfs Map.!? func of
|
case tfs Map.!? func of
|
||||||
Nothing -> Call (Ident func) (Args pnArgs kwArgs)
|
Nothing -> constructor (Ident func) (Args pnArgs kwArgs)
|
||||||
Just ordered -> Call (Ident func) (Args args [])
|
Just ordered -> constructor (Ident func) (Args args [])
|
||||||
where
|
where
|
||||||
args = pnArgs ++ (map snd $ sortOn position kwArgs)
|
args = pnArgs ++ (map snd $ sortOn position kwArgs)
|
||||||
position (x, _) = elemIndex x ordered
|
position (x, _) = elemIndex x ordered
|
||||||
convertExpr _ other = other
|
convertInvoke _ constructor expr args =
|
||||||
|
constructor expr args
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
module top;
|
||||||
|
function f;
|
||||||
|
input integer z;
|
||||||
|
input integer a;
|
||||||
|
$display(z, a);
|
||||||
|
return z + a;
|
||||||
|
endfunction
|
||||||
|
task t;
|
||||||
|
input integer z;
|
||||||
|
input integer a;
|
||||||
|
$display(z, a);
|
||||||
|
endtask
|
||||||
|
initial begin
|
||||||
|
$display(f(.a(3), .z(7)));
|
||||||
|
t(.a(5), .z(9));
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
module top;
|
||||||
|
function f;
|
||||||
|
input integer z;
|
||||||
|
input integer a;
|
||||||
|
begin
|
||||||
|
$display(z, a);
|
||||||
|
f = z + a;
|
||||||
|
end
|
||||||
|
endfunction
|
||||||
|
task t;
|
||||||
|
input integer z;
|
||||||
|
input integer a;
|
||||||
|
$display(z, a);
|
||||||
|
endtask
|
||||||
|
initial begin
|
||||||
|
$display(f(7, 3));
|
||||||
|
t(9, 5);
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue