mirror of https://github.com/zachjs/sv2v.git
struct conversion handles alternate and mixed integer vector field types
This commit is contained in:
parent
44ea16e3eb
commit
3bef2b9cdb
|
|
@ -1,7 +1,7 @@
|
||||||
{- sv2v
|
{- sv2v
|
||||||
- Author: Zachary Snow <zach@zachjs.com>
|
- Author: Zachary Snow <zach@zachjs.com>
|
||||||
-
|
-
|
||||||
- Conversion for `int`, `shortint`, `longint`, and `byte`
|
- Conversion for `bit`, `int`, `shortint`, `longint`, and `byte`
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Convert.IntTypes (convert) where
|
module Convert.IntTypes (convert) where
|
||||||
|
|
@ -21,6 +21,7 @@ convertType (IntegerAtom TInt sg) = baseType sg Signed 32
|
||||||
convertType (IntegerAtom TShortint sg) = baseType sg Signed 16
|
convertType (IntegerAtom TShortint sg) = baseType sg Signed 16
|
||||||
convertType (IntegerAtom TLongint sg) = baseType sg Signed 64
|
convertType (IntegerAtom TLongint sg) = baseType sg Signed 64
|
||||||
convertType (IntegerAtom TByte sg) = baseType sg Unspecified 8
|
convertType (IntegerAtom TByte sg) = baseType sg Unspecified 8
|
||||||
|
convertType (IntegerVector TBit sg rs) = IntegerVector TLogic sg rs
|
||||||
convertType other = other
|
convertType other = other
|
||||||
|
|
||||||
-- makes a integer "compatible" type with the given signing, base signing and
|
-- makes a integer "compatible" type with the given signing, base signing and
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,6 @@ convertDescription other = other
|
||||||
-- write down unstructured versions of packed struct types
|
-- write down unstructured versions of packed struct types
|
||||||
collectStructM :: Type -> Writer Structs ()
|
collectStructM :: Type -> Writer Structs ()
|
||||||
collectStructM (Struct (Packed sg) fields _) = do
|
collectStructM (Struct (Packed sg) fields _) = do
|
||||||
-- TODO: How should we combine the structs Signing with that of the types it
|
|
||||||
-- contains?
|
|
||||||
if canUnstructure
|
if canUnstructure
|
||||||
then tell $ Map.singleton
|
then tell $ Map.singleton
|
||||||
(Struct (Packed sg) fields)
|
(Struct (Packed sg) fields)
|
||||||
|
|
@ -102,25 +100,19 @@ collectStructM (Struct (Packed sg) fields _) = do
|
||||||
vals = zip unstructRanges unstructOffsets
|
vals = zip unstructRanges unstructOffsets
|
||||||
unstructFields = Map.fromList $ zip keys vals
|
unstructFields = Map.fromList $ zip keys vals
|
||||||
|
|
||||||
-- create the unstructured type
|
-- create the unstructured type; result type takes on the signing of the
|
||||||
tf = fst $ typeRanges $ head fieldTypes
|
-- struct itself to preserve behavior of operations on the whole struct
|
||||||
structSize = foldl1 (BinOp Add) fieldSizes
|
structSize = foldl1 (BinOp Add) fieldSizes
|
||||||
packedRange = (simplify $ BinOp Sub structSize (Number "1"), zero)
|
packedRange = (simplify $ BinOp Sub structSize (Number "1"), zero)
|
||||||
unstructType = tf [packedRange]
|
unstructType = IntegerVector TLogic sg [packedRange]
|
||||||
|
|
||||||
-- TODO: For now, we only convert packed structs which contain fields
|
-- check if this struct can be packed into an integer vector; integer
|
||||||
-- with all the same base type. We might be able to get away with
|
-- atoms and non-integers do not have a definitive size, and so cannot
|
||||||
-- converting everything to a Logic type. This should work in cases of
|
-- be packed; net types are not permitted as struct fields
|
||||||
-- mixed `wire`/`logic` or `reg`/`logic`.
|
isIntVec :: Type -> Bool
|
||||||
fieldClasses = map (show . fst . typeRanges) fieldTypes
|
isIntVec (IntegerVector _ _ _) = True
|
||||||
isComplex :: Type -> Bool
|
isIntVec _ = False
|
||||||
isComplex (Struct _ _ _) = True
|
canUnstructure = all isIntVec fieldTypes
|
||||||
isComplex (Enum _ _ _) = True
|
|
||||||
isComplex (Alias _ _ _) = True
|
|
||||||
isComplex _ = False
|
|
||||||
canUnstructure =
|
|
||||||
all (head fieldClasses ==) fieldClasses &&
|
|
||||||
not (any isComplex fieldTypes)
|
|
||||||
|
|
||||||
collectStructM _ = return ()
|
collectStructM _ = return ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
typedef struct packed { logic w, x, y; } StructA;
|
typedef struct packed { reg w; bit x; logic y; } StructA;
|
||||||
typedef struct packed { logic w, y, x; } StructB;
|
typedef struct packed { reg w; logic y; bit x; } StructB;
|
||||||
typedef struct packed { logic x, w, y; } StructC;
|
typedef struct packed { bit x; reg w; logic y; } StructC;
|
||||||
typedef struct packed { logic y, w, x; } StructD;
|
typedef struct packed { logic y; reg w; bit x; } StructD;
|
||||||
typedef struct packed { logic x, y, w; } StructE;
|
typedef struct packed { bit x; logic y; reg w; } StructE;
|
||||||
typedef struct packed { logic y, x, w; } StructF;
|
typedef struct packed { logic y; bit x; reg w; } StructF;
|
||||||
|
|
||||||
module top;
|
module top;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue