-----------------------------------------------------------------------------
--
-- Code generation for coverage
--
-- (c) Galois Connections, Inc. 2006
--
-----------------------------------------------------------------------------

module GHC.StgToCmm.Hpc ( mkTickBox ) where

import GHC.Prelude
import GHC.Platform


import GHC.Cmm.Graph
import GHC.Cmm.Expr
import GHC.Cmm.CLabel
import GHC.Cmm.Utils

import GHC.Unit.Module


mkTickBox :: Platform -> Module -> Int -> CmmAGraph
mkTickBox :: Platform -> Module -> Int -> CmmAGraph
mkTickBox Platform
platform Module
mod Int
n
  = CmmExpr -> CmmExpr -> CmmAGraph
mkStore CmmExpr
tick_box (MachOp -> [CmmExpr] -> CmmExpr
CmmMachOp (Width -> MachOp
MO_Add Width
W64)
                                [ CmmExpr -> CmmType -> AlignmentSpec -> CmmExpr
CmmLoad CmmExpr
tick_box CmmType
b64 AlignmentSpec
NaturallyAligned
                                , CmmLit -> CmmExpr
CmmLit (Integer -> Width -> CmmLit
CmmInt Integer
1 Width
W64)
                                ])
  where
    tick_box :: CmmExpr
tick_box = Platform -> Width -> CmmExpr -> Int -> CmmExpr
cmmIndex Platform
platform Width
W64
                        (CmmLit -> CmmExpr
CmmLit (CmmLit -> CmmExpr) -> CmmLit -> CmmExpr
forall a b. (a -> b) -> a -> b
$ CLabel -> CmmLit
CmmLabel (CLabel -> CmmLit) -> CLabel -> CmmLit
forall a b. (a -> b) -> a -> b
$ Module -> CLabel
mkHpcTicksLabel (Module -> CLabel) -> Module -> CLabel
forall a b. (a -> b) -> a -> b
$ Module
mod)
                        Int
n