Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c858049

Browse files
committed
cleanup
Bit 0 is `isConst` Bit 1 is `explicitType` Bit 2 is `addressSpace`
1 parent 67a03dd commit c858049

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

‎src/Data/BitCode/LLVM/ToBitCode.hs‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ instance ToNBitCode (Maybe Ident, Module) where
346346

347347
mkGlobalRec :: HasCallStack => V.Value -> NBitCode
348348
mkGlobalRec (V.Global{..}) = mkRec MC.GLOBALVAR [ lookupTypeIndex typeMap t -- NOTE: We store the pointee type.
349-
, 1.|. shift (bool gIsConst) 1 .|. shift gAddressSpace 2
349+
, bool gIsConst .|. shift explicitType 1 .|. shift gAddressSpace 2
350350
, fromMaybe 0 ((+1) . lookupSymbolIndex <$> gInit)
351351
, fromEnum' gLinkage
352352
, gParamAttrs
@@ -359,6 +359,7 @@ instance ToNBitCode (Maybe Ident, Module) where
359359
, gComdat
360360
]
361361
where (T.Ptr _ t) = gPointerType
362+
explicitType = 1
362363

363364
mkFunctionRec :: HasCallStack => V.Value -> NBitCode
364365
mkFunctionRec (V.Function{..}) = mkRec MC.FUNCTION [ lookupTypeIndex typeMap t -- NOTE: Similar to Globals we store the pointee type.
@@ -505,13 +506,21 @@ instance ToNBitCode (Maybe Ident, Module) where
505506
-- XXX: Call needs paramAttrs! -- Can use 0 for empty param set.
506507
mkInstRec n (I.Call _ tck cc s fnTy args)
507508
| ty (V.symbolValue s) /= ty s = error $ unlines [ "SymbolValues type and Symbol"
508-
, show s
509-
, "type mismatch; symbolValue ty"
510-
, show (ty (V.symbolValue s))
511-
, "ty s"
512-
, show (ty s)
513-
]
514-
| ty (V.symbolValue s) /= fnTy = error $ "Callees Symbols ty " ++ show (ty (V.symbolValue s)) ++ " does not match call signature " ++ show fnTy
509+
, show s
510+
, "type mismatch; symbolValue ty"
511+
, show (ty (V.symbolValue s))
512+
, "ty s"
513+
, show (ty s)
514+
]
515+
| ty (V.symbolValue s) /= fnTy = error $ unlines [ "Callees Symbols "
516+
, show s
517+
, "type mismatch; symbolValue ty"
518+
, show (ty (V.symbolValue s))
519+
, "function signature type"
520+
, show fnTy
521+
, "arguments (" ++ show (length args) ++ ")"
522+
, show args
523+
]
515524
| otherwise = mkRec FC.INST_CALL $ [ (0 :: Word64) -- Fix PARAMATTR
516525
, cconv .|. tcKind .|. explTy
517526
-- FMF
@@ -592,7 +601,7 @@ instance ToNBitCode (Maybe Ident, Module) where
592601

593602
mkInstRec n (I.ExtractValue val idxs)
594603
= mkRec FC.INST_EXTRACTVAL $ [ lookupRelativeSymbolIndex' n val ] ++ idxs
595-
604+
596605
mkInstRec n i = error $ "Instruction " ++ (show i) ++ " not yet supported."
597606
-- Fold helper to keep track of the instruction count.
598607
mkInstRecFold :: HasCallStack => (Word64, [NBitCode]) -> I.Inst -> (Word64, [NBitCode])

‎src/Data/BitCode/LLVM/Value.hs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ external = setLinkage External
163163
private = setLinkage Private
164164
internal = setLinkage Private
165165

166+
mutable, immutable :: HasCallStack => Value -> Value
167+
mutable x = x { gIsConst = False }
168+
immutable x = x { gIsConst = True }
169+
170+
166171
instance HasLinkage Value where
167172
getLinkage (Global{gLinkage = l}) = l
168173
getLinkage (Function{fLinkage = l}) = l
@@ -252,7 +257,7 @@ type Symbol = Named Value
252257
instance HasLinkage a => HasLinkage (Named a) where
253258
getLinkage (Named _ _ _ x) = getLinkage x
254259
getLinkage (Unnamed _ _ x) = getLinkage x
255-
setLinkage l = fmap (setLinkage l)
260+
setLinkage l = fmap (setLinkage l)
256261

257262
symbolValue :: Symbol -> Value
258263
symbolValue (Named n _ _ v) = trace ("[symbolValue] for symbol " ++ n) v

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /