~jojo/Carth

283eb4840fa8cbce85e1476e685c7d62443ff958 — JoJo 1 year, 10 months ago 89feacb
Remove not-really-needed deps llvm-hs-pretty & prettyprinter

They weren't unused, but very unimportant. We can do things in a very
slightly worse way if it means simplifying our dependency graph!
6 files changed, 8 insertions(+), 33 deletions(-)

M package.yaml
M src/Abi.hs
M src/Codegen.hs
M src/Compile.hs
M src/Misc.hs
M src/TypeErr.hs
M package.yaml => package.yaml +0 -2
@@ 28,12 28,10 @@ dependencies:
- microlens-platform
- llvm-hs-pure
- llvm-hs
- llvm-hs-pretty
- filepath
- directory
- bytestring
- utf8-string
- prettyprinter
- process

library:

M src/Abi.hs => src/Abi.hs +1 -1
@@ 181,7 181,7 @@ alignmentof = \case
    t@(StructureType _ us) -> do
        as <- traverse alignmentof us
        if null as
            then ice ("alignmentof: alignments empty for struct " ++ pretty t)
            then ice ("alignmentof: alignments empty for struct " ++ show t)
            else pure (maximum as)
    VectorType _ u -> alignmentof u
    ArrayType _ u -> alignmentof u

M src/Codegen.hs => src/Codegen.hs +4 -6
@@ 768,9 768,7 @@ extractvalue struct is = fmap
        NamedTypeReference x -> getMembers =<< lift (lookupDatatype x)
        StructureType _ members -> pure members
        t ->
            ice
                $ "Tried to get member types of non-struct type "
                ++ pretty t
            ice $ "Tried to get member types of non-struct type " ++ show t

store :: Operand -> Operand -> Instruction
store srcVal destPtr = Store


@@ 853,17 851,17 @@ typeUnit = StructureType { isPacked = False, elementTypes = [] }
getFunRet :: Type -> Type
getFunRet = \case
    FunctionType rt _ _ -> rt
    t -> ice $ "Tried to get return type of non-function type " ++ pretty t
    t -> ice $ "Tried to get return type of non-function type " ++ show t

getPointee :: Type -> Type
getPointee = \case
    LLType.PointerType t _ -> t
    t -> ice $ "Tried to get pointee of non-function type " ++ pretty t
    t -> ice $ "Tried to get pointee of non-function type " ++ show t

getIntBitWidth :: Type -> Word32
getIntBitWidth = \case
    LLType.IntegerType w -> w
    t -> ice $ "Tried to get bit width of non-integer type " ++ pretty t
    t -> ice $ "Tried to get bit width of non-integer type " ++ show t

mangleName :: (String, [MonoAst.Type]) -> String
mangleName (x, us) = x ++ mangleInst us

M src/Compile.hs => src/Compile.hs +2 -4
@@ 11,7 11,6 @@ import qualified LLVM.Relocation as Reloc
import qualified LLVM.CodeModel as CodeModel
import qualified LLVM.CodeGenOpt as CodeGenOpt

import Misc
import qualified MonoAst
import Codegen



@@ 33,7 32,6 @@ compile f cfg pgm = withContext $ \c -> withHostTargetMachinePIC $ \t -> do
    layout <- getTargetMachineDataLayout t
    putStrLn ("   Generating LLVM")
    let mod' = codegen layout f pgm
    writeFile ".dbg.out.dbgll" (pretty mod')
    withModuleFromAST c mod' (compileModule t cfg)

compileModule :: TargetMachine -> CompileConfig -> Module -> IO ()


@@ 56,8 54,8 @@ compileModule t cfg m = do
        , "-lpthread"
        ]

-- | `writeLLVMAssemblyToFile` doesn't clear file contents before writing, so this
--   is a workaround.
-- | `writeLLVMAssemblyToFile` doesn't clear file contents before writing, so
--   this is a workaround.
--
--   If the file was previously 100 lines of data, and the new LLVM-assembly is
--   70 lines, the first 70 lines will be overwritten, but the remaining 30 will

M src/Misc.hs => src/Misc.hs +0 -19
@@ 4,7 4,6 @@ module Misc
    ( ice
    , nyi
    , precalate
    , prettyPrint
    , pretty
    , Pretty(..)
    , indent


@@ 31,10 30,6 @@ import Control.Monad.State
import Lens.Micro.Platform (Lens, Lens', over, set, use, modifying)
import Data.Bitraversable
import System.Exit
import LLVM.AST.Type (Type)
import LLVM.AST (Name, Module)
import LLVM.Pretty ()
import qualified Data.Text.Prettyprint.Doc as Prettyprint
import qualified Text.Megaparsec as Mega
import Text.Megaparsec hiding (parse, match)
import Text.Megaparsec.Char hiding (space, space1)


@@ 53,10 48,6 @@ precalate prefix = \case
    [] -> []
    xs -> prefix ++ intercalate prefix xs

-- Pretty printing
prettyPrint :: Pretty a => a -> IO ()
prettyPrint = putStrLn . pretty

pretty :: Pretty a => a -> String
pretty = pretty' 0



@@ 64,16 55,6 @@ pretty = pretty' 0
class Pretty a where
    pretty' :: Int -> a -> String

instance Pretty String where
    pretty' _ = id

instance Pretty Type where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Name where
    pretty' _ = show . Prettyprint.pretty
instance Pretty Module where
    pretty' _ = show . Prettyprint.pretty

indent :: Int -> String
indent = flip replicate ' '


M src/TypeErr.hs => src/TypeErr.hs +1 -1
@@ 108,7 108,7 @@ printErr = \case
            $ ("Non-function variable definition `" ++ x ++ "` is recursive.")
    TypeInstArityMismatch p t expected found ->
        posd p tokenTree
            $ ("Arity mismatch for instantiation of type `" ++ pretty t)
            $ ("Arity mismatch for instantiation of type `" ++ t)
            ++ ("`.\nExpected " ++ show expected)
            ++ (", found " ++ show found)
    ConflictingVarDef p x ->