Commit 3bef2b9c by Zachary Snow

struct conversion handles alternate and mixed integer vector field types

parent 44ea16e3
{- sv2v
- 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
......@@ -21,6 +21,7 @@ convertType (IntegerAtom TInt sg) = baseType sg Signed 32
convertType (IntegerAtom TShortint sg) = baseType sg Signed 16
convertType (IntegerAtom TLongint sg) = baseType sg Signed 64
convertType (IntegerAtom TByte sg) = baseType sg Unspecified 8
convertType (IntegerVector TBit sg rs) = IntegerVector TLogic sg rs
convertType other = other
-- 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
collectStructM :: Type -> Writer Structs ()
collectStructM (Struct (Packed sg) fields _) = do
-- TODO: How should we combine the structs Signing with that of the types it
-- contains?
if canUnstructure
then tell $ Map.singleton
(Struct (Packed sg) fields)
......@@ -102,25 +100,19 @@ collectStructM (Struct (Packed sg) fields _) = do
vals = zip unstructRanges unstructOffsets
unstructFields = Map.fromList $ zip keys vals
-- create the unstructured type
tf = fst $ typeRanges $ head fieldTypes
-- create the unstructured type; result type takes on the signing of the
-- struct itself to preserve behavior of operations on the whole struct
structSize = foldl1 (BinOp Add) fieldSizes
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
-- with all the same base type. We might be able to get away with
-- converting everything to a Logic type. This should work in cases of
-- mixed `wire`/`logic` or `reg`/`logic`.
fieldClasses = map (show . fst . typeRanges) fieldTypes
isComplex :: Type -> Bool
isComplex (Struct _ _ _) = True
isComplex (Enum _ _ _) = True
isComplex (Alias _ _ _) = True
isComplex _ = False
canUnstructure =
all (head fieldClasses ==) fieldClasses &&
not (any isComplex fieldTypes)
-- check if this struct can be packed into an integer vector; integer
-- atoms and non-integers do not have a definitive size, and so cannot
-- be packed; net types are not permitted as struct fields
isIntVec :: Type -> Bool
isIntVec (IntegerVector _ _ _) = True
isIntVec _ = False
canUnstructure = all isIntVec fieldTypes
collectStructM _ = return ()
......
typedef struct packed { logic w, x, y; } StructA;
typedef struct packed { logic w, y, x; } StructB;
typedef struct packed { logic x, w, y; } StructC;
typedef struct packed { logic y, w, x; } StructD;
typedef struct packed { logic x, y, w; } StructE;
typedef struct packed { logic y, x, w; } StructF;
typedef struct packed { reg w; bit x; logic y; } StructA;
typedef struct packed { reg w; logic y; bit x; } StructB;
typedef struct packed { bit x; reg w; logic y; } StructC;
typedef struct packed { logic y; reg w; bit x; } StructD;
typedef struct packed { bit x; logic y; reg w; } StructE;
typedef struct packed { logic y; bit x; reg w; } StructF;
module top;
......
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