never executed always true always false
    1 module HelVM.HelMA.Automaton.Instruction.Groups.CFInstruction where
    2 
    3 import           HelVM.HelMA.Automaton.Instruction.Extras.TextExtra
    4 
    5 import           HelVM.HelIO.Collections.SList
    6 
    7 -- | Others
    8 
    9 isNotJump ∷ Integral e ⇒ BranchTest → e → Bool
   10 isNotJump t = not . isJump t
   11 
   12 isJump ∷ Integral e ⇒ BranchTest → e → Bool
   13 isJump NE  e = e /= 0
   14 isJump EZ  e = e == 0
   15 isJump LTZ e = e <  0
   16 isJump GTZ e = e >  0
   17 
   18 -- | Types
   19 data CFInstruction
   20   = Mark !Mark
   21   | Branch !BranchOperand !BranchTest
   22   | Labeled !LabelOperand !LabelOperation
   23   | Return
   24   deriving stock (Eq, Read, Show)
   25 
   26 data Mark
   27   = MNatural Natural
   28   | MArtificial Label
   29   deriving stock (Eq, Read, Show)
   30 
   31 data LabelOperand
   32   = LTop
   33   | LImmediate !Natural
   34   | LArtificial Label
   35   deriving stock (Eq, Read, Show)
   36 
   37 data BranchOperand
   38   = BSwapped
   39   | BTop
   40   | BImmediate !Natural
   41   | BArtificial Label
   42   deriving stock (Eq, Read, Show)
   43 
   44 --FIXME
   45 --data Artificial = Integer | Label
   46 --
   47 
   48 type Label = SString --FIXME Artificial
   49 
   50 data LabelOperation
   51   = Call
   52   | Jump
   53   deriving stock (Eq, Read, Show)
   54 
   55 data BranchTest
   56   = EZ
   57   | LTZ
   58   | GTZ
   59   | NE
   60   deriving stock (Eq, Read, Show)
   61 
   62 -- | Internal
   63 
   64 printCF ∷ CFInstruction → Text
   65 printCF (Mark     i  ) = "\nmark" <> printMark i
   66 printCF (Branch i t)   = printBranchTest t <> printBranchOperand i
   67 printCF (Labeled  i o) = toLowerShow o <> printLabelOperand i
   68 printCF           i    = toLowerShow i
   69 
   70 printMark ∷ Mark → Text
   71 printMark (MNatural    i) = "M " <> show i
   72 printMark (MArtificial i) = "A " <> show i
   73 
   74 printBranchTest ∷ BranchTest → Text
   75 printBranchTest t = "b" <> show t
   76 
   77 printBranchOperand ∷ BranchOperand → Text
   78 printBranchOperand  BTop           = ""
   79 printBranchOperand  BSwapped       = "S"
   80 printBranchOperand (BImmediate  i) = "I " <> show i
   81 printBranchOperand (BArtificial i) = "A " <> show i
   82 
   83 printLabelOperand ∷ LabelOperand → Text
   84 printLabelOperand  LTop           = ""
   85 printLabelOperand (LImmediate  i) = "I " <> show i
   86 printLabelOperand (LArtificial i) = "A " <> show i