<commit_before>{-# LANGUAGE GeneralizedNewtypeDeriving, ScopedTypeVariables #-}

module L0.EnablingOpts.EnablingOptDriver ( 
                                    enablingOpts
                                  , copyCtProp
                                  , CallGraph
                                  , buildCG
                                  , aggInlineDriver
                                  , deadFunElim
                                  , EnablingOptError(..)
                            )
  where
 
 
--import Data.Either
 
import L0.AbSyn
import L0.Renamer

import L0.EnablingOpts.InliningDeadFun
import L0.EnablingOpts.CopyCtPropFold
import L0.EnablingOpts.DeadVarElim
import L0.EnablingOpts.TupleNormalizer
import L0.EnablingOpts.LetNormalizer
import L0.EnablingOpts.EnablingOptErrors

import L0.EnablingOpts.ArrTup2TupArr

import Debug.Trace

--------------------------------------------------------------
---- Enabling Optimization Driver
--------------------------------------------------------------

--enablingOpts :: TypeBox tf => Prog tf -> Either EnablingOptError (Prog tf)
enablingOpts :: Prog Type -> Either EnablingOptError (Prog Type)
enablingOpts prog = do

    prog_inl      <- aggInlineDriver prog

    prog_dfe      <- deadFunElim     prog_inl

    let prog_rn   = renameProg       prog_dfe

    prog_ntup     <- tupleNormProg   prog_rn

    --(_, prog_nlet)<- letNormProg     prog_ntup
    --(_,prog_cp)   <- copyCtProp      prog_nlet
    --(_, prog_dce) <- deadCodeElim    prog_cp

    prog_enopt <- normCopyDeadOpts prog_ntup

    prog_l0 <- arr2tupProg prog_enopt
    
    return prog_l0
    --return prog_enopt

--    if(succs)
--    then enablingOpts outprog
--    else return       outprog

normCopyDeadOpts :: Prog Type -> Either EnablingOptError (Prog Type)
normCopyDeadOpts prog = do
    (_, prog_nlet1) <- letNormProg     prog
    (_,prog_cp1)    <- copyCtProp      prog_nlet1
    --(_, prog_dce1)  <- trace (prettyPrint prog_cp1) (deadCodeElim prog_cp1)
    (_, prog_dce1)  <- deadCodeElim    prog_cp1

    (_, prog_nlet2) <- letNormProg     prog_dce1
    (_,prog_cp2)    <- copyCtProp      prog_nlet2
    --(_, prog_dce2)  <- trace (prettyPrint prog_cp2) (deadCodeElim prog_cp2)
    (_, prog_dce2)  <- deadCodeElim    prog_cp2

    return prog_dce2    
    

<commit_msg>reorganized<commit_after>{-# LANGUAGE GeneralizedNewtypeDeriving, ScopedTypeVariables #-}

module L0.EnablingOpts.EnablingOptDriver ( 
                                    enablingOpts
                                  , copyCtProp
                                  , CallGraph
                                  , buildCG
                                  , aggInlineDriver
                                  , deadFunElim
                                  , EnablingOptError(..)
                            )
  where
 
 
--import Data.Either
 
import L0.AbSyn
import L0.Renamer

import L0.EnablingOpts.InliningDeadFun
import L0.EnablingOpts.CopyCtPropFold
import L0.EnablingOpts.DeadVarElim
import L0.EnablingOpts.TupleNormalizer
import L0.EnablingOpts.LetNormalizer
import L0.EnablingOpts.EnablingOptErrors

import L0.EnablingOpts.ArrTup2TupArr

import Debug.Trace

--------------------------------------------------------------
---- Enabling Optimization Driver
--------------------------------------------------------------

--enablingOpts :: TypeBox tf => Prog tf -> Either EnablingOptError (Prog tf)
enablingOpts :: Prog Type -> Either EnablingOptError (Prog Type)
enablingOpts prog = do

    prog_inl      <- aggInlineDriver prog

    prog_dfe      <- deadFunElim     prog_inl

    let prog_rn   = renameProg       prog_dfe

    prog_ntup     <- tupleNormProg   prog_rn

    prog_enopt1 <- normCopyDeadOpts prog_ntup
    prog_enopt2 <- normCopyDeadOpts prog_enopt1

    prog_flat <- arr2tupProg prog_enopt2
    prog_l0   <- normCopyDeadOpts prog_flat
    
    return prog_l0

--    if(succs)
--    then enablingOpts outprog
--    else return       outprog

normCopyDeadOpts :: Prog Type -> Either EnablingOptError (Prog Type)
normCopyDeadOpts prog = do
    (_, prog_nlet) <- letNormProg     prog
    (_,prog_cp)    <- copyCtProp      prog_nlet
    --(_, prog_dce)  <- trace (prettyPrint prog_cp1) (deadCodeElim prog_cp1)
    (_, prog_dce)  <- deadCodeElim    prog_cp

    return prog_dce


{'fraction_non_alphanumeric': 0.12424523920111473, 'fraction_numerical': 0.012076172782164421, 'mean_word_length': 1.6701797892126473, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7236338', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1313, 'n_words': 258}