Skip to content

Commit

Permalink
Merge pull request #121 from elliottt/dgb_1691441044-0
Browse files Browse the repository at this point in the history
Fix issue #113 and #114
  • Loading branch information
kquick committed Aug 7, 2023
2 parents e586747 + d229beb commit 7f5631f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion llvm-pretty.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cabal-version: 2.2
Name: llvm-pretty
Version: 0.11.0.0.100
Version: 0.11.0.0.101
License: BSD-3-Clause
License-file: LICENSE
Author: Trevor Elliott
Expand Down
1 change: 1 addition & 0 deletions src/Text/LLVM/AST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,7 @@ data DICompileUnit' lab = DICompileUnit
, dicuSplitDebugInlining :: Bool
, dicuDebugInfoForProf :: Bool
, dicuNameTableKind :: Word64
-- added in LLVM 11: dicuRangesBaseAddress, dicuSysRoot, and dicuSDK
, dicuRangesBaseAddress :: Bool
, dicuSysRoot :: Maybe String
, dicuSDK :: Maybe String
Expand Down
21 changes: 14 additions & 7 deletions src/Text/LLVM/PP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ ppLLVM36 = withConfig Config { cfgVer = llvmV3_6 }
ppLLVM37 = withConfig Config { cfgVer = llvmV3_7 }
ppLLVM38 = withConfig Config { cfgVer = llvmV3_8 }

checkConfig :: (?config :: Config) => (Config -> Bool) -> Bool
checkConfig p = p ?config

llvmVer :: (?config :: Config) => LLVMVer
llvmVer = cfgVer ?config

-- | This is a helper function for when a list of parameters is gated by a
-- condition (usually the llvmVer value).
when' :: Monoid a => Bool -> a -> a
when' c l = if c then l else mempty


-- | This type encapsulates the ability to convert an object into Doc
-- format. Using this abstraction allows for a consolidated representation of the
Expand Down Expand Up @@ -971,7 +973,7 @@ ppDIImportedEntity = ppDIImportedEntity' ppLabel
ppDILabel' :: Fmt i -> Fmt (DILabel' i)
ppDILabel' pp ie = "!DILabel"
<> parens (mcommas [ (("scope:" <+>) . ppValMd' pp) <$> dilScope ie
, pure ("name:" <+> text (dilName ie))
, pure ("name:" <+> ppStringLiteral (dilName ie))
, (("file:" <+>) . ppValMd' pp) <$> dilFile ie
, pure ("line:" <+> integral (dilLine ie))
])
Expand Down Expand Up @@ -1025,7 +1027,7 @@ ppDIBasicType bt = "!DIBasicType"

ppDICompileUnit' :: Fmt i -> Fmt (DICompileUnit' i)
ppDICompileUnit' pp cu = "!DICompileUnit"
<> parens (mcommas
<> parens (mcommas $
[ pure ("language:" <+> integral (dicuLanguage cu))
, (("file:" <+>) . ppValMd' pp) <$> (dicuFile cu)
, (("producer:" <+>) . doubleQuotes . text)
Expand All @@ -1046,12 +1048,17 @@ ppDICompileUnit' pp cu = "!DICompileUnit"
, pure ("splitDebugInlining:" <+> ppBool (dicuSplitDebugInlining cu))
, pure ("debugInfoForProfiling:" <+> ppBool (dicuDebugInfoForProf cu))
, pure ("nameTableKind:" <+> integral (dicuNameTableKind cu))
, pure ("rangesBaseAddress:" <+> ppBool (dicuRangesBaseAddress cu))
]
++
when' (llvmVer >= 11)
[ pure ("rangesBaseAddress:" <+> ppBool (dicuRangesBaseAddress cu))
, (("sysroot:" <+>) . doubleQuotes . text)
<$> (dicuSysRoot cu)
, (("sdk:" <+>) . doubleQuotes . text)
<$> (dicuSDK cu)
])
]
)


ppDICompileUnit :: Fmt DICompileUnit
ppDICompileUnit = ppDICompileUnit' ppLabel
Expand Down
43 changes: 38 additions & 5 deletions test/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ tests = Tasty.testGroup "LLVM pretty-printing output tests"
dwoId: 2,
splitDebugInlining: false,
debugInfoForProfiling: true,
nameTableKind: 4,
rangesBaseAddress: true,
sysroot: "the root",
sdk: "SDK")
nameTableKind: 4)
----
|]
(ppToText $ ppLLVM35 ppStmt s1)
Expand All @@ -115,6 +112,43 @@ tests = Tasty.testGroup "LLVM pretty-printing output tests"
assertEqLines [sq|
In LLVM 3.7, the GEP instruction output shows the additional type
----
getelementptr inbounds %hi, opaque !DICompileUnit(language: 12,
producer: "llvm-pretty-test",
isOptimized: true,
flags: "some flags",
runtimeVersion: 3,
emissionKind: 1,
enums: !DITemplateTypeParameter(name: ttp),
dwoId: 2,
splitDebugInlining: false,
debugInfoForProfiling: true,
nameTableKind: 4)
----
|]
(ppToText $ ppLLVM37 ppStmt s1)

, testCase "Stmt 1, LLVM 10" $
assertEqLines (ppToText $ ppLLVM 10 $ ppStmt s1) [sq|
No change from LLVM 3.7 through LLVM 10
----
getelementptr inbounds %hi, opaque !DICompileUnit(language: 12,
producer: "llvm-pretty-test",
isOptimized: true,
flags: "some flags",
runtimeVersion: 3,
emissionKind: 1,
enums: !DITemplateTypeParameter(name: ttp),
dwoId: 2,
splitDebugInlining: false,
debugInfoForProfiling: true,
nameTableKind: 4)
----
|]

, testCase "Stmt 1, LLVM 11" $
assertEqLines (ppToText $ ppLLVM 11 $ ppStmt s1) [sq|
In LLVM 11, DICompileUnit adds rangesBaseAddress, sysroot, and sdk
----
getelementptr inbounds %hi, opaque !DICompileUnit(language: 12,
producer: "llvm-pretty-test",
isOptimized: true,
Expand All @@ -131,7 +165,6 @@ tests = Tasty.testGroup "LLVM pretty-printing output tests"
sdk: "SDK")
----
|]
(ppToText $ ppLLVM37 ppStmt s1)

------------------------------------------------------------

Expand Down

0 comments on commit 7f5631f

Please sign in to comment.