From 3bef2b9cdb6aa22c40e010015003be3a340d8eca Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Fri, 10 May 2019 10:41:31 -0400 Subject: [PATCH] struct conversion handles alternate and mixed integer vector field types --- src/Convert/IntTypes.hs | 3 ++- src/Convert/Struct.hs | 28 ++++++++++------------------ test/basic/struct_shadow.sv | 12 ++++++------ 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Convert/IntTypes.hs b/src/Convert/IntTypes.hs index 3ada549..58a31eb 100644 --- a/src/Convert/IntTypes.hs +++ b/src/Convert/IntTypes.hs @@ -1,7 +1,7 @@ {- sv2v - Author: Zachary Snow - - - 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 diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 6c9629d..2c85023 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -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 () diff --git a/test/basic/struct_shadow.sv b/test/basic/struct_shadow.sv index d5e88c5..82c141e 100644 --- a/test/basic/struct_shadow.sv +++ b/test/basic/struct_shadow.sv @@ -1,9 +1,9 @@ -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;