From 9ec0f3539f37e571282219941d29202e21abad87 Mon Sep 17 00:00:00 2001 From: Christian Gram Kalhauge <chrg@dtu.dk> Date: Fri, 21 Mar 2025 10:13:19 +0100 Subject: [PATCH] Better Unstatic --- rtree-c/src/ReduceC.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/rtree-c/src/ReduceC.hs b/rtree-c/src/ReduceC.hs index d066856..42cf7a9 100644 --- a/rtree-c/src/ReduceC.hs +++ b/rtree-c/src/ReduceC.hs @@ -91,13 +91,24 @@ reduceCTranslUnit :: reduceCTranslUnit (C.CTranslUnit es ni) ctx = do 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)] = List.sortOn (maybe 0 (negate . funSize) . snd) . Map.toList . Map.fromListWith const . map (\f -> (funName f, Just f)) . List.sortOn funSize - $ _functions + $ unstatic let reduce funcs = forM funcs \(k, mf) -> (k,) <$> runMaybeT do @@ -116,11 +127,7 @@ reduceCTranslUnit (C.CTranslUnit es ni) ctx = do pure f{funIsStatic = isStatic} -- try remove static - functions2 <- do - funmap' <- reduce funmap - if ComputeFunctionFixpoint `isIn` ctx - then reduce funmap' - else pure funmap' + functions2 <- reduce funmap functions3 <- forM functions2 \(k, mf) -> (k,) <$> runMaybeT do -- GitLab