<commit_before>{- |
Module      : Backend
Description : Converts the internal LLVM representation into textual LLVM IR.
Maintainer  : <NAME>, <NAME>, <NAME>
License     : MIT

Uses the LLVM bindings for Haskell to convert the internal LLVM representation
(provided by the bindings themselves) into the final, textual LLVM IR.

Does not do any linking.
-}
module Backend (
                process   -- main function of the module "Backend"
               )
where

-- imports --
import InterfaceDT as IDT
import ErrorHandling as EH

import LLVM.General.AST
import qualified LLVM.General.AST as AST
import LLVM.General.Context
import LLVM.General.Module
import Control.Monad.Error
import LLVM.General.AST.Global


-- functions --
-- |Converts the internal LLVM representation into textual LLVM IR.
process :: IDT.CodeOpt2Backend -> IDT.Backend2Output
process input = output
  where
    output = IDT.IBO $ generateOutput input

-- |Uses the Haskell LLVM bindings to convert the internal LLVM
-- representation into textual LLVM IR.
generateOutput :: IDT.CodeOpt2Backend -> IO String
generateOutput (IDT.ICB mod) = do
  s <- withContext $ \context ->
    runErrorT $ withModuleFromAST context mod $ \m -> moduleLLVMAssembly m
  either error return s
<commit_msg>simplify backend code a bit more; sort imports<commit_after>{- |
Module      : Backend
Description : Converts the internal LLVM representation into textual LLVM IR.
Maintainer  : <NAME>, <NAME>, <NAME>
License     : MIT

Uses the LLVM bindings for Haskell to convert the internal LLVM representation
(provided by the bindings themselves) into the final, textual LLVM IR.

Does not do any linking.
-}
module Backend (
                process   -- main function of the module "Backend"
               )
where

-- imports --
import ErrorHandling as EH
import InterfaceDT as IDT

import Control.Monad.Error
import LLVM.General.AST
import LLVM.General.AST.Global
import LLVM.General.Context
import LLVM.General.Module
import qualified LLVM.General.AST as AST

-- functions --
-- |Converts the internal LLVM representation into textual LLVM IR.
process :: IDT.CodeOpt2Backend -> IDT.Backend2Output
process input = IDT.IBO $ generateOutput input

-- |Uses the Haskell LLVM bindings to convert the internal LLVM
-- representation into textual LLVM IR.
generateOutput :: IDT.CodeOpt2Backend -> IO String
generateOutput (IDT.ICB mod) = do
  s <- withContext $ \context ->
    runErrorT $ withModuleFromAST context mod $ \m -> moduleLLVMAssembly m
  either error return s

{'fraction_non_alphanumeric': 0.07386814932486101, 'fraction_numerical': 0.0023828435266084196, 'mean_word_length': 3.506261180679785, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '1654888', 'n_tokens_mistral': 730, 'n_tokens_neox': 697, 'n_words': 282}