-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core llvm: handle change in syntax of load and getelembyptr in LLVM 3.7
- Loading branch information
Showing
7 changed files
with
203 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,83 @@ | ||
|
||
module DDC.Llvm.Pretty.Base | ||
( Config(..) | ||
, configDefault | ||
, Version | ||
, versionWantsMetadataAsValue) | ||
, defaultConfig | ||
, configOfVersion | ||
, versionWantsMetadataAsValue | ||
, versionWantsLoadReturnTypes) | ||
where | ||
import Data.List | ||
import Data.Maybe | ||
|
||
|
||
------------------------------------------------------------------------------- | ||
-- | LLVM pretty printer configuration. | ||
data Config | ||
= Config | ||
{ configLlvmVersion :: Version } | ||
|
||
|
||
-- | Default config. | ||
configDefault :: Config | ||
configDefault | ||
= Config | ||
{ -- | Assume LLVM 3.8 as the default version unless told otherwise. | ||
-- This default should only be used during debugging, | ||
-- when compiling real modules the version will be set explicitly | ||
-- by the compilation driver. | ||
-- | ||
-- LLVM version 3.8.0 was current as of March 2016. | ||
configLlvmVersion = "LLVM version 3.8.0" } | ||
{ configLlvmVersion :: Version | ||
, configWantsMetadataAsValue :: Bool | ||
, configWantsLoadReturnTypes :: Bool } | ||
deriving Show | ||
|
||
|
||
-- | LLVM version descriptor. | ||
type Version | ||
= String | ||
|
||
|
||
-- | In LLVM versions before 3.6.1 encoded meta data as a value, | ||
-- | Default config that can be used for debugging. | ||
defaultConfig :: Config | ||
defaultConfig = configOfVersion Nothing | ||
|
||
|
||
-- | Produce a default pretty printer config for the given version. | ||
-- | ||
-- Assume LLVM 3.8 as the default version unless told otherwise. | ||
-- This default should only be used during debugging, | ||
-- when compiling real modules the version will be set explicitly | ||
-- by the compilation driver. | ||
-- | ||
-- LLVM version 3.8.0 was current as of March 2016. | ||
-- | ||
configOfVersion :: Maybe Version -> Config | ||
configOfVersion mVersion | ||
= let version = fromMaybe "3.8.0" mVersion | ||
in Config | ||
{ configLlvmVersion = version | ||
|
||
, configWantsMetadataAsValue | ||
= fromMaybe False $ versionWantsMetadataAsValue version | ||
|
||
, configWantsLoadReturnTypes | ||
= fromMaybe True $ versionWantsLoadReturnTypes version } | ||
|
||
|
||
-- | LLVM versions before 3.6.1 encoded meta data as a value, | ||
-- while after that it is typeless. | ||
versionWantsMetadataAsValue :: Version -> Maybe Bool | ||
versionWantsMetadataAsValue version | ||
= case words version of | ||
["LLVM", "version", num] | ||
| isPrefixOf "3.1." num -> Just True | ||
| isPrefixOf "3.2." num -> Just True | ||
| isPrefixOf "3.3." num -> Just True | ||
| isPrefixOf "3.4." num -> Just True | ||
| isPrefixOf "3.5." num -> Just True | ||
| isPrefixOf "3." num -> Just False | ||
|
||
_ -> Nothing | ||
versionWantsMetadataAsValue v | ||
| isPrefixOf "3.1." v = Just True | ||
| isPrefixOf "3.2." v = Just True | ||
| isPrefixOf "3.3." v = Just True | ||
| isPrefixOf "3.4." v = Just True | ||
| isPrefixOf "3.5." v = Just True | ||
| isPrefixOf "3." v = Just False | ||
| otherwise = Nothing | ||
|
||
|
||
-- | LLVM versions before 3.7.0 did not use a result type | ||
-- on load and getelembyptr operations, while after they | ||
-- did. | ||
versionWantsLoadReturnTypes :: Version -> Maybe Bool | ||
versionWantsLoadReturnTypes v | ||
| isPrefixOf "3.1." v = Just False | ||
| isPrefixOf "3.2." v = Just False | ||
| isPrefixOf "3.3." v = Just False | ||
| isPrefixOf "3.4." v = Just False | ||
| isPrefixOf "3.5." v = Just False | ||
| isPrefixOf "3.6." v = Just False | ||
| isPrefixOf "3." v = Just True | ||
| otherwise = Nothing | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.