diff options
author | Ben Gamari <ben@smart-cactus.org> | 2016-06-17 22:57:38 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-06-18 11:45:10 +0200 |
commit | 2396d9bb76c11775589fc91b362a61c4a92d27fa (patch) | |
tree | 8974307980358a9aadace3f9e60a5c1a25a4a832 /compiler/llvmGen/Llvm | |
parent | 3e8c495f2e6557c85c65c7fc91113f45b010d333 (diff) | |
download | haskell-2396d9bb76c11775589fc91b362a61c4a92d27fa.tar.gz |
llvmGen: Make metadata ids a newtype
These were previously just represented as Ints which was needlessly
vague.
Diffstat (limited to 'compiler/llvmGen/Llvm')
-rw-r--r-- | compiler/llvmGen/Llvm/MetaData.hs | 17 | ||||
-rw-r--r-- | compiler/llvmGen/Llvm/PpLlvm.hs | 11 |
2 files changed, 18 insertions, 10 deletions
diff --git a/compiler/llvmGen/Llvm/MetaData.hs b/compiler/llvmGen/Llvm/MetaData.hs index e1e63c9191..a50553ccb0 100644 --- a/compiler/llvmGen/Llvm/MetaData.hs +++ b/compiler/llvmGen/Llvm/MetaData.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} + module Llvm.MetaData where import Llvm.Types @@ -55,16 +57,23 @@ import Outputable -- !llvm.module.linkage = !{ !0, !1 } -- +-- | A reference to an un-named metadata node. +newtype MetaId = MetaId Int + deriving (Eq, Ord, Enum) + +instance Outputable MetaId where + ppr (MetaId n) = char '!' <> int n + -- | LLVM metadata expressions data MetaExpr = MetaStr LMString - | MetaNode Int + | MetaNode MetaId | MetaVar LlvmVar | MetaStruct [MetaExpr] deriving (Eq) instance Outputable MetaExpr where ppr (MetaStr s ) = text "!\"" <> ftext s <> char '"' - ppr (MetaNode n ) = text "!" <> int n + ppr (MetaNode n ) = ppr n ppr (MetaVar v ) = ppr v ppr (MetaStruct es) = text "!{ " <> ppCommaJoin es <> char '}' @@ -77,7 +86,7 @@ data MetaAnnot = MetaAnnot LMString MetaExpr data MetaDecl -- | Named metadata. Only used for communicating module information to -- LLVM. ('!name = !{ [!<n>] }' form). - = MetaNamed LMString [Int] + = MetaNamed LMString [MetaId] -- | Metadata node declaration. -- ('!0 = metadata !{ <metadata expression> }' form). - | MetaUnamed Int MetaExpr + | MetaUnnamed MetaId MetaExpr diff --git a/compiler/llvmGen/Llvm/PpLlvm.hs b/compiler/llvmGen/Llvm/PpLlvm.hs index cdaf962c4a..d92e3c0739 100644 --- a/compiler/llvmGen/Llvm/PpLlvm.hs +++ b/compiler/llvmGen/Llvm/PpLlvm.hs @@ -106,20 +106,19 @@ ppLlvmMetas metas = vcat $ map ppLlvmMeta metas -- | Print out an LLVM metadata definition. ppLlvmMeta :: MetaDecl -> SDoc -ppLlvmMeta (MetaUnamed n m) - = exclamation <> int n <> text " = " <> ppLlvmMetaExpr m +ppLlvmMeta (MetaUnnamed n m) + = ppr n <> text " = " <> ppLlvmMetaExpr m ppLlvmMeta (MetaNamed n m) = exclamation <> ftext n <> text " = !" <> braces nodes where - nodes = hcat $ intersperse comma $ map pprNode m - pprNode n = exclamation <> int n + nodes = hcat $ intersperse comma $ map ppr m -- | Print out an LLVM metadata value. ppLlvmMetaExpr :: MetaExpr -> SDoc ppLlvmMetaExpr (MetaVar (LMLitVar (LMNullLit _))) = text "null" ppLlvmMetaExpr (MetaStr s ) = text "!" <> doubleQuotes (ftext s) -ppLlvmMetaExpr (MetaNode n ) = text "!" <> int n +ppLlvmMetaExpr (MetaNode n ) = ppr n ppLlvmMetaExpr (MetaVar v ) = ppr v ppLlvmMetaExpr (MetaStruct es) = text "!{" <> hsep (punctuate comma (map ppLlvmMetaExpr es)) <> char '}' @@ -489,7 +488,7 @@ ppMetaAnnots meta = hcat $ map ppMeta meta ppMeta (MetaAnnot name e) = comma <+> exclamation <> ftext name <+> case e of - MetaNode n -> exclamation <> int n + MetaNode n -> ppr n MetaStruct ms -> exclamation <> braces (ppCommaJoin ms) other -> exclamation <> braces (ppr other) -- possible? |