<commit_before>{- |
Module      : $Header$
Description : Parses a REIL text file
Maintainer  : <NAME>
Stability   : experimental
-}

-- | This module parses a text file containing REIL instructions.

module Data.REIL.Parse (
    parseReilFile,
) where

import Text.Parsec
import Text.Parsec.String

import Control.Applicative hiding ((<|>), many)

import Numeric (readHex)

import qualified Data.REIL.InstructionSet as IS
import qualified Data.REIL.BasicBlock as BB
import qualified Data.REIL.CFG as CFG

-------------------------------------------------------------------------------
-- Helper functions
-------------------------------------------------------------------------------

-- Applicative cons (is this name accurate?)
(<:>) :: Applicative f => f a -> f [a] -> f [a]
h <:> t =
    (:) <$> h <*> t

-- Parse 1 or more digits
digits :: Parser String
digits =
    many1 digit

-------------------------------------------------------------------------------

-- | Parse an address. An address is represented as a hexadecimal integer. E.g.
-- @0000100015C20700@
address :: Parser IS.Address
address =
    do
        addr <- many1 hexDigit
        let ((hexInt, _) : _) = readHex addr
        return hexInt

-- Type synonym for convienience
type InstructionConstructor = IS.Operand -> IS.Operand -> IS.Operand -> IS.Instruction

-- | Valid REIL instructions
instructionConstructor :: Parser InstructionConstructor
instructionConstructor =
    (IS.Add <$ try (string "add"))
    <|> (IS.And <$ try (string "and"))
    <|> (IS.Bisz <$ try (string "bisz"))
    <|> (IS.Bsh <$ try (string "bsh"))
    <|> (IS.Div <$ try (string "div"))
    <|> (IS.Jcc <$ try (string "jcc"))
    <|> (IS.Ldm <$ try (string "ldm"))
    <|> (IS.Mod <$ try (string "mod"))
    <|> (IS.Mul <$ try (string "mul"))
    <|> (IS.Nop <$ try (string "nop"))
    <|> (IS.Or <$ try (string "or"))
    <|> (IS.Stm <$ try (string "stm"))<commit_msg>Fixed bug with parse module exports<commit_after>{- |
Module      : $Header$
Description : Parses a REIL text file
Maintainer  : <NAME>
Stability   : experimental
-}

-- | This module parses a text file containing REIL instructions.

module Data.REIL.Parse (
    -- TODO
) where

import Text.Parsec
import Text.Parsec.String

import Control.Applicative hiding ((<|>), many)

import Numeric (readHex)

import qualified Data.REIL.InstructionSet as IS
import qualified Data.REIL.BasicBlock as BB
import qualified Data.REIL.CFG as CFG

-------------------------------------------------------------------------------
-- Helper functions
-------------------------------------------------------------------------------

-- Applicative cons (is this name accurate?)
(<:>) :: Applicative f => f a -> f [a] -> f [a]
h <:> t =
    (:) <$> h <*> t

-- Parse 1 or more digits
digits :: Parser String
digits =
    many1 digit

-------------------------------------------------------------------------------

-- | Parse an address. An address is represented as a hexadecimal integer. E.g.
-- @0000100015C20700@
address :: Parser IS.Address
address =
    do
        addr <- many1 hexDigit
        let ((hexInt, _) : _) = readHex addr
        return hexInt

-- Type synonym for convienience
type InstructionConstructor =
    IS.Operand -> IS.Operand -> IS.Operand -> IS.Instruction

-- | Valid REIL instructions
instructionConstructor :: Parser InstructionConstructor
instructionConstructor =
    (IS.Add <$ try (string "add"))
    <|> (IS.And <$ try (string "and"))
    <|> (IS.Bisz <$ try (string "bisz"))
    <|> (IS.Bsh <$ try (string "bsh"))
    <|> (IS.Div <$ try (string "div"))
    <|> (IS.Jcc <$ try (string "jcc"))
    <|> (IS.Ldm <$ try (string "ldm"))
    <|> (IS.Mod <$ try (string "mod"))
    <|> (IS.Mul <$ try (string "mul"))
    <|> (IS.Nop <$ try (string "nop"))
    <|> (IS.Or <$ try (string "or"))
    <|> (IS.Stm <$ try (string "stm"))
{'fraction_non_alphanumeric': 0.2635397771443379, 'fraction_numerical': 0.00932884166882612, 'mean_word_length': 1.9443173150266972, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1422626', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1166, 'n_words': 354}