Skip to content

Commit

Permalink
improve argsToRegisters
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Ptival committed Aug 30, 2023
1 parent 0d3cb65 commit e7566ac
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Reopt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down

0 comments on commit e7566ac

Please sign in to comment.