Skip to content

Commit

Permalink
Fix DITemplateTypeParameter and DITemplateValueParameter
Browse files Browse the repository at this point in the history
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](llvm-mirror/llvm@8921bbc): `MDTemplateTypeParameter` lands. It's fields have type
    i. `Num`
   ii. `Maybe PValMd`
   iii. `MDString`
   iv. `Maybe PValMd`
    v. `Maybe PValMd`
 1. [Feb 18, 2015](llvm-mirror/llvm@eac950e ): The last field, "scope", was dropped, and the type of the second field was made into a `MDString`.
 2. [Apr 23, 2016](llvm-mirror/llvm@de74840): 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.
  • Loading branch information
langston-barrett committed Dec 7, 2018
1 parent de881be commit 5fcb523
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/Text/LLVM/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 8 additions & 7 deletions src/Text/LLVM/PP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fcb523

Please sign in to comment.