never executed always true always false
    1 module HelVM.HelMA.Automaton.Optimizer.ConstantFoldingOptimizer (
    2   constantFolding,
    3 ) where
    4 
    5 import           HelVM.HelMA.Automaton.Combiner.ALU
    6 
    7 import           HelVM.HelMA.Automaton.Instruction
    8 
    9 import           HelVM.HelMA.Automaton.Instruction.Extras.Constructors
   10 import           HelVM.HelMA.Automaton.Instruction.Groups.SMInstruction
   11 
   12 import qualified Data.ListLike                                          as LL
   13 
   14 constantFolding :: InstructionList -> InstructionList
   15 constantFolding = constantFoldingWithAcc []
   16 
   17 constantFoldingWithAcc :: [Integer] -> InstructionList -> InstructionList
   18 constantFoldingWithAcc acc (i : il) = constantFoldingForI acc il i
   19 constantFoldingWithAcc acc []       = generateIL acc
   20 
   21 constantFoldingForI :: [Integer] -> InstructionList -> Instruction -> InstructionList
   22 constantFoldingForI acc il i@(ISM (SPure i')) = constantFoldingForResult il i acc $ runSAL i' acc
   23 constantFoldingForI acc il i                  = generateIL acc <> (i : constantFolding il)
   24 
   25 constantFoldingForResult :: InstructionList -> Instruction -> [Integer] -> Either a [Integer] -> InstructionList
   26 constantFoldingForResult il _ _   (Right acc) = constantFoldingWithAcc acc il
   27 constantFoldingForResult il i acc (Left  _  ) = generateIL acc <> (i : constantFolding il)
   28 
   29 generateIL :: [Integer] -> InstructionList
   30 generateIL acc = consI <$> LL.reverse acc