Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing target triples #96

Merged
merged 27 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
78acfab
ASTs of target triples
langston-barrett Sep 22, 2022
e290161
Introduce Triple.Print
langston-barrett Sep 22, 2022
d68dfee
Triple.Print: osName
langston-barrett Sep 22, 2022
918a812
Triple.Print: envName
langston-barrett Sep 22, 2022
8d05747
Triple.Print: vendorName, objFmtName
langston-barrett Sep 22, 2022
f0994e4
Introduce Triple.Parse
langston-barrett Sep 22, 2022
15579af
Skeleton of test suite
langston-barrett Sep 22, 2022
dece9b9
Skeleton of triple tests
langston-barrett Sep 22, 2022
0a3e12e
Test print-then-parse roundtrip for Vendor
langston-barrett Sep 22, 2022
f6a9426
Fix return type of parseVendor
langston-barrett Sep 22, 2022
65c628e
Add a Haddock for parseVendor
langston-barrett Sep 22, 2022
2ec7334
Triple.Parse: Add parseOS
langston-barrett Sep 22, 2022
80ab2bc
Triple.Parse: Refactor, use a newtype for LookupTable
langston-barrett Sep 22, 2022
0f9a66f
Triple.Parse: Add parseEnv
langston-barrett Sep 22, 2022
4c89c59
Triple.Parse: Add parseObjFmt
langston-barrett Sep 22, 2022
a7fd08b
Triple.Parse: More Haddocks for internal helpers
langston-barrett Sep 22, 2022
5826948
Triple.Parse: Introduce lookupByWithDefault
langston-barrett Sep 22, 2022
ea6f361
Triple.Parse: Introduce variants
langston-barrett Sep 22, 2022
6f74820
Triple.Parse: Arch
langston-barrett Sep 22, 2022
cc934e1
Triple.Parse: Towards parseSubArch
langston-barrett Sep 23, 2022
c973d98
Fix Monoid instance for Module to actually be pointwise
langston-barrett Sep 23, 2022
e79b7b9
Triple.Parse.ARM: parseArch
langston-barrett Sep 23, 2022
8b0647b
Triple.Parse: Finish parseSubArch
langston-barrett Sep 23, 2022
a74f017
Triple.Parse: parseTriple
langston-barrett Sep 23, 2022
026eda1
Triple.Parse.ARM: Remove redundant case
langston-barrett Sep 23, 2022
b8aa843
Triple.Parse: Fix parsing of object formats
langston-barrett Sep 23, 2022
d1d937c
Insert issue numbers in TODO comments
langston-barrett Sep 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions llvm-pretty.cabal
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Cabal-version: 2.2
Name: llvm-pretty
Version: 0.11.0
License: BSD3
License: BSD-3-Clause
License-file: LICENSE
Author: Trevor Elliott
Maintainer: [email protected]
Category: Text
Build-type: Simple
Cabal-version: >=1.16
Synopsis: A pretty printing library inspired by the llvm binding.
Description:
A pretty printing library that was inspired by the LLVM binding by Lennart
Expand All @@ -20,8 +20,13 @@ source-repository head
type: git
location: http://github.com/elliottt/llvm-pretty

Library
common common
Default-language: Haskell2010
Ghc-options:
-Wall

Library
Import: common

Hs-source-dirs: src
Exposed-modules: Text.LLVM
Expand All @@ -32,7 +37,13 @@ Library
Text.LLVM.Parser
Text.LLVM.PP
Text.LLVM.DebugUtils
Other-modules: Text.LLVM.Util
Text.LLVM.Triple
Text.LLVM.Triple.AST
Text.LLVM.Triple.Parse
Text.LLVM.Triple.Print
Other-modules: Text.LLVM.Triple.Parse.ARM
Text.LLVM.Triple.Parse.LookupTable
Text.LLVM.Util

Build-depends: base >= 4.9 && < 5,
containers >= 0.4,
Expand All @@ -44,4 +55,17 @@ Library
template-haskell >= 2.7,
th-abstraction >= 0.3.1 && <0.5

Ghc-options: -Wall
Test-suite llvm-pretty-test
Import: common
Type: exitcode-stdio-1.0
Main-is: Main.hs
Other-modules:
Triple
Hs-source-dirs: test
Ghc-options:
-threaded
Build-depends:
llvm-pretty,
base,
tasty,
tasty-hunit
6 changes: 6 additions & 0 deletions src/Text/LLVM/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import Language.Haskell.TH.Syntax (Lift)
import Text.Parsec
import Text.Parsec.String

import Text.LLVM.Triple.AST (TargetTriple)


-- Modules ---------------------------------------------------------------------

data Module = Module
{ modSourceName :: Maybe String
, modTriple :: TargetTriple -- ^ target triple
, modDataLayout :: DataLayout -- ^ type size and alignment information
, modTypes :: [TypeDecl] -- ^ top-level type aliases
, modNamedMd :: [NamedMd]
Expand All @@ -40,9 +43,11 @@ data Module = Module
, modAliases :: [GlobalAlias]
} deriving (Data, Eq, Ord, Generic, Show, Typeable)

-- | Combines fields pointwise.
instance Sem.Semigroup Module where
m1 <> m2 = Module
{ modSourceName = modSourceName m1 `mplus` modSourceName m2
, modTriple = modTriple m1 <> modTriple m2
, modDataLayout = modDataLayout m1 <> modDataLayout m2
, modTypes = modTypes m1 <> modTypes m2
, modUnnamedMd = modUnnamedMd m1 <> modUnnamedMd m2
Expand All @@ -62,6 +67,7 @@ instance Monoid Module where
emptyModule :: Module
emptyModule = Module
{ modSourceName = mempty
, modTriple = mempty
, modDataLayout = mempty
, modTypes = mempty
, modNamedMd = mempty
Expand Down
17 changes: 17 additions & 0 deletions src/Text/LLVM/Triple.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{- |
Module : Text.LLVM.Triple
Description : AST, parsing, and printing of LLVM target triples.
License : BSD3
Maintainer : Langston Barrett
Stability : experimental
-}

module Text.LLVM.Triple
( module Text.LLVM.Triple.AST
, module Text.LLVM.Triple.Parse
, module Text.LLVM.Triple.Print
) where

import Text.LLVM.Triple.AST
import Text.LLVM.Triple.Parse
import Text.LLVM.Triple.Print
Loading