+-- | Is the given data constructor a dontcare?
+isDontCare :: DataCon.DataCon -> Bool
+isDontCare datacon =
+ case Name.getOccString tyname of
+ -- TODO: Do something more robust than string matching
+ "Bit" ->
+ Name.getOccString dcname == "DontCare"
+ otherwise ->
+ False
+ where
+ tycon = DataCon.dataConTyCon datacon
+ tyname = TyCon.tyConName tycon
+ dcname = DataCon.dataConName datacon
+
+-- | Translates a dataconstructor without arguments to the corresponding
+-- literal.
+dataConToLiteral :: DataCon.DataCon -> FlattenState String
+dataConToLiteral datacon = do
+ let tycon = DataCon.dataConTyCon datacon
+ let tyname = TyCon.tyConName tycon
+ case Name.getOccString tyname of
+ -- TODO: Do something more robust than string matching
+ "Bit" -> do
+ let dcname = DataCon.dataConName datacon
+ let lit = case Name.getOccString dcname of "High" -> "'1'"; "Low" -> "'0'"; "DontCare" -> "'-'"
+ return lit
+ "Bool" -> do
+ let dcname = DataCon.dataConName datacon
+ let lit = case Name.getOccString dcname of "True" -> "true"; "False" -> "false"
+ return lit
+ otherwise ->
+ error $ "Literals of type " ++ (Name.getOccString tyname) ++ " not supported."