Skip to content
Snippets Groups Projects
Commit 9ec0f353 authored by chrg's avatar chrg
Browse files

Better Unstatic

parent c5b2a24a
Branches
No related tags found
No related merge requests found
...@@ -91,13 +91,24 @@ reduceCTranslUnit :: ...@@ -91,13 +91,24 @@ reduceCTranslUnit ::
reduceCTranslUnit (C.CTranslUnit es ni) ctx = do reduceCTranslUnit (C.CTranslUnit es ni) ctx = do
let _functions = foldMap (findFunctions (: [])) es let _functions = foldMap (findFunctions (: [])) es
unstatic <-
if ComputeFunctionFixpoint `isIn` ctx
then forM _functions \fun ->
if funIsStatic fun
then do
let fstr = C.identToString (funName fun)
isStatic <- check ("remove static from " <> fstr, funPosition fun)
pure fun{funIsStatic = isStatic}
else pure fun
else pure _functions
let funmap :: [(C.Ident, Maybe Function)] = let funmap :: [(C.Ident, Maybe Function)] =
List.sortOn (maybe 0 (negate . funSize) . snd) List.sortOn (maybe 0 (negate . funSize) . snd)
. Map.toList . Map.toList
. Map.fromListWith const . Map.fromListWith const
. map (\f -> (funName f, Just f)) . map (\f -> (funName f, Just f))
. List.sortOn funSize . List.sortOn funSize
$ _functions $ unstatic
let reduce funcs = forM funcs \(k, mf) -> let reduce funcs = forM funcs \(k, mf) ->
(k,) <$> runMaybeT do (k,) <$> runMaybeT do
...@@ -116,11 +127,7 @@ reduceCTranslUnit (C.CTranslUnit es ni) ctx = do ...@@ -116,11 +127,7 @@ reduceCTranslUnit (C.CTranslUnit es ni) ctx = do
pure f{funIsStatic = isStatic} pure f{funIsStatic = isStatic}
-- try remove static -- try remove static
functions2 <- do functions2 <- reduce funmap
funmap' <- reduce funmap
if ComputeFunctionFixpoint `isIn` ctx
then reduce funmap'
else pure funmap'
functions3 <- forM functions2 \(k, mf) -> functions3 <- forM functions2 \(k, mf) ->
(k,) <$> runMaybeT do (k,) <$> runMaybeT do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment