Commit 85e09b1b authored by Ben Gamari's avatar Ben Gamari 🐢

llvmGen: Consolidate MetaExpr pretty-printing

Previously this logic was duplicated needlessly.
parent 2396d9bb
......@@ -72,10 +72,11 @@ data MetaExpr = MetaStr LMString
deriving (Eq)
instance Outputable MetaExpr where
ppr (MetaStr s ) = text "!\"" <> ftext s <> char '"'
ppr (MetaVar (LMLitVar (LMNullLit _))) = text "null"
ppr (MetaStr s ) = char '!' <> doubleQuotes (ftext s)
ppr (MetaNode n ) = ppr n
ppr (MetaVar v ) = ppr v
ppr (MetaStruct es) = text "!{ " <> ppCommaJoin es <> char '}'
ppr (MetaStruct es) = char '!' <> braces (ppCommaJoin es)
-- | Associates some metadata with a specific label for attaching to an
-- instruction.
......
......@@ -107,22 +107,13 @@ ppLlvmMetas metas = vcat $ map ppLlvmMeta metas
-- | Print out an LLVM metadata definition.
ppLlvmMeta :: MetaDecl -> SDoc
ppLlvmMeta (MetaUnnamed n m)
= ppr n <> text " = " <> ppLlvmMetaExpr m
= ppr n <+> equals <+> ppr m
ppLlvmMeta (MetaNamed n m)
= exclamation <> ftext n <> text " = !" <> braces nodes
= exclamation <> ftext n <+> equals <+> exclamation <> braces nodes
where
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 ) = ppr n
ppLlvmMetaExpr (MetaVar v ) = ppr v
ppLlvmMetaExpr (MetaStruct es) =
text "!{" <> hsep (punctuate comma (map ppLlvmMetaExpr es)) <> char '}'
-- | Print out a list of function definitions.
ppLlvmFunctions :: LlvmFunctions -> SDoc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment