Skip to content

Commit

Permalink
Fix GenCRepr to work with changes to derived Generic instance
Browse files Browse the repository at this point in the history
  • Loading branch information
krame505 authored and quark17 committed Feb 6, 2024
1 parent be5e071 commit a178a2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Libraries/GenC/GenCRepr/GenCRepr.bs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ instance (GenCStructBody bodyRepr n, TypeNames ta) =>
"}")

-- Multi-constructor case, generate a tagged union
instance (GenCUnionBody tagBytes bodyRepr 0 bodyBytes, TypeNames ta,
instance (GenCUnionBody tagBytes bodyRepr maxCIdx bodyBytes, TypeNames ta,
GenCRepr' (Meta (MetaData name pkg ta numCtors) bodyRepr) n1, -- TODO: Why is this context needed?
Log numCtors tagBits, Div tagBits 8 tagBytes, Add tagBytes bodyBytes n) =>
GenCRepr' (Meta (MetaData name pkg ta numCtors) bodyRepr) n where
Expand Down Expand Up @@ -400,7 +400,7 @@ instance TypeNames () where
-- Helper type class to handle sum types.
-- nt = number of tag bytes
-- a = representation type of contents
-- i = constructor index
-- i = max constructor index
-- n = max number of bytes needed to pack any summand
-- Code generation methods require proxy values for nt and a.
class GenCUnionBody nt a i n | nt a -> i n where
Expand All @@ -418,7 +418,7 @@ class GenCUnionBody nt a i n | nt a -> i n where
instance (GenCUnionBody tagBytes a i1 n1, GenCUnionBody tagBytes b i2 n2,
Max n1 n2 n,
Mul tagBytes 8 tagBits) =>
GenCUnionBody tagBytes (Either a b) i1 n where
GenCUnionBody tagBytes (Either a b) i2 n where
genCEnumBody _ _ typeName =
genCEnumBody (_ :: Bit tagBytes) (_ :: a) typeName +++ ", " +++
genCEnumBody (_ :: Bit tagBytes) (_ :: b) typeName
Expand All @@ -437,7 +437,7 @@ instance (GenCUnionBody tagBytes a i1 n1, GenCUnionBody tagBytes b i2 n2,

unpackUnionBody _ = do
x <- get
if fromByteList (take (valueOf tagBytes) x) == ((fromInteger (valueOf i1)) :: Bit tagBits)
if fromByteList (take (valueOf tagBytes) x) <= ((fromInteger (valueOf i1)) :: Bit tagBits)
then liftM Left $ unpackUnionBody (_ :: Bit tagBytes)
else liftM Right $ unpackUnionBody (_ :: Bit tagBytes)
genCUnpackUnionBody _ _ typeName =
Expand Down
7 changes: 7 additions & 0 deletions testing/bsc.contrib/GenC/GenCRepr/Calculator.bs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ eval Sub x y = x - y
eval Mul x y = x * y
eval Div x y = x / y

-- Check that encodings have the expected number of bytes:
instrSize :: (GenCRepr Instr 6) => ()
instrSize = ()

resultSize :: (GenCRepr Result 6) => ()
resultSize = ()

{-# verilog sysCalculator #-}
sysCalculator :: Module Empty
sysCalculator = module
Expand Down

0 comments on commit a178a2d

Please sign in to comment.