mirror of https://github.com/zachjs/sv2v.git
better error message for indexed atoms
This commit is contained in:
parent
c103d0cb67
commit
3b2a55a69c
|
|
@ -214,18 +214,20 @@ typeof (Number n) =
|
||||||
typeof (Call (Ident x) args) = typeofCall x args
|
typeof (Call (Ident x) args) = typeofCall x args
|
||||||
typeof orig@(Bit e _) = do
|
typeof orig@(Bit e _) = do
|
||||||
t <- typeof e
|
t <- typeof e
|
||||||
let t' = popRange t
|
|
||||||
case t of
|
case t of
|
||||||
TypeOf{} -> lookupTypeOf orig
|
TypeOf{} -> return $ TypeOf orig
|
||||||
Alias{} -> return $ TypeOf orig
|
Alias{} -> return $ TypeOf orig
|
||||||
_ -> return $ typeSignednessOverride t' Unsigned t'
|
_ -> do
|
||||||
|
t' <- popRange orig t
|
||||||
|
return $ typeSignednessOverride t' Unsigned t'
|
||||||
typeof orig@(Range e NonIndexed r) = do
|
typeof orig@(Range e NonIndexed r) = do
|
||||||
t <- typeof e
|
t <- typeof e
|
||||||
let t' = replaceRange r t
|
case t of
|
||||||
return $ case t of
|
TypeOf{} -> return $ TypeOf orig
|
||||||
TypeOf{} -> TypeOf orig
|
Alias{} -> return $ TypeOf orig
|
||||||
Alias{} -> TypeOf orig
|
_ -> do
|
||||||
_ -> typeSignednessOverride t' Unsigned t'
|
t' <- replaceRange orig r t
|
||||||
|
return $ typeSignednessOverride t' Unsigned t'
|
||||||
typeof (Range expr mode (base, len)) =
|
typeof (Range expr mode (base, len)) =
|
||||||
typeof $ Range expr NonIndexed $
|
typeof $ Range expr NonIndexed $
|
||||||
endianCondRange index (base, end) (end, base)
|
endianCondRange index (base, end) (end, base)
|
||||||
|
|
@ -398,23 +400,31 @@ injectRanges (UnpackedType t rs) unpacked = UnpackedType t $ unpacked ++ rs
|
||||||
injectRanges t unpacked = UnpackedType t unpacked
|
injectRanges t unpacked = UnpackedType t unpacked
|
||||||
|
|
||||||
-- removes the most significant range of the given type
|
-- removes the most significant range of the given type
|
||||||
popRange :: Type -> Type
|
popRange :: Expr -> Type -> ST Type
|
||||||
popRange (UnpackedType t [_]) = t
|
popRange _ (UnpackedType t [_]) = return t
|
||||||
popRange (IntegerAtom TInteger sg) =
|
popRange _ (IntegerAtom TInteger sg) =
|
||||||
IntegerVector TLogic sg []
|
return $ IntegerVector TLogic sg []
|
||||||
popRange t =
|
popRange e t =
|
||||||
tf rs
|
case typeRanges t of
|
||||||
where (tf, _ : rs) = typeRanges t
|
(tf, _ : rs) -> return $ tf rs
|
||||||
|
_ -> indexedAtomError e t
|
||||||
|
|
||||||
-- replaces the most significant range of the given type
|
-- replaces the most significant range of the given type
|
||||||
replaceRange :: Range -> Type -> Type
|
replaceRange :: Expr -> Range -> Type -> ST Type
|
||||||
replaceRange r (UnpackedType t (_ : rs)) =
|
replaceRange _ r (UnpackedType t (_ : rs)) =
|
||||||
UnpackedType t (r : rs)
|
return $ UnpackedType t (r : rs)
|
||||||
replaceRange r (IntegerAtom TInteger sg) =
|
replaceRange _ r (IntegerAtom TInteger sg) =
|
||||||
IntegerVector TLogic sg [r]
|
return $ IntegerVector TLogic sg [r]
|
||||||
replaceRange r t =
|
replaceRange e r t =
|
||||||
tf (r : rs)
|
case typeRanges t of
|
||||||
where (tf, _ : rs) = typeRanges t
|
(tf, _ : rs) -> return $ tf (r : rs)
|
||||||
|
_ -> indexedAtomError e t
|
||||||
|
|
||||||
|
-- readable error message when looking up the type of a portion of an atom
|
||||||
|
indexedAtomError :: Expr -> Type -> ST a
|
||||||
|
indexedAtomError e t =
|
||||||
|
scopedErrorM $ "can't determine the type of " ++ show e ++ " because the"
|
||||||
|
++ " inner type " ++ show t ++ " can't be indexed"
|
||||||
|
|
||||||
-- checks for a cast type which already trivially matches the expression type
|
-- checks for a cast type which already trivially matches the expression type
|
||||||
typeCastUnneeded :: Type -> Type -> Bool
|
typeCastUnneeded :: Type -> Type -> Bool
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
// pattern: can't determine the type of x\[1\] because the inner type reg can't be indexed
|
||||||
|
// location: typeof_atom_bit.sv:5:13
|
||||||
|
module top;
|
||||||
|
reg x;
|
||||||
|
initial $display($bits(x[1]));
|
||||||
|
endmodule
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
// pattern: can't determine the type of x\[1:0\] because the inner type reg can't be indexed
|
||||||
|
// location: typeof_atom_range.sv:5:5
|
||||||
|
module top;
|
||||||
|
reg x;
|
||||||
|
var type(x[1:0]) y;
|
||||||
|
initial $display(y);
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue