mirror of https://github.com/zachjs/sv2v.git
disambiguate struct names that shadow module names
This commit is contained in:
parent
7808819c48
commit
c56a91b290
|
|
@ -22,6 +22,7 @@
|
||||||
declarations tagged with an attribute
|
declarations tagged with an attribute
|
||||||
* Fixed stray attributes producing invalid nested output when attached to
|
* Fixed stray attributes producing invalid nested output when attached to
|
||||||
inlined interfaces and interface-bounds modules
|
inlined interfaces and interface-bounds modules
|
||||||
|
* Fixed conversion of struct variables that shadow their module's name
|
||||||
* Fixed `` `resetall `` not resetting the `` `default_nettype ``
|
* Fixed `` `resetall `` not resetting the `` `default_nettype ``
|
||||||
|
|
||||||
### Other Enhancements
|
### Other Enhancements
|
||||||
|
|
|
||||||
|
|
@ -380,7 +380,7 @@ convertLHS l = do
|
||||||
-- try expression conversion by looking at the *innermost* type first
|
-- try expression conversion by looking at the *innermost* type first
|
||||||
convertSubExpr :: Scopes Type -> Expr -> (Type, Expr)
|
convertSubExpr :: Scopes Type -> Expr -> (Type, Expr)
|
||||||
convertSubExpr scopes (Dot e x) =
|
convertSubExpr scopes (Dot e x) =
|
||||||
if isntStruct subExprType then
|
if isntStruct subExprType || isHier then
|
||||||
fallbackType scopes $ Dot e' x
|
fallbackType scopes $ Dot e' x
|
||||||
else if structIsntReady subExprType then
|
else if structIsntReady subExprType then
|
||||||
(fieldType, Dot e' x)
|
(fieldType, Dot e' x)
|
||||||
|
|
@ -388,7 +388,7 @@ convertSubExpr scopes (Dot e x) =
|
||||||
(fieldType, undottedWithSign)
|
(fieldType, undottedWithSign)
|
||||||
where
|
where
|
||||||
(subExprType, e') = convertSubExpr scopes e
|
(subExprType, e') = convertSubExpr scopes e
|
||||||
(fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
(isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
||||||
base = fst bounds
|
base = fst bounds
|
||||||
len = rangeSize bounds
|
len = rangeSize bounds
|
||||||
undotted = if null dims || rangeSize (head dims) == RawNum 1
|
undotted = if null dims || rangeSize (head dims) == RawNum 1
|
||||||
|
|
@ -403,7 +403,7 @@ convertSubExpr scopes (Dot e x) =
|
||||||
else undotted
|
else undotted
|
||||||
|
|
||||||
convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
|
convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
|
||||||
if isntStruct subExprType then
|
if isntStruct subExprType || isHier then
|
||||||
(UnknownType, orig')
|
(UnknownType, orig')
|
||||||
else if structIsntReady subExprType then
|
else if structIsntReady subExprType then
|
||||||
(replaceInnerTypeRange NonIndexed rOuter' fieldType, orig')
|
(replaceInnerTypeRange NonIndexed rOuter' fieldType, orig')
|
||||||
|
|
@ -420,7 +420,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
|
||||||
(_, roRight') = convertSubExpr scopes roRight
|
(_, roRight') = convertSubExpr scopes roRight
|
||||||
rOuter' = (roLeft', roRight')
|
rOuter' = (roLeft', roRight')
|
||||||
orig' = Range (Dot e' x) NonIndexed rOuter'
|
orig' = Range (Dot e' x) NonIndexed rOuter'
|
||||||
(fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
(isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
||||||
[dim] = dims
|
[dim] = dims
|
||||||
rangeLeft = ( BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roLeft'
|
rangeLeft = ( BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roLeft'
|
||||||
, BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roRight' )
|
, BinOp Sub (fst bounds) $ BinOp Sub (fst dim) roRight' )
|
||||||
|
|
@ -429,7 +429,7 @@ convertSubExpr scopes (Range (Dot e x) NonIndexed rOuter) =
|
||||||
undotted = Range e' NonIndexed $
|
undotted = Range e' NonIndexed $
|
||||||
endianCondRange dim rangeLeft rangeRight
|
endianCondRange dim rangeLeft rangeRight
|
||||||
convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
|
convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
|
||||||
if isntStruct subExprType then
|
if isntStruct subExprType || isHier then
|
||||||
(UnknownType, orig')
|
(UnknownType, orig')
|
||||||
else if structIsntReady subExprType then
|
else if structIsntReady subExprType then
|
||||||
(replaceInnerTypeRange mode (baseO', lenO') fieldType, orig')
|
(replaceInnerTypeRange mode (baseO', lenO') fieldType, orig')
|
||||||
|
|
@ -444,7 +444,7 @@ convertSubExpr scopes (Range (Dot e x) mode (baseO, lenO)) =
|
||||||
(_, baseO') = convertSubExpr scopes baseO
|
(_, baseO') = convertSubExpr scopes baseO
|
||||||
(_, lenO') = convertSubExpr scopes lenO
|
(_, lenO') = convertSubExpr scopes lenO
|
||||||
orig' = Range (Dot e' x) mode (baseO', lenO')
|
orig' = Range (Dot e' x) mode (baseO', lenO')
|
||||||
(fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
(isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
||||||
[dim] = dims
|
[dim] = dims
|
||||||
baseLeft = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) baseO'
|
baseLeft = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) baseO'
|
||||||
baseRight = BinOp Add (snd bounds) $ BinOp Sub (snd dim) baseO'
|
baseRight = BinOp Add (snd bounds) $ BinOp Sub (snd dim) baseO'
|
||||||
|
|
@ -463,7 +463,7 @@ convertSubExpr scopes (Range e mode (left, right)) =
|
||||||
(_, right') = convertSubExpr scopes right
|
(_, right') = convertSubExpr scopes right
|
||||||
r' = (left', right')
|
r' = (left', right')
|
||||||
convertSubExpr scopes (Bit (Dot e x) i) =
|
convertSubExpr scopes (Bit (Dot e x) i) =
|
||||||
if isntStruct subExprType then
|
if isntStruct subExprType || isHier then
|
||||||
(dropInnerTypeRange backupType, orig')
|
(dropInnerTypeRange backupType, orig')
|
||||||
else if structIsntReady subExprType then
|
else if structIsntReady subExprType then
|
||||||
(dropInnerTypeRange fieldType, orig')
|
(dropInnerTypeRange fieldType, orig')
|
||||||
|
|
@ -477,7 +477,7 @@ convertSubExpr scopes (Bit (Dot e x) i) =
|
||||||
(_, i') = convertSubExpr scopes i
|
(_, i') = convertSubExpr scopes i
|
||||||
(backupType, _) = fallbackType scopes $ Dot e' x
|
(backupType, _) = fallbackType scopes $ Dot e' x
|
||||||
orig' = Bit (Dot e' x) i'
|
orig' = Bit (Dot e' x) i'
|
||||||
(fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
(isHier, fieldType, bounds, dims) = lookupFieldInfo scopes subExprType e' x
|
||||||
[dim] = dims
|
[dim] = dims
|
||||||
left = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) i'
|
left = BinOp Sub (fst bounds) $ BinOp Sub (fst dim) i'
|
||||||
right = BinOp Add (snd bounds) $ BinOp Sub (snd dim) i'
|
right = BinOp Add (snd bounds) $ BinOp Sub (snd dim) i'
|
||||||
|
|
@ -536,13 +536,11 @@ isntStruct = (== Nothing) . getFields
|
||||||
|
|
||||||
-- get the field type, flattened bounds, and original type dimensions
|
-- get the field type, flattened bounds, and original type dimensions
|
||||||
lookupFieldInfo :: Scopes Type -> Type -> Expr -> Identifier
|
lookupFieldInfo :: Scopes Type -> Type -> Expr -> Identifier
|
||||||
-> (Type, Range, [Range])
|
-> (Bool, Type, Range, [Range])
|
||||||
lookupFieldInfo scopes struct base fieldName =
|
lookupFieldInfo scopes struct base fieldName =
|
||||||
if maybeFieldType == Nothing
|
if maybeFieldType == Nothing
|
||||||
then scopedError scopes $ "field '" ++ fieldName ++ "' not found in "
|
then (isHier, err, err, err)
|
||||||
++ show struct ++ ", in expression "
|
else (False, fieldType, bounds, dims)
|
||||||
++ show (Dot base fieldName)
|
|
||||||
else (fieldType, bounds, dims)
|
|
||||||
where
|
where
|
||||||
Just fields = getFields struct
|
Just fields = getFields struct
|
||||||
maybeFieldType = lookup fieldName $ map swap fields
|
maybeFieldType = lookup fieldName $ map swap fields
|
||||||
|
|
@ -550,6 +548,10 @@ lookupFieldInfo scopes struct base fieldName =
|
||||||
dims = snd $ typeRanges fieldType
|
dims = snd $ typeRanges fieldType
|
||||||
Just (_, unstructRanges) = convertStruct struct
|
Just (_, unstructRanges) = convertStruct struct
|
||||||
Just bounds = lookup fieldName unstructRanges
|
Just bounds = lookup fieldName unstructRanges
|
||||||
|
err = scopedError scopes $ "field '" ++ fieldName ++ "' not found in "
|
||||||
|
++ show struct ++ ", in expression "
|
||||||
|
++ show (Dot base fieldName)
|
||||||
|
isHier = lookupElem scopes (Dot base fieldName) /= Nothing
|
||||||
|
|
||||||
-- attempts to convert based on the assignment-like contexts of TF arguments
|
-- attempts to convert based on the assignment-like contexts of TF arguments
|
||||||
convertCall :: Scopes Type -> Expr -> Args -> Args
|
convertCall :: Scopes Type -> Expr -> Args -> Args
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,11 @@ isStringParam _ = return False
|
||||||
-- checks if referring to part.wire is needlessly explicit
|
-- checks if referring to part.wire is needlessly explicit
|
||||||
unneededModuleScope :: Identifier -> Identifier -> ST Bool
|
unneededModuleScope :: Identifier -> Identifier -> ST Bool
|
||||||
unneededModuleScope part wire = do
|
unneededModuleScope part wire = do
|
||||||
|
partDetails <- lookupElemM part
|
||||||
accessesLocal <- localAccessesM wire
|
accessesLocal <- localAccessesM wire
|
||||||
if accessesLocal == accessesTop then
|
if partDetails /= Nothing then
|
||||||
|
return False
|
||||||
|
else if accessesLocal == accessesTop then
|
||||||
return True
|
return True
|
||||||
else if head accessesLocal == head accessesTop then do
|
else if head accessesLocal == head accessesTop then do
|
||||||
details <- lookupElemM wire
|
details <- lookupElemM wire
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package P;
|
||||||
|
localparam [31:0] L = 8;
|
||||||
|
typedef struct packed {
|
||||||
|
logic [L + L[0] + L[1:0] + L[0+:1] - 1:0] x;
|
||||||
|
} S;
|
||||||
|
endpackage
|
||||||
|
module top;
|
||||||
|
P::S top;
|
||||||
|
logic [2:0] x;
|
||||||
|
assign x = '0;
|
||||||
|
assign top.x = '1;
|
||||||
|
initial begin
|
||||||
|
#1;
|
||||||
|
$display("%b %b", x, top.x);
|
||||||
|
$display("%b %b", x[0], top.x[0]);
|
||||||
|
$display("%b %b", x[1:0], top.x[1:0]);
|
||||||
|
$display("%b %b", x[0+:1], top.x[0+:1]);
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
module top;
|
||||||
|
wire [7:0] top;
|
||||||
|
wire [2:0] x;
|
||||||
|
assign x = 0;
|
||||||
|
assign top = 8'hFF;
|
||||||
|
initial begin
|
||||||
|
#1;
|
||||||
|
$display("%b %b", x, top);
|
||||||
|
$display("%b %b", x[0], top[0]);
|
||||||
|
$display("%b %b", x[1:0], top[1:0]);
|
||||||
|
$display("%b %b", x[0+:1], top[0+:1]);
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue