mirror of https://github.com/zachjs/sv2v.git
support converting interfaces with parameters
This commit is contained in:
parent
5843ef3879
commit
06411d70f1
|
|
@ -86,9 +86,8 @@ Other:
|
||||||
## Supported Features
|
## Supported Features
|
||||||
|
|
||||||
sv2v supports most synthesizable SystemVerilog features. Current notable
|
sv2v supports most synthesizable SystemVerilog features. Current notable
|
||||||
exceptions include `export`, interfaces _with parameter bindings_, and complex
|
exceptions include `export` and complex (non-identifier) `modport` expressions.
|
||||||
(non-identifier) `modport` expressions. Assertions are also supported, but are
|
Assertions are also supported, but are simply dropped during conversion.
|
||||||
simply dropped during conversion.
|
|
||||||
|
|
||||||
If you find a bug or have a feature request, please create an issue. Preference
|
If you find a bug or have a feature request, please create an issue. Preference
|
||||||
will be given to issues which include examples or test cases.
|
will be given to issues which include examples or test cases.
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,8 @@ convertDescription interfaces modules (Part attrs extern Module lifetime name po
|
||||||
mapInterface (Instance part params ident Nothing instancePorts) =
|
mapInterface (Instance part params ident Nothing instancePorts) =
|
||||||
case Map.lookup part interfaces of
|
case Map.lookup part interfaces of
|
||||||
Just interface ->
|
Just interface ->
|
||||||
-- TODO: Add support for interfaces with parameter bindings.
|
Generate $ map GenModuleItem $
|
||||||
if not $ null params
|
inlineInterface interface (ident, params, expandedPorts)
|
||||||
then error $ "interface instantiations with parameter "
|
|
||||||
++ "bindings are not yet supported: "
|
|
||||||
++ show (part, params, ident)
|
|
||||||
else Generate $ map GenModuleItem $
|
|
||||||
inlineInterface interface (ident, expandedPorts)
|
|
||||||
Nothing -> Instance part params ident Nothing expandedPorts
|
Nothing -> Instance part params ident Nothing expandedPorts
|
||||||
where expandedPorts = concatMap (expandPortBinding part) instancePorts
|
where expandedPorts = concatMap (expandPortBinding part) instancePorts
|
||||||
mapInterface (orig @ (MIPackageItem (Function _ _ _ decls _))) =
|
mapInterface (orig @ (MIPackageItem (Function _ _ _ decls _))) =
|
||||||
|
|
@ -234,8 +229,8 @@ lookupType _ expr =
|
||||||
++ " are not identifiers: " ++ show expr
|
++ " are not identifiers: " ++ show expr
|
||||||
|
|
||||||
-- convert an interface instantiation into a series of equivalent module items
|
-- convert an interface instantiation into a series of equivalent module items
|
||||||
inlineInterface :: Interface -> (Identifier, [PortBinding]) -> [ModuleItem]
|
inlineInterface :: Interface -> (Identifier, [ParamBinding], [PortBinding]) -> [ModuleItem]
|
||||||
inlineInterface (ports, items) (instanceName, instancePorts) =
|
inlineInterface (ports, items) (instanceName, instanceParams, instancePorts) =
|
||||||
(:) (MIPackageItem $ Comment $ "expanded instance: " ++ instanceName) $
|
(:) (MIPackageItem $ Comment $ "expanded instance: " ++ instanceName) $
|
||||||
flip (++) portBindings $
|
flip (++) portBindings $
|
||||||
map (traverseNestedModuleItems removeModport) $
|
map (traverseNestedModuleItems removeModport) $
|
||||||
|
|
@ -243,7 +238,10 @@ inlineInterface (ports, items) (instanceName, instancePorts) =
|
||||||
itemsPrefixed
|
itemsPrefixed
|
||||||
where
|
where
|
||||||
prefix = instanceName ++ "_"
|
prefix = instanceName ++ "_"
|
||||||
itemsPrefixed = map (prefixModuleItems prefix) $ items
|
itemsPrefixed =
|
||||||
|
map (prefixModuleItems prefix) $
|
||||||
|
map (traverseDecls overrideParam) $
|
||||||
|
items
|
||||||
origInstancePortNames = map fst instancePorts
|
origInstancePortNames = map fst instancePorts
|
||||||
instancePortExprs = map snd instancePorts
|
instancePortExprs = map snd instancePorts
|
||||||
instancePortNames =
|
instancePortNames =
|
||||||
|
|
@ -264,6 +262,24 @@ inlineInterface (ports, items) (instanceName, instancePorts) =
|
||||||
MIPackageItem $ Comment $ "removed modport " ++ x
|
MIPackageItem $ Comment $ "removed modport " ++ x
|
||||||
removeModport other = other
|
removeModport other = other
|
||||||
|
|
||||||
|
instanceParamMap = Map.fromList instanceParams
|
||||||
|
overrideParam :: Decl -> Decl
|
||||||
|
overrideParam (Param Parameter t x e) =
|
||||||
|
case Map.lookup x instanceParamMap of
|
||||||
|
Nothing -> Param Parameter t x e
|
||||||
|
Just (Right e') -> Param Parameter t x e'
|
||||||
|
Just (Left t') ->
|
||||||
|
error $ "interface param expected expression, found type: "
|
||||||
|
++ show t'
|
||||||
|
overrideParam (ParamType Parameter x mt) =
|
||||||
|
case Map.lookup x instanceParamMap of
|
||||||
|
Nothing -> ParamType Parameter x mt
|
||||||
|
Just (Left t') -> ParamType Parameter x (Just t')
|
||||||
|
Just (Right e') ->
|
||||||
|
error $ "interface param expected type, found expression: "
|
||||||
|
++ show e'
|
||||||
|
overrideParam other = other
|
||||||
|
|
||||||
portBindingItem :: PortBinding -> Maybe ModuleItem
|
portBindingItem :: PortBinding -> Maybe ModuleItem
|
||||||
portBindingItem (ident, Just expr) =
|
portBindingItem (ident, Just expr) =
|
||||||
Just $ if declDirs Map.! ident == Input
|
Just $ if declDirs Map.! ident == Input
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,16 @@
|
||||||
interface Foo;
|
interface Foo;
|
||||||
function bar;
|
parameter MULTIPLIER = 7;
|
||||||
|
function integer bar;
|
||||||
input integer x;
|
input integer x;
|
||||||
return x * x;
|
return x * x * MULTIPLIER;
|
||||||
endfunction
|
endfunction
|
||||||
endinterface
|
endinterface
|
||||||
|
|
||||||
module top;
|
module top;
|
||||||
Foo foo();
|
Foo foo_1();
|
||||||
initial $display(foo.bar(3));
|
Foo #(.MULTIPLIER(8)) foo_2();
|
||||||
|
initial begin
|
||||||
|
$display(foo_1.bar(3));
|
||||||
|
$display(foo_2.bar(3));
|
||||||
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,16 @@
|
||||||
module top;
|
module top;
|
||||||
function bar;
|
localparam MULTIPLIER_1 = 7;
|
||||||
|
localparam MULTIPLIER_2 = 8;
|
||||||
|
function integer bar_1;
|
||||||
input integer x;
|
input integer x;
|
||||||
bar = x * x;
|
bar_1 = x * x * MULTIPLIER_1;
|
||||||
endfunction
|
endfunction
|
||||||
initial $display(bar(3));
|
function integer bar_2;
|
||||||
|
input integer x;
|
||||||
|
bar_2 = x * x * MULTIPLIER_2;
|
||||||
|
endfunction
|
||||||
|
initial begin
|
||||||
|
$display(bar_1(3));
|
||||||
|
$display(bar_2(3));
|
||||||
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue