X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=clash%2FCLasH%2FVHDL%2FVHDLTools.hs;h=ab3360b8126c44950c2f9cabddf71f73f38ef0ee;hb=4cab3f3e4f50032c79fc7dd28a5545e99c8c64d7;hp=0ac3015e3f512533371a150f3d047de00e50da44;hpb=4ec63e9167a55d916e14f9c74e952e218e66fe0c;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/clash/CLasH/VHDL/VHDLTools.hs b/clash/CLasH/VHDL/VHDLTools.hs index 0ac3015..ab3360b 100644 --- a/clash/CLasH/VHDL/VHDLTools.hs +++ b/clash/CLasH/VHDL/VHDLTools.hs @@ -346,7 +346,8 @@ mkHTypeEither' ty | ty_has_free_tyvars ty = return $ Left $ "\nVHDLTools.mkHType return $ Right $ SizedIType len "Index" -> do bound <- tfp_to_int (ranged_word_bound_ty ty) - return $ Right $ RangedWType bound + -- Upperbound is exclusive, hence the -1 + return $ Right $ RangedWType (bound - 1) otherwise -> mkTyConHType tycon args Nothing -> return $ Left $ "\nVHDLTools.mkHTypeEither': Do not know what to do with type: " ++ pprString ty @@ -570,8 +571,8 @@ getFields :: getFields htype dc_i = case htype of (AggrType name _ fieldss) | dc_i >= 0 && dc_i < length fieldss -> fieldss!!dc_i - | otherwise -> error $ "Invalid constructor index: " ++ (show dc_i) ++ ". No such constructor in HType: " ++ (show htype) - _ -> error $ "Can't get fields from non-aggregate HType: " ++ show htype + | otherwise -> error $ "VHDLTool.getFields: Invalid constructor index: " ++ (show dc_i) ++ ". No such constructor in HType: " ++ (show htype) + _ -> error $ "VHDLTool.getFields: Can't get fields from non-aggregate HType: " ++ show htype -- Finds the field labels for an aggregation type, as VHDLIds. getFieldLabels :: @@ -581,6 +582,17 @@ getFieldLabels :: -> [AST.VHDLId] -- ^ The labels getFieldLabels htype dc_i = ((map mkVHDLBasicId) . (map fst)) (getFields htype dc_i) +-- Finds the field label for the constructor field, if any. +getConstructorFieldLabel :: + HType + -> Maybe AST.VHDLId +getConstructorFieldLabel (AggrType _ (Just con) _) = + Just $ mkVHDLBasicId (fst con) +getConstructorFieldLabel (AggrType _ Nothing _) = + Nothing +getConstructorFieldLabel htype = + error $ "Can't get constructor field label from non-aggregate HType: " ++ show htype + mktydecl :: (AST.VHDLId, Maybe (Either AST.TypeDef AST.SubtypeIn)) -> Maybe AST.PackageDecItem mytydecl (_, Nothing) = Nothing mktydecl (ty_id, Just (Left ty_def)) = Just $ AST.PDITD $ AST.TypeDec ty_id ty_def