-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for LLVM address spaces #148
base: master
Are you sure you want to change the base?
Conversation
This affects many types and objects, and this work has only been tested by prettyprinting CHERI bc files.
This is required by llvm-as
@@ -414,7 +414,7 @@ iT :: Word32 -> Type | |||
iT = PrimType . Integer | |||
|
|||
ptrT :: Type -> Type | |||
ptrT = PtrTo | |||
ptrT = PtrTo (AddrSpace 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded 0 address space here and elsewhere is reasonable because every previous use was with 0 (nothing else existed) but additional helpers may be useful later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you factor AddrSpace 0
out into its own definition? Something like this (with an appropriate Haddock comment):
defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0
And then use this in places where AddrSpace 0
is currently used. This would make it more obvious at a glance that AddrSpace 0
is a distinguished value, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done an initial pass (without having yet looked at the corresponding llvm-pretty-bc-parser
changes).
newtype AddrSpace = AddrSpace | ||
{ getAddrSpace :: Int | ||
} deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to derive a Num
instance for this? It would be convenient to be able to write, say, 0
instead of AddrSpace 0
.
newtype AddrSpace = AddrSpace | ||
{ getAddrSpace :: Int | ||
} deriving (Data, Eq, Generic, Ord, Show, Typeable) -- , Bits, FiniteBits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the commented-out code here be removed, or is there a need to keep it around?
| LocalExec | ||
deriving (Data, Eq, Generic, Ord, Show, Typeable) | ||
|
||
-- ^ there is also None, use Nothing for it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this comment referring to?
@@ -414,7 +414,7 @@ iT :: Word32 -> Type | |||
iT = PrimType . Integer | |||
|
|||
ptrT :: Type -> Type | |||
ptrT = PtrTo | |||
ptrT = PtrTo (AddrSpace 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you factor AddrSpace 0
out into its own definition? Something like this (with an appropriate Haddock comment):
defaultAddrSpace :: AddrSpace
defaultAddrSpace = Addr 0
And then use this in places where AddrSpace 0
is currently used. This would make it more obvious at a glance that AddrSpace 0
is a distinguished value, IMO.
@@ -284,7 +290,7 @@ type DataLayout = [LayoutSpec] | |||
data LayoutSpec | |||
= BigEndian | |||
| LittleEndian | |||
| PointerSize !Int !Int !Int (Maybe Int) -- ^ address space, size, abi, pref | |||
| PointerSize !Bool !Int !Int !Int (Maybe Int) (Maybe Int) -- ^ fat pointer?, address space, size, abi, pref, "size of index used in GEP for address calculation" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, the first Int
here is intended to be an address space, but it is not using the AddrSpace
type. I wonder if it should.
ppAddrSpace (gaAddrSpace ga) <+> | ||
constant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments above this ought to be updated, since it claims that only the value (and nothing else) is printed. Really, it ought to say that the address space and the value are printed now.
<+> ppMaybe (\s -> "section" <+> doubleQuotes (text s)) (defSection d) | ||
<+> ppMaybe (\gc -> "gc" <+> ppGC gc) (defGC d) | ||
<+> ppMds (defMetadata d) | ||
<+> char '{' | ||
$+$ vcat (map ppBasicBlock (defBody d)) | ||
$+$ vcat (punctuate "" $ map ppBasicBlock (defBody d)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for this change?
DefaultVisibility -> "default" | ||
DefaultVisibility -> empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for this change?
@@ -947,7 +984,7 @@ ppConstExpr' pp expr = | |||
ConstArith op a b -> ppArithOp op <+> ppTuple a b | |||
ConstUnaryArith op a -> ppUnaryArithOp op <+> ppTyp' a | |||
ConstBit op a b -> ppBitOp op <+> ppTuple a b | |||
where ppTuple a b = parens $ ppTyped ppVal' a <> comma <+> ppVal' b | |||
where ppTuple a b = parens $ ppTyped ppVal' a <> comma <+> ppTyped ppVal' (const b <$> a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for this change?
| LocalUnnamedAddr | ||
deriving (Data, Eq, Generic, Ord, Show, Typeable) | ||
|
||
newtype AddrSpace = AddrSpace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in this part of the LLVM Language Reference Manual suggest that an address space's value must be less than 2^24
. Is that worth putting in the Haddocks here?
, gaConstant :: Bool | ||
} deriving (Data, Eq, Generic, Ord, Show, Typeable) | ||
|
||
emptyGlobalAttrs :: GlobalAttrs | ||
emptyGlobalAttrs = GlobalAttrs | ||
{ gaLinkage = Nothing | ||
, gaVisibility = Nothing | ||
, gaUnnamedAddr = Nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing gaThreadLocality = Nothing
?
Address spaces default to 0 and are currently mostly used by CHERI for capabilities (address space 200).
The thread_local property is properly read and reported.
Various formatting changes are implemented to more closely match llvm-dis output.