From: Matthijs Kooijman Date: Mon, 22 Jun 2009 11:06:33 +0000 (+0200) Subject: Check parameter counts in mkConcSm instead of the actual generate functions. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=77d347006ced194e77aee0f66da98a2028cb259e;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git Check parameter counts in mkConcSm instead of the actual generate functions. --- diff --git a/Generate.hs b/Generate.hs index 26c0448..23e4a2c 100644 --- a/Generate.hs +++ b/Generate.hs @@ -7,12 +7,10 @@ import Constants -- constructor from the AST.Expr type, e.g. AST.And. genExprOp2 :: (AST.Expr -> AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr genExprOp2 op [arg1, arg2] = op arg1 arg2 -genExprOp2 _ _ = error "Generate.genExprOp2 wrong number of argumetns" -- | Generate a unary operator application genExprOp1 :: (AST.Expr -> AST.Expr) -> [AST.Expr] -> AST.Expr genExprOp1 op [arg] = op arg -genExprOp1 _ _ = error "Generate.genExprOp1 wrong number of argumetns" -- | Generate a function call from the Function Name and a list of expressions -- (its arguments) @@ -21,16 +19,6 @@ genExprFCall fName args = AST.PrimFCall $ AST.FCall (AST.NSimple fName) $ map (\exp -> Nothing AST.:=>: AST.ADExpr exp) args --- | List version of genExprFCall1 -genExprFCall1L :: AST.VHDLId -> [AST.Expr] -> AST.Expr -genExprFCall1L fName [arg] = genExprFCall fName [arg] -genExprFCall1L _ _ = error "Generate.genExprFCall1L incorrect length" - --- | List version of genExprFCall2 -genExprFCall2L :: AST.VHDLId -> [AST.Expr] -> AST.Expr -genExprFCall2L fName [arg1, arg2] = genExprFCall fName [arg1,arg2] -genExprFCall2L _ _ = error "Generate.genExprFCall2L incorrect length" - genUnconsVectorFuns :: AST.TypeMark -- ^ type of the vector elements -> AST.TypeMark -- ^ type of the vector -> [AST.SubProgBody] diff --git a/GlobalNameTable.hs b/GlobalNameTable.hs index 8c3faab..756c611 100644 --- a/GlobalNameTable.hs +++ b/GlobalNameTable.hs @@ -17,8 +17,8 @@ mkGlobalNameTable = Map.fromList globalNameTable :: NameTable globalNameTable = mkGlobalNameTable - [ ("!" , (2, genExprFCall2L exId ) ) - , ("head" , (1, genExprFCall1L headId ) ) + [ ("!" , (2, genExprFCall exId ) ) + , ("head" , (1, genExprFCall headId ) ) , ("hwxor" , (2, genExprOp2 AST.Xor ) ) , ("hwand" , (2, genExprOp2 AST.And ) ) , ("hwor" , (2, genExprOp2 AST.And ) ) diff --git a/VHDL.hs b/VHDL.hs index 8f710f3..229ba5c 100644 --- a/VHDL.hs +++ b/VHDL.hs @@ -283,16 +283,19 @@ mkConcSm (bndr, app@(CoreSyn.App _ _))= do -- functions. funSignatures <- getA vsNameTable case (Map.lookup (bndrToString f) funSignatures) of - Just funSignature -> - let - sigs = map (bndrToString.varBndr) args - sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs - func = (snd funSignature) sigsNames - src_wform = AST.Wform [AST.WformElem func Nothing] - dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr)) - assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing) - in - return $ AST.CSSASm assign + Just (arg_count, builder) -> + if length args == arg_count then + let + sigs = map (bndrToString.varBndr) args + sigsNames = map (\signal -> (AST.PrimName (AST.NSimple (mkVHDLExtId signal)))) sigs + func = builder sigsNames + src_wform = AST.Wform [AST.WformElem func Nothing] + dst_name = AST.NSimple (mkVHDLExtId (bndrToString bndr)) + assign = dst_name AST.:<==: (AST.ConWforms [] src_wform Nothing) + in + return $ AST.CSSASm assign + else + error $ "VHDL.mkConcSm Incorrect number of arguments to builtin function: " ++ pprString f ++ " Args: " ++ pprString args Nothing -> error $ "Using function from another module that is not a known builtin: " ++ pprString f IdInfo.NotGlobalId -> do signatures <- getA vsSignatures