Commit 490d96ba by Zachary Snow

generate consistent hashes within interface conversion

parent dd1a9efb
...@@ -79,7 +79,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) = ...@@ -79,7 +79,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
-- inline instantiation of an interface -- inline instantiation of an interface
convertNested $ Generate $ map GenModuleItem $ convertNested $ Generate $ map GenModuleItem $
inlineInstance rs [] inlineInstance rs []
partItems instanceName paramBindings portBindings partItems part instanceName paramBindings portBindings
else if null modportInstances then else if null modportInstances then
return instanceItem return instanceItem
else do else do
...@@ -94,7 +94,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) = ...@@ -94,7 +94,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
++ showKeys modportBindings ++ " are connected" ++ showKeys modportBindings ++ " are connected"
else convertNested $ Generate $ map GenModuleItem $ else convertNested $ Generate $ map GenModuleItem $
inlineInstance rs modportBindings partItems inlineInstance rs modportBindings partItems
instanceName paramBindings portBindings part instanceName paramBindings portBindings
where where
Instance part rawParamBindings instanceName rs rawPortBindings = Instance part rawParamBindings instanceName rs rawPortBindings =
instanceItem instanceItem
...@@ -242,7 +242,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) = ...@@ -242,7 +242,7 @@ convertDescription parts (Part attrs extern Module lifetime name ports items) =
case Map.lookup x replacements of case Map.lookup x replacements of
Just replacement -> replacement Just replacement -> replacement
Nothing -> Nothing ->
if "_tmp_" `isPrefixOf` x if "_param_" `isPrefixOf` x
then Ident x then Ident x
else Dot instanceE x else Dot instanceE x
prefixExpr other = traverseSinglyNestedExprs prefixExpr other prefixExpr other = traverseSinglyNestedExprs prefixExpr other
...@@ -298,9 +298,9 @@ impliedModport = ...@@ -298,9 +298,9 @@ impliedModport =
-- convert an interface-bound module instantiation or an interface instantiation -- convert an interface-bound module instantiation or an interface instantiation
-- into a series of equivalent inlined module items -- into a series of equivalent inlined module items
inlineInstance :: [Range] -> [ModportBinding] -> [ModuleItem] inlineInstance :: [Range] -> [ModportBinding] -> [ModuleItem] -> Identifier
-> Identifier -> [ParamBinding] -> [PortBinding] -> [ModuleItem] -> Identifier -> [ParamBinding] -> [PortBinding] -> [ModuleItem]
inlineInstance ranges modportBindings items inlineInstance ranges modportBindings items partName
instanceName instanceParams instancePorts = instanceName instanceParams instancePorts =
comment : comment :
map (MIPackageItem . Decl) bindingBaseParams ++ map (MIPackageItem . Decl) bindingBaseParams ++
...@@ -315,6 +315,8 @@ inlineInstance ranges modportBindings items ...@@ -315,6 +315,8 @@ inlineInstance ranges modportBindings items
then dimensionModport : bundleModport : items then dimensionModport : bundleModport : items
else items else items
key = shortHash (partName, instanceName)
-- synthetic modports to be collected and removed after inlining -- synthetic modports to be collected and removed after inlining
bundleModport = Modport "" (impliedModport items) bundleModport = Modport "" (impliedModport items)
dimensionModport = if not isArray dimensionModport = if not isArray
...@@ -472,7 +474,7 @@ inlineInstance ranges modportBindings items ...@@ -472,7 +474,7 @@ inlineInstance ranges modportBindings items
case makeBindingBaseExpr modportE of case makeBindingBaseExpr modportE of
Just expr -> localparam (bindingBaseName ++ portName) expr Just expr -> localparam (bindingBaseName ++ portName) expr
Nothing -> CommentDecl "no-op" Nothing -> CommentDecl "no-op"
bindingBaseName = "_sv2v_bind_base_" ++ shortHash instanceName ++ "_" bindingBaseName = "_bbase_" ++ key ++ "_"
makeBindingBaseExpr :: Expr -> Maybe Expr makeBindingBaseExpr :: Expr -> Maybe Expr
makeBindingBaseExpr modportE = makeBindingBaseExpr modportE =
case modportE of case modportE of
...@@ -485,7 +487,7 @@ inlineInstance ranges modportBindings items ...@@ -485,7 +487,7 @@ inlineInstance ranges modportBindings items
localparam :: Identifier -> Expr -> Decl localparam :: Identifier -> Expr -> Decl
localparam = Param Localparam (Implicit Unspecified []) localparam = Param Localparam (Implicit Unspecified [])
paramTmp = "_tmp_" ++ (shortHash (items, instanceName)) ++ "_" paramTmp = "_param_" ++ key ++ "_"
parameterBinds = map makeParameterBind instanceParams parameterBinds = map makeParameterBind instanceParams
makeParameterBind :: ParamBinding -> Decl makeParameterBind :: ParamBinding -> Decl
...@@ -545,7 +547,7 @@ inlineInstance ranges modportBindings items ...@@ -545,7 +547,7 @@ inlineInstance ranges modportBindings items
++ " output to " ++ show expr ++ " but that can't be an LHS" ++ " output to " ++ show expr ++ " but that can't be an LHS"
-- for instance arrays, a unique identifier to be used as a genvar -- for instance arrays, a unique identifier to be used as a genvar
loopVar = "_sv2v_arr_" ++ shortHash (instanceName, ranges) loopVar = "_arr_" ++ key
isArray = not $ null ranges isArray = not $ null ranges
[arrayRange @ (arrayLeft, arrayRight)] = ranges [arrayRange @ (arrayLeft, arrayRight)] = ranges
...@@ -574,7 +576,7 @@ pattern Tag :: Expr ...@@ -574,7 +576,7 @@ pattern Tag :: Expr
pattern Tag = Ident "%" pattern Tag = Ident "%"
modportBaseName :: Identifier -> Identifier modportBaseName :: Identifier -> Identifier
modportBaseName = (++) "_sv2v_base_" modportBaseName = (++) "_mbase_"
-- the dimensions of interface instance arrays are encoded as synthetic modports -- the dimensions of interface instance arrays are encoded as synthetic modports
-- during inlining, enabling subsequent modport bindings to implicitly use the -- during inlining, enabling subsequent modport bindings to implicitly use the
......
interface Interface;
logic x;
endinterface
module ModuleC(Interface intf, input y);
initial $display("ModuleC %b %b", intf.x, y);
endmodule
module ModuleB(Interface intf, input y);
initial $display("ModuleB %b %b", intf.x, y);
ModuleC m[2:0] (intf, y);
endmodule
module ModuleA(Interface intf, input y);
initial $display("ModuleA %b %b", intf.x, y);
ModuleB m[2:0] (intf, y);
endmodule
module top;
logic y;
Interface intf();
ModuleA m[2:0] (intf, y);
endmodule
module top;
generate
if (1) begin : intf
wire x;
end
endgenerate
wire y;
genvar i, j, k;
generate
for (i = 2; i >= 0; i = i - 1) begin
initial $display("ModuleA %b %b", intf.x, y);
for (j = 2; j >= 0; j = j - 1) begin
initial $display("ModuleB %b %b", intf.x, y);
for (k = 2; k >= 0; k = k - 1) begin
initial $display("ModuleC %b %b", intf.x, y);
end
end
end
endgenerate
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