From bea731ff833bb35772448bb6b3a6ccae2aad7856 Mon Sep 17 00:00:00 2001 From: Langston Barrett Date: Sun, 15 May 2022 10:41:11 -0400 Subject: [PATCH 1/3] Add DWARF address space to DIDerivedType (added in LLVM 5) This lays the foundation towards an eventual fix for https://github.com/GaloisInc/llvm-pretty-bc-parser/issues/85. GitHub commit: https://github.com/llvm/llvm-project/commit/d5561e0a0bbd484da17d3b68ae5fedc0a057246b It's an unsigned int: https://github.com/llvm/llvm-project/blob/d5561e0a0bbd484da17d3b68ae5fedc0a057246b/llvm/include/llvm/IR/DebugInfoMetadata.h#L783 Co-authored-by: Ryan Scott --- src/Text/LLVM/AST.hs | 5 +++++ src/Text/LLVM/PP.hs | 1 + 2 files changed, 6 insertions(+) diff --git a/src/Text/LLVM/AST.hs b/src/Text/LLVM/AST.hs index 29aca19..552fd6d 100644 --- a/src/Text/LLVM/AST.hs +++ b/src/Text/LLVM/AST.hs @@ -1287,6 +1287,11 @@ data DIDerivedType' lab = DIDerivedType , didtOffset :: Word64 , didtFlags :: DIFlags , didtExtraData :: Maybe (ValMd' lab) + , didtDwarfAddressSpace :: Maybe Word32 + -- ^ Introduced in LLVM 5. + -- + -- The 'Maybe' encodes the possibility that there is no associated address + -- space (in LLVM, the sentinel value @0@ is used for this). } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DIDerivedType = DIDerivedType' BlockLabel diff --git a/src/Text/LLVM/PP.hs b/src/Text/LLVM/PP.hs index 5bd6afb..eb8f9eb 100644 --- a/src/Text/LLVM/PP.hs +++ b/src/Text/LLVM/PP.hs @@ -1070,6 +1070,7 @@ ppDIDerivedType' pp dt = "!DIDerivedType" , pure ("offset:" <+> integral (didtOffset dt)) , pure ("flags:" <+> integral (didtFlags dt)) , (("extraData:" <+>) . ppValMd' pp) <$> (didtExtraData dt) + , (("dwarfAddressSpace:" <+>) . integral) <$> didtDwarfAddressSpace dt ]) ppDIDerivedType :: LLVM => DIDerivedType -> Doc From 22a2c227341011ebc2b6831e87468f1890218c3e Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sun, 15 May 2022 11:13:07 -0400 Subject: [PATCH 2/3] Add alignment to DILocalVariable This paves the way for an eventual fix to https://github.com/GaloisInc/llvm-pretty-bc-parser/issues/217. --- src/Text/LLVM/AST.hs | 2 ++ src/Text/LLVM/PP.hs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/Text/LLVM/AST.hs b/src/Text/LLVM/AST.hs index 552fd6d..525bee5 100644 --- a/src/Text/LLVM/AST.hs +++ b/src/Text/LLVM/AST.hs @@ -1353,6 +1353,8 @@ data DILocalVariable' lab = DILocalVariable , dilvType :: Maybe (ValMd' lab) , dilvArg :: Word16 , dilvFlags :: DIFlags + , dilvAlignment :: Maybe Word32 + -- ^ Introduced in LLVM 4. } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DILocalVariable = DILocalVariable' BlockLabel diff --git a/src/Text/LLVM/PP.hs b/src/Text/LLVM/PP.hs index eb8f9eb..d46f48d 100644 --- a/src/Text/LLVM/PP.hs +++ b/src/Text/LLVM/PP.hs @@ -1156,6 +1156,7 @@ ppDILocalVariable' pp lv = "!DILocalVariable" , (("type:" <+>) . ppValMd' pp) <$> (dilvType lv) , pure ("arg:" <+> integral (dilvArg lv)) , pure ("flags:" <+> integral (dilvFlags lv)) + , (("align:" <+>) . integral) <$> dilvAlignment lv ]) ppDILocalVariable :: LLVM => DILocalVariable -> Doc From f06ba63f679718e6964e471c803b9e4bcc108282 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sun, 15 May 2022 09:58:49 -0400 Subject: [PATCH 3/3] Add support for `btf_tag` annotations This paves the way for an eventual fix for https://github.com/GaloisInc/llvm-pretty-bc-parser/issues/188. --- src/Text/LLVM/AST.hs | 10 ++++++++++ src/Text/LLVM/PP.hs | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/src/Text/LLVM/AST.hs b/src/Text/LLVM/AST.hs index 525bee5..456e591 100644 --- a/src/Text/LLVM/AST.hs +++ b/src/Text/LLVM/AST.hs @@ -1271,6 +1271,8 @@ data DICompositeType' lab = DICompositeType , dictAssociated :: Maybe (ValMd' lab) , dictAllocated :: Maybe (ValMd' lab) , dictRank :: Maybe (ValMd' lab) + , dictAnnotations :: Maybe (ValMd' lab) + -- ^ Introduced in LLVM 14. } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DICompositeType = DICompositeType' BlockLabel @@ -1292,6 +1294,8 @@ data DIDerivedType' lab = DIDerivedType -- -- The 'Maybe' encodes the possibility that there is no associated address -- space (in LLVM, the sentinel value @0@ is used for this). + , didtAnnotations :: Maybe (ValMd' lab) + -- ^ Introduced in LLVM 14 } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DIDerivedType = DIDerivedType' BlockLabel @@ -1317,6 +1321,8 @@ data DIGlobalVariable' lab = DIGlobalVariable , digvVariable :: Maybe (ValMd' lab) , digvDeclaration :: Maybe (ValMd' lab) , digvAlignment :: Maybe Word32 + , digvAnnotations :: Maybe (ValMd' lab) + -- ^ Introduced in LLVM 14. } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DIGlobalVariable = DIGlobalVariable' BlockLabel @@ -1355,6 +1361,8 @@ data DILocalVariable' lab = DILocalVariable , dilvFlags :: DIFlags , dilvAlignment :: Maybe Word32 -- ^ Introduced in LLVM 4. + , dilvAnnotations :: Maybe (ValMd' lab) + -- ^ Introduced in LLVM 14. } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DILocalVariable = DILocalVariable' BlockLabel @@ -1380,6 +1388,8 @@ data DISubprogram' lab = DISubprogram , dispDeclaration :: Maybe (ValMd' lab) , dispRetainedNodes :: Maybe (ValMd' lab) , dispThrownTypes :: Maybe (ValMd' lab) + , dispAnnotations :: Maybe (ValMd' lab) + -- ^ Introduced in LLVM 14. } deriving (Data, Eq, Functor, Generic, Generic1, Ord, Show, Typeable) type DISubprogram = DISubprogram' BlockLabel diff --git a/src/Text/LLVM/PP.hs b/src/Text/LLVM/PP.hs index d46f48d..6bd97e3 100644 --- a/src/Text/LLVM/PP.hs +++ b/src/Text/LLVM/PP.hs @@ -1052,6 +1052,7 @@ ppDICompositeType' pp ct = "!DICompositeType" , (("associated:" <+>) . ppValMd' pp) <$> (dictAssociated ct) , (("allocated:" <+>) . ppValMd' pp) <$> (dictAllocated ct) , (("rank:" <+>) . ppValMd' pp) <$> (dictRank ct) + , (("annotations:" <+>) . ppValMd' pp) <$> (dictAnnotations ct) ]) ppDICompositeType :: LLVM => DICompositeType -> Doc @@ -1071,6 +1072,7 @@ ppDIDerivedType' pp dt = "!DIDerivedType" , pure ("flags:" <+> integral (didtFlags dt)) , (("extraData:" <+>) . ppValMd' pp) <$> (didtExtraData dt) , (("dwarfAddressSpace:" <+>) . integral) <$> didtDwarfAddressSpace dt + , (("annotations:" <+>) . ppValMd' pp) <$> (didtAnnotations dt) ]) ppDIDerivedType :: LLVM => DIDerivedType -> Doc @@ -1108,6 +1110,7 @@ ppDIGlobalVariable' pp gv = "!DIGlobalVariable" , (("variable:" <+>) . ppValMd' pp) <$> (digvVariable gv) , (("declaration:" <+>) . ppValMd' pp) <$> (digvDeclaration gv) , (("align:" <+>) . integral) <$> digvAlignment gv + , (("annotations:" <+>) . ppValMd' pp) <$> (digvAnnotations gv) ]) ppDIGlobalVariable :: LLVM => DIGlobalVariable -> Doc @@ -1157,6 +1160,7 @@ ppDILocalVariable' pp lv = "!DILocalVariable" , pure ("arg:" <+> integral (dilvArg lv)) , pure ("flags:" <+> integral (dilvFlags lv)) , (("align:" <+>) . integral) <$> dilvAlignment lv + , (("annotations:" <+>) . ppValMd' pp) <$> (dilvAnnotations lv) ]) ppDILocalVariable :: LLVM => DILocalVariable -> Doc @@ -1189,6 +1193,7 @@ ppDISubprogram' pp sp = "!DISubprogram" , (("declaration:" <+>) . ppValMd' pp) <$> (dispDeclaration sp) , (("retainedNodes:" <+>) . ppValMd' pp) <$> (dispRetainedNodes sp) , (("thrownTypes:" <+>) . ppValMd' pp) <$> (dispThrownTypes sp) + , (("annotations:" <+>) . ppValMd' pp) <$> (dispAnnotations sp) ]) ppDISubprogram :: LLVM => DISubprogram -> Doc