From e7566ac3f6dbe843afd0ff6f0ae333ff565afc89 Mon Sep 17 00:00:00 2001 From: Valentin Robert Date: Tue, 29 Aug 2023 15:43:13 -0700 Subject: [PATCH] improve `argsToRegisters` `argsToRegisters` was unnecessarily exposing an argument counter used internally for vector indexing, while annotated with an incorrect comment. This makes the function simpler from the outside, and fixes the comment. --- src/Reopt.hs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Reopt.hs b/src/Reopt.hs index 0d4af755..134819e3 100644 --- a/src/Reopt.hs +++ b/src/Reopt.hs @@ -2090,22 +2090,24 @@ resolveArgType nm tp0 = TypedefAnnType _ tp -> resolveArgType nm tp --- | This parses the types extracted from header function argumnts to --- the machine code registers that the function will expect. +-- | This parses the types extracted from header function arguments to the +-- machine code registers that the function will expect. argsToRegisters :: + forall m. Monad m => - -- | Number of arguments processed so far. - Int -> - -- | Remaining arguments to parse + -- | Vector of arguments to a given function V.Vector AnnFunArg -> ArgResolver m () -argsToRegisters cnt args - | cnt >= V.length args = pure () - | otherwise = do - let arg = args V.! cnt - let nm = fromMaybe ("arg" ++ show cnt) (funArgName arg) - resolveArgType nm (funArgType arg) - argsToRegisters (cnt + 1) args +argsToRegisters args = go 0 + where + go :: Int -> ArgResolver m () + go argIx + | argIx >= V.length args = pure () + | otherwise = do + let arg = args V.! argIx + let nm = fromMaybe ("arg" ++ show argIx) (funArgName arg) + resolveArgType nm (funArgType arg) + go (argIx + 1) parseReturnType :: AnnType -> Either ArgResolverError [Some X86RetInfo] parseReturnType tp0 = @@ -2124,7 +2126,7 @@ resolveAnnFunType :: AnnFunType -> ExceptT ArgResolverError m X86FunTypeInfo resolveAnnFunType funType = do - args <- runArgResolver (argsToRegisters 0 (funArgs funType)) + args <- runArgResolver (argsToRegisters (funArgs funType)) ret <- case parseReturnType (funRet funType) of Left e -> throwError e