Skip to content

Commit

Permalink
compute functions depending on Cairo builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Jun 20, 2024
1 parent 20f52ea commit 0ec6a2b
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/Juvix/Compiler/Reg/Extra/Blocks/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ module Juvix.Compiler.Reg.Extra.Blocks.Info
)
where

import Data.HashMap.Strict qualified as HashMap
import Juvix.Compiler.Reg.Data.Blocks.CallGraph
import Juvix.Compiler.Reg.Data.Blocks.InfoTable
import Juvix.Compiler.Reg.Language.Base
import Juvix.Compiler.Reg.Extra.Blocks
import Juvix.Compiler.Reg.Language.Blocks
import Juvix.Compiler.Tree.Extra.Info

data ExtraInfo = ExtraInfo
Expand All @@ -14,7 +17,10 @@ data ExtraInfo = ExtraInfo
_extraInfoFUIDs :: HashMap Symbol Int,
-- | IDs for constructor tags, consecutive starting from 0 for each
-- inductive type separately
_extraInfoCIDs :: HashMap Tag Int
_extraInfoCIDs :: HashMap Tag Int,
-- | Symbols of functions which depend (directly or indirectly) on Cairo
-- builtins
_extraInfoCairoDepFuns :: HashSet Symbol
}

makeLenses ''ExtraInfo
Expand All @@ -24,5 +30,31 @@ computeExtraInfo tab =
ExtraInfo
{ _extraInfoTable = tab,
_extraInfoFUIDs = computeFUIDs tab,
_extraInfoCIDs = computeCIDs tab
_extraInfoCIDs = computeCIDs tab,
_extraInfoCairoDepFuns = computeCairoDepFuns tab
}

computeCairoDepFuns :: InfoTable -> HashSet Symbol
computeCairoDepFuns tab =
computeAncestors callGraph startNodes
where
callGraph :: CallGraph
callGraph = createCallGraph tab

startNodes :: [Symbol]
startNodes =
map (^. functionSymbol)
. filter (usesCairoBuiltins . (^. functionCode))
. HashMap.elems
$ (tab ^. infoFunctions)

usesCairoBuiltins :: Block -> Bool
usesCairoBuiltins block =
maybe False usesCairoBuiltins (block ^. blockNext)
|| any isCairo (block ^. blockBody)
|| any usesCairoBuiltins (getSubBlocks block)
where
isCairo :: Instruction -> Bool
isCairo = \case
Cairo {} -> True
_ -> False

0 comments on commit 0ec6a2b

Please sign in to comment.