From 5fcb5238188f8257fb19bb0b658874f806351b82 Mon Sep 17 00:00:00 2001 From: Langston Barrett Date: Thu, 6 Dec 2018 16:51:50 -0800 Subject: [PATCH 1/2] Fix DITemplateTypeParameter and DITemplateValueParameter Tested and working on a _very_ large C++ program. Fixes #43, text copied from that issue: -------------------------------------------------------- Okay, this particular node has an especially twisted history. 0. [Feb 12, 2015](https://github.com/llvm-mirror/llvm/commit/8921bbca59c0ab2bc63988558a38c9546c638755): `MDTemplateTypeParameter` lands. It's fields have type i. `Num` ii. `Maybe PValMd` iii. `MDString` iv. `Maybe PValMd` v. `Maybe PValMd` 1. [Feb 18, 2015](https://github.com/llvm-mirror/llvm/commit/eac950e4085c349f0ac06ecab4854e175c7d92d4 ): The last field, "scope", was dropped, and the type of the second field was made into a `MDString`. 2. [Apr 23, 2016](https://github.com/llvm-mirror/llvm/commit/de7484036b628b08be6acbfb5feac405d7450300): Removal of MDString-based references (see #39). Third field is made into a `DITypeRef`. Interestingly, at no point in this process does the field only have three fields, [as it does in the AST](https://github.com/elliottt/llvm-pretty/blob/de881be8e97bc085150d816d359599d75ad3ac9b/src/Text/LLVM/AST.hs#L1100). The biggest flaw I'm seeing is that the first field of the record _is not a reference_, but it is looked up as if it is one. This is causing the parser to crash, because the reference is not defined. --- src/Text/LLVM/AST.hs | 9 +++++---- src/Text/LLVM/PP.hs | 15 ++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Text/LLVM/AST.hs b/src/Text/LLVM/AST.hs index 58cac99..bcd477e 100644 --- a/src/Text/LLVM/AST.hs +++ b/src/Text/LLVM/AST.hs @@ -1092,14 +1092,15 @@ data DIImportedEntity' lab = DIImportedEntity type DITemplateTypeParameter = DITemplateTypeParameter' BlockLabel data DITemplateTypeParameter' lab = DITemplateTypeParameter - { dittpName :: String - , dittpType :: ValMd' lab + { dittpName :: Maybe String + , dittpType :: Maybe (ValMd' lab) } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DITemplateValueParameter = DITemplateValueParameter' BlockLabel data DITemplateValueParameter' lab = DITemplateValueParameter - { ditvpName :: String - , ditvpType :: ValMd' lab + { ditvpTag :: DwarfTag + , ditvpName :: Maybe String + , ditvpType :: Maybe (ValMd' lab) , ditvpValue :: ValMd' lab } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) diff --git a/src/Text/LLVM/PP.hs b/src/Text/LLVM/PP.hs index 6cd2d05..ac0b23c 100644 --- a/src/Text/LLVM/PP.hs +++ b/src/Text/LLVM/PP.hs @@ -867,19 +867,20 @@ ppDINameSpace = ppDINameSpace' ppLabel ppDITemplateTypeParameter' :: LLVM => (i -> Doc) -> DITemplateTypeParameter' i -> Doc ppDITemplateTypeParameter' pp tp = "!DITemplateTypeParameter" - <> parens (commas [ "name:" <+> text (dittpName tp) - , "type:" <+> ppValMd' pp (dittpType tp) - ]) + <> parens (mcommas [ ("name:" <+>) . text <$> dittpName tp + , ("type:" <+>) . ppValMd' pp <$> dittpType tp + ]) ppDITemplateTypeParameter :: LLVM => DITemplateTypeParameter -> Doc ppDITemplateTypeParameter = ppDITemplateTypeParameter' ppLabel ppDITemplateValueParameter' :: LLVM => (i -> Doc) -> DITemplateValueParameter' i -> Doc ppDITemplateValueParameter' pp vp = "!DITemplateValueParameter" - <> parens (commas [ "name:" <+> text (ditvpName vp) - , "type:" <+> ppValMd' pp (ditvpType vp) - , "value:" <+> ppValMd' pp (ditvpValue vp) - ]) + <> parens (mcommas [ pure ("tag:" <+> integral (ditvpTag vp)) + , ("name:" <+>) . text <$> ditvpName vp + , ("type:" <+>) . ppValMd' pp <$> ditvpType vp + , pure ("value:" <+> ppValMd' pp (ditvpValue vp)) + ]) ppDITemplateValueParameter :: LLVM => DITemplateValueParameter -> Doc ppDITemplateValueParameter = ppDITemplateValueParameter' ppLabel From 6219d6ac1b32a824402dae78aaee52109d36d792 Mon Sep 17 00:00:00 2001 From: Langston Barrett Date: Thu, 6 Dec 2018 16:56:40 -0800 Subject: [PATCH 2/2] Bump version to 0.7.7 This is so the bitcode parser can depend on a version with current support for DITemplate(Type|Value)Parameter, see last commit --- llvm-pretty.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm-pretty.cabal b/llvm-pretty.cabal index 0bf66f6..cebe3c9 100644 --- a/llvm-pretty.cabal +++ b/llvm-pretty.cabal @@ -1,5 +1,5 @@ Name: llvm-pretty -Version: 0.7.6 +Version: 0.7.7 License: BSD3 License-file: LICENSE Author: Trevor Elliott