1 -----------------------------------------------------------------------------
3 -- Object-file symbols (called CLabel for histerical raisins).
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 -- The above warning supression flag is a temporary kludge.
11 -- While working on this module you are encouraged to remove it and fix
12 -- any warnings in the module. See
13 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
17 CLabel, -- abstract type
25 mkStaticConEntryLabel,
28 mkStaticInfoTableLabel,
35 mkLocalInfoTableLabel,
38 mkLocalStaticConEntryLabel,
39 mkLocalConInfoTableLabel,
40 mkLocalStaticInfoTableLabel,
41 mkLocalClosureTableLabel,
53 mkPlainModuleInitLabel,
56 mkDirty_MUT_VAR_Label,
59 mkMainCapabilityLabel,
60 mkMAP_FROZEN_infoLabel,
61 mkMAP_DIRTY_infoLabel,
62 mkEMPTY_MVAR_infoLabel,
65 mkCAFBlackHoleInfoTableLabel,
66 mkSECAFBlackHoleInfoTableLabel,
68 mkRtsSlowTickyCtrLabel,
94 mkCCLabel, mkCCSLabel,
96 DynamicLinkerLabelInfo(..),
98 dynamicLinkerLabelInfo,
101 mkDeadStripPreventer,
104 mkHpcModuleNameLabel,
106 infoLblToEntryLbl, entryLblToInfoLbl,
107 needsCDecl, isAsmTemp, maybeAsmTemp, externallyVisibleCLabel,
108 CLabelType(..), labelType, labelDynamic,
114 #include "HsVersions.h"
130 -- -----------------------------------------------------------------------------
134 CLabel is an abstract type that supports the following operations:
138 - In a C file, does it need to be declared before use? (i.e. is it
139 guaranteed to be already in scope in the places we need to refer to it?)
141 - If it needs to be declared, what type (code or data) should it be
144 - Is it visible outside this object file or not?
146 - Is it "dynamic" (see details below)
148 - Eq and Ord, so that we can make sets of CLabels (currently only
149 used in outputting C as far as I can tell, to avoid generating
150 more than one declaration for any given label).
152 - Converting an info table label into an entry label.
156 = IdLabel -- A family of labels related to the
157 Name -- definition of a particular Id or Con
160 | CaseLabel -- A family of labels related to a particular
162 {-# UNPACK #-} !Unique -- Unique says which case expression
166 {-# UNPACK #-} !Unique
169 {-# UNPACK #-} !Unique
172 Module -- the module name
174 -- at some point we might want some kind of version number in
175 -- the module init label, to guard against compiling modules in
176 -- the wrong order. We can't use the interface file version however,
177 -- because we don't always recompile modules which depend on a module
178 -- whose version has changed.
180 | PlainModuleInitLabel -- without the vesrion & way info
185 | RtsLabel RtsLabelInfo
187 | ForeignLabel FastString -- a 'C' (or otherwise foreign) label
188 (Maybe Int) -- possible '@n' suffix for stdcall functions
189 -- When generating C, the '@n' suffix is omitted, but when
190 -- generating assembler we must add it to the label.
191 Bool -- True <=> is dynamic
193 | CC_Label CostCentre
194 | CCS_Label CostCentreStack
196 -- Dynamic Linking in the NCG:
197 -- generated and used inside the NCG only,
198 -- see module PositionIndependentCode for details.
200 | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel
201 -- special variants of a label used for dynamic linking
203 | PicBaseLabel -- a label used as a base for PIC calculations
204 -- on some platforms.
205 -- It takes the form of a local numeric
206 -- assembler label '1'; it is pretty-printed
207 -- as 1b, referring to the previous definition
208 -- of 1: in the assembler source file.
210 | DeadStripPreventer CLabel
211 -- label before an info table to prevent excessive dead-stripping on darwin
213 | HpcTicksLabel Module -- Per-module table of tick locations
214 | HpcModuleNameLabel -- Per-module name of the module for Hpc
216 | LargeSRTLabel -- Label of an StgLargeSRT
217 {-# UNPACK #-} !Unique
219 | LargeBitmapLabel -- A bitmap (function or case return)
220 {-# UNPACK #-} !Unique
225 = Closure -- Label for closure
226 | SRT -- Static reference table
227 | InfoTable -- Info tables for closures; always read-only
228 | Entry -- entry point
229 | Slow -- slow entry point
231 | RednCounts -- Label of place to keep Ticky-ticky info for
234 | ConEntry -- constructor entry point
235 | ConInfoTable -- corresponding info table
236 | StaticConEntry -- static constructor entry point
237 | StaticInfoTable -- corresponding info table
239 | ClosureTable -- table of closures for Enum tycons
253 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- Selector thunks
254 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
256 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- AP thunks
257 | RtsApEntry Bool{-updatable-} Int{-arity-}
261 | RtsInfo LitString -- misc rts info tables
262 | RtsEntry LitString -- misc rts entry points
263 | RtsRetInfo LitString -- misc rts ret info tables
264 | RtsRet LitString -- misc rts return points
265 | RtsData LitString -- misc rts data bits, eg CHARLIKE_closure
266 | RtsCode LitString -- misc rts code
268 | RtsInfoFS FastString -- misc rts info tables
269 | RtsEntryFS FastString -- misc rts entry points
270 | RtsRetInfoFS FastString -- misc rts ret info tables
271 | RtsRetFS FastString -- misc rts return points
272 | RtsDataFS FastString -- misc rts data bits, eg CHARLIKE_closure
273 | RtsCodeFS FastString -- misc rts code
275 | RtsApFast LitString -- _fast versions of generic apply
277 | RtsSlowTickyCtr String
280 -- NOTE: Eq on LitString compares the pointer only, so this isn't
283 data DynamicLinkerLabelInfo
284 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
285 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
286 | GotSymbolPtr -- ELF: foo@got
287 | GotSymbolOffset -- ELF: foo@gotoff
291 -- -----------------------------------------------------------------------------
292 -- Constructing CLabels
294 -- These are always local:
295 mkSRTLabel name = IdLabel name SRT
296 mkSlowEntryLabel name = IdLabel name Slow
297 mkRednCountsLabel name = IdLabel name RednCounts
299 -- These have local & (possibly) external variants:
300 mkLocalClosureLabel name = IdLabel name Closure
301 mkLocalInfoTableLabel name = IdLabel name InfoTable
302 mkLocalEntryLabel name = IdLabel name Entry
303 mkLocalClosureTableLabel name = IdLabel name ClosureTable
305 mkClosureLabel name = IdLabel name Closure
306 mkInfoTableLabel name = IdLabel name InfoTable
307 mkEntryLabel name = IdLabel name Entry
308 mkClosureTableLabel name = IdLabel name ClosureTable
309 mkLocalConInfoTableLabel con = IdLabel con ConInfoTable
310 mkLocalConEntryLabel con = IdLabel con ConEntry
311 mkLocalStaticInfoTableLabel con = IdLabel con StaticInfoTable
312 mkLocalStaticConEntryLabel con = IdLabel con StaticConEntry
313 mkConInfoTableLabel name = IdLabel name ConInfoTable
314 mkStaticInfoTableLabel name = IdLabel name StaticInfoTable
316 mkConEntryLabel name = IdLabel name ConEntry
317 mkStaticConEntryLabel name = IdLabel name StaticConEntry
319 mkLargeSRTLabel uniq = LargeSRTLabel uniq
320 mkBitmapLabel uniq = LargeBitmapLabel uniq
322 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
323 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
324 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
325 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
327 mkStringLitLabel = StringLitLabel
328 mkAsmTempLabel = AsmTempLabel
330 mkModuleInitLabel :: Module -> String -> CLabel
331 mkModuleInitLabel mod way = ModuleInitLabel mod way
333 mkPlainModuleInitLabel :: Module -> CLabel
334 mkPlainModuleInitLabel mod = PlainModuleInitLabel mod
336 -- Some fixed runtime system labels
338 mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
339 mkDirty_MUT_VAR_Label = RtsLabel (RtsCode SLIT("dirty_MUT_VAR"))
340 mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
341 mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
342 mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
343 mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN0"))
344 mkMAP_DIRTY_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_DIRTY"))
345 mkEMPTY_MVAR_infoLabel = RtsLabel (RtsInfo SLIT("stg_EMPTY_MVAR"))
347 mkTopTickyCtrLabel = RtsLabel (RtsData SLIT("top_ct"))
348 mkCAFBlackHoleInfoTableLabel = RtsLabel (RtsInfo SLIT("stg_CAF_BLACKHOLE"))
349 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
350 RtsLabel (RtsInfo SLIT("stg_SE_CAF_BLACKHOLE"))
351 else -- RTS won't have info table unless -ticky is on
352 panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
353 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
355 moduleRegdLabel = ModuleRegdLabel
357 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
358 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
360 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
361 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
365 mkForeignLabel :: FastString -> Maybe Int -> Bool -> CLabel
366 mkForeignLabel str mb_sz is_dynamic = ForeignLabel str mb_sz is_dynamic
368 addLabelSize :: CLabel -> Int -> CLabel
369 addLabelSize (ForeignLabel str _ is_dynamic) sz
370 = ForeignLabel str (Just sz) is_dynamic
376 mkCCLabel cc = CC_Label cc
377 mkCCSLabel ccs = CCS_Label ccs
379 mkRtsInfoLabel str = RtsLabel (RtsInfo str)
380 mkRtsEntryLabel str = RtsLabel (RtsEntry str)
381 mkRtsRetInfoLabel str = RtsLabel (RtsRetInfo str)
382 mkRtsRetLabel str = RtsLabel (RtsRet str)
383 mkRtsCodeLabel str = RtsLabel (RtsCode str)
384 mkRtsDataLabel str = RtsLabel (RtsData str)
386 mkRtsInfoLabelFS str = RtsLabel (RtsInfoFS str)
387 mkRtsEntryLabelFS str = RtsLabel (RtsEntryFS str)
388 mkRtsRetInfoLabelFS str = RtsLabel (RtsRetInfoFS str)
389 mkRtsRetLabelFS str = RtsLabel (RtsRetFS str)
390 mkRtsCodeLabelFS str = RtsLabel (RtsCodeFS str)
391 mkRtsDataLabelFS str = RtsLabel (RtsDataFS str)
393 mkRtsApFastLabel str = RtsLabel (RtsApFast str)
395 mkRtsSlowTickyCtrLabel :: String -> CLabel
396 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
400 mkHpcTicksLabel = HpcTicksLabel
401 mkHpcModuleNameLabel = HpcModuleNameLabel
405 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
406 mkDynamicLinkerLabel = DynamicLinkerLabel
408 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
409 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
410 dynamicLinkerLabelInfo _ = Nothing
412 -- Position independent code
414 mkPicBaseLabel :: CLabel
415 mkPicBaseLabel = PicBaseLabel
417 mkDeadStripPreventer :: CLabel -> CLabel
418 mkDeadStripPreventer lbl = DeadStripPreventer lbl
420 -- -----------------------------------------------------------------------------
421 -- Converting between info labels and entry/ret labels.
423 infoLblToEntryLbl :: CLabel -> CLabel
424 infoLblToEntryLbl (IdLabel n InfoTable) = IdLabel n Entry
425 infoLblToEntryLbl (IdLabel n ConInfoTable) = IdLabel n ConEntry
426 infoLblToEntryLbl (IdLabel n StaticInfoTable) = IdLabel n StaticConEntry
427 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
428 infoLblToEntryLbl (RtsLabel (RtsInfo s)) = RtsLabel (RtsEntry s)
429 infoLblToEntryLbl (RtsLabel (RtsRetInfo s)) = RtsLabel (RtsRet s)
430 infoLblToEntryLbl (RtsLabel (RtsInfoFS s)) = RtsLabel (RtsEntryFS s)
431 infoLblToEntryLbl (RtsLabel (RtsRetInfoFS s)) = RtsLabel (RtsRetFS s)
432 infoLblToEntryLbl _ = panic "CLabel.infoLblToEntryLbl"
434 entryLblToInfoLbl :: CLabel -> CLabel
435 entryLblToInfoLbl (IdLabel n Entry) = IdLabel n InfoTable
436 entryLblToInfoLbl (IdLabel n ConEntry) = IdLabel n ConInfoTable
437 entryLblToInfoLbl (IdLabel n StaticConEntry) = IdLabel n StaticInfoTable
438 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
439 entryLblToInfoLbl (RtsLabel (RtsEntry s)) = RtsLabel (RtsInfo s)
440 entryLblToInfoLbl (RtsLabel (RtsRet s)) = RtsLabel (RtsRetInfo s)
441 entryLblToInfoLbl (RtsLabel (RtsEntryFS s)) = RtsLabel (RtsInfoFS s)
442 entryLblToInfoLbl (RtsLabel (RtsRetFS s)) = RtsLabel (RtsRetInfoFS s)
443 entryLblToInfoLbl l = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
445 -- -----------------------------------------------------------------------------
446 -- Does a CLabel need declaring before use or not?
448 needsCDecl :: CLabel -> Bool
449 -- False <=> it's pre-declared; don't bother
450 -- don't bother declaring SRT & Bitmap labels, we always make sure
451 -- they are defined before use.
452 needsCDecl (IdLabel _ SRT) = False
453 needsCDecl (LargeSRTLabel _) = False
454 needsCDecl (LargeBitmapLabel _) = False
455 needsCDecl (IdLabel _ _) = True
456 needsCDecl (CaseLabel _ _) = True
457 needsCDecl (ModuleInitLabel _ _) = True
458 needsCDecl (PlainModuleInitLabel _) = True
459 needsCDecl ModuleRegdLabel = False
461 needsCDecl (StringLitLabel _) = False
462 needsCDecl (AsmTempLabel _) = False
463 needsCDecl (RtsLabel _) = False
464 needsCDecl (ForeignLabel _ _ _) = False
465 needsCDecl (CC_Label _) = True
466 needsCDecl (CCS_Label _) = True
467 needsCDecl (HpcTicksLabel _) = True
468 needsCDecl HpcModuleNameLabel = False
470 -- Whether the label is an assembler temporary:
472 isAsmTemp :: CLabel -> Bool -- is a local temporary for native code generation
473 isAsmTemp (AsmTempLabel _) = True
476 maybeAsmTemp :: CLabel -> Maybe Unique
477 maybeAsmTemp (AsmTempLabel uq) = Just uq
478 maybeAsmTemp _ = Nothing
480 -- -----------------------------------------------------------------------------
481 -- Is a CLabel visible outside this object file or not?
483 -- From the point of view of the code generator, a name is
484 -- externally visible if it has to be declared as exported
485 -- in the .o file's symbol table; that is, made non-static.
487 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
488 externallyVisibleCLabel (CaseLabel _ _) = False
489 externallyVisibleCLabel (StringLitLabel _) = False
490 externallyVisibleCLabel (AsmTempLabel _) = False
491 externallyVisibleCLabel (ModuleInitLabel _ _) = True
492 externallyVisibleCLabel (PlainModuleInitLabel _)= True
493 externallyVisibleCLabel ModuleRegdLabel = False
494 externallyVisibleCLabel (RtsLabel _) = True
495 externallyVisibleCLabel (ForeignLabel _ _ _) = True
496 externallyVisibleCLabel (IdLabel name _) = isExternalName name
497 externallyVisibleCLabel (CC_Label _) = True
498 externallyVisibleCLabel (CCS_Label _) = True
499 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
500 externallyVisibleCLabel (HpcTicksLabel _) = True
501 externallyVisibleCLabel HpcModuleNameLabel = False
502 externallyVisibleCLabel (LargeBitmapLabel _) = False
503 externallyVisibleCLabel (LargeSRTLabel _) = False
505 -- -----------------------------------------------------------------------------
506 -- Finding the "type" of a CLabel
508 -- For generating correct types in label declarations:
514 labelType :: CLabel -> CLabelType
515 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
516 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
517 labelType (RtsLabel (RtsData _)) = DataLabel
518 labelType (RtsLabel (RtsCode _)) = CodeLabel
519 labelType (RtsLabel (RtsInfo _)) = DataLabel
520 labelType (RtsLabel (RtsEntry _)) = CodeLabel
521 labelType (RtsLabel (RtsRetInfo _)) = DataLabel
522 labelType (RtsLabel (RtsRet _)) = CodeLabel
523 labelType (RtsLabel (RtsDataFS _)) = DataLabel
524 labelType (RtsLabel (RtsCodeFS _)) = CodeLabel
525 labelType (RtsLabel (RtsInfoFS _)) = DataLabel
526 labelType (RtsLabel (RtsEntryFS _)) = CodeLabel
527 labelType (RtsLabel (RtsRetInfoFS _)) = DataLabel
528 labelType (RtsLabel (RtsRetFS _)) = CodeLabel
529 labelType (RtsLabel (RtsApFast _)) = CodeLabel
530 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
531 labelType (CaseLabel _ _) = CodeLabel
532 labelType (ModuleInitLabel _ _) = CodeLabel
533 labelType (PlainModuleInitLabel _) = CodeLabel
534 labelType (LargeSRTLabel _) = DataLabel
535 labelType (LargeBitmapLabel _) = DataLabel
537 labelType (IdLabel _ info) = idInfoLabelType info
538 labelType _ = DataLabel
540 idInfoLabelType info =
542 InfoTable -> DataLabel
544 ConInfoTable -> DataLabel
545 StaticInfoTable -> DataLabel
546 ClosureTable -> DataLabel
547 -- krc: aie! a ticky counter label is data
548 RednCounts -> DataLabel
552 -- -----------------------------------------------------------------------------
553 -- Does a CLabel need dynamic linkage?
555 -- When referring to data in code, we need to know whether
556 -- that data resides in a DLL or not. [Win32 only.]
557 -- @labelDynamic@ returns @True@ if the label is located
558 -- in a DLL, be it a data reference or not.
560 labelDynamic :: PackageId -> CLabel -> Bool
561 labelDynamic this_pkg lbl =
563 RtsLabel _ -> not opt_Static && (this_pkg /= rtsPackageId) -- i.e., is the RTS in a DLL or not?
564 IdLabel n k -> isDllName this_pkg n
565 #if mingw32_TARGET_OS
566 ForeignLabel _ _ d -> d
568 -- On Mac OS X and on ELF platforms, false positives are OK,
569 -- so we claim that all foreign imports come from dynamic libraries
570 ForeignLabel _ _ _ -> True
572 ModuleInitLabel m _ -> not opt_Static && this_pkg /= (modulePackageId m)
573 PlainModuleInitLabel m -> not opt_Static && this_pkg /= (modulePackageId m)
575 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
579 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
580 right places. It is used to detect when the abstractC statement of an
581 CCodeBlock actually contains the code for a slow entry point. -- HWL
583 We need at least @Eq@ for @CLabels@, because we want to avoid
584 duplicate declarations in generating C (see @labelSeenTE@ in
588 -----------------------------------------------------------------------------
589 -- Printing out CLabels.
596 where <name> is <Module>_<name> for external names and <unique> for
597 internal names. <type> is one of the following:
600 srt Static reference table
601 srtd Static reference table descriptor
602 entry Entry code (function, closure)
603 slow Slow entry code (if any)
604 ret Direct return address
606 <n>_alt Case alternative (tag n)
607 dflt Default case alternative
608 btm Large bitmap vector
609 closure Static closure
610 con_entry Dynamic Constructor entry code
611 con_info Dynamic Constructor info table
612 static_entry Static Constructor entry code
613 static_info Static Constructor info table
614 sel_info Selector info table
615 sel_entry Selector entry code
617 ccs Cost centre stack
619 Many of these distinctions are only for documentation reasons. For
620 example, _ret is only distinguished from _entry to make it easy to
621 tell whether a code fragment is a return point or a closure/function
625 instance Outputable CLabel where
628 pprCLabel :: CLabel -> SDoc
630 #if ! OMIT_NATIVE_CODEGEN
631 pprCLabel (AsmTempLabel u)
632 = getPprStyle $ \ sty ->
634 ptext asmTempLabelPrefix <> pprUnique u
636 char '_' <> pprUnique u
638 pprCLabel (DynamicLinkerLabel info lbl)
639 = pprDynamicLinkerAsmLabel info lbl
641 pprCLabel PicBaseLabel
644 pprCLabel (DeadStripPreventer lbl)
645 = pprCLabel lbl <> ptext SLIT("_dsp")
649 #if ! OMIT_NATIVE_CODEGEN
650 getPprStyle $ \ sty ->
652 maybe_underscore (pprAsmCLbl lbl)
658 | underscorePrefix = pp_cSEP <> doc
661 #ifdef mingw32_TARGET_OS
662 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
663 -- (The C compiler does this itself).
664 pprAsmCLbl (ForeignLabel fs (Just sz) _)
665 = ftext fs <> char '@' <> int sz
670 pprCLbl (StringLitLabel u)
671 = pprUnique u <> ptext SLIT("_str")
673 pprCLbl (CaseLabel u CaseReturnPt)
674 = hcat [pprUnique u, ptext SLIT("_ret")]
675 pprCLbl (CaseLabel u CaseReturnInfo)
676 = hcat [pprUnique u, ptext SLIT("_info")]
677 pprCLbl (CaseLabel u (CaseAlt tag))
678 = hcat [pprUnique u, pp_cSEP, int tag, ptext SLIT("_alt")]
679 pprCLbl (CaseLabel u CaseDefault)
680 = hcat [pprUnique u, ptext SLIT("_dflt")]
682 pprCLbl (LargeSRTLabel u) = pprUnique u <> pp_cSEP <> ptext SLIT("srtd")
683 pprCLbl (LargeBitmapLabel u) = text "b" <> pprUnique u <> pp_cSEP <> ptext SLIT("btm")
684 -- Some bitsmaps for tuple constructors have a numeric tag (e.g. '7')
685 -- until that gets resolved we'll just force them to start
686 -- with a letter so the label will be legal assmbly code.
689 pprCLbl (RtsLabel (RtsCode str)) = ptext str
690 pprCLbl (RtsLabel (RtsData str)) = ptext str
691 pprCLbl (RtsLabel (RtsCodeFS str)) = ftext str
692 pprCLbl (RtsLabel (RtsDataFS str)) = ftext str
694 pprCLbl (RtsLabel (RtsApFast str)) = ptext str <> ptext SLIT("_fast")
696 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
697 = hcat [ptext SLIT("stg_sel_"), text (show offset),
699 then SLIT("_upd_info")
700 else SLIT("_noupd_info"))
703 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
704 = hcat [ptext SLIT("stg_sel_"), text (show offset),
706 then SLIT("_upd_entry")
707 else SLIT("_noupd_entry"))
710 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
711 = hcat [ptext SLIT("stg_ap_"), text (show arity),
713 then SLIT("_upd_info")
714 else SLIT("_noupd_info"))
717 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
718 = hcat [ptext SLIT("stg_ap_"), text (show arity),
720 then SLIT("_upd_entry")
721 else SLIT("_noupd_entry"))
724 pprCLbl (RtsLabel (RtsInfo fs))
725 = ptext fs <> ptext SLIT("_info")
727 pprCLbl (RtsLabel (RtsEntry fs))
728 = ptext fs <> ptext SLIT("_entry")
730 pprCLbl (RtsLabel (RtsRetInfo fs))
731 = ptext fs <> ptext SLIT("_info")
733 pprCLbl (RtsLabel (RtsRet fs))
734 = ptext fs <> ptext SLIT("_ret")
736 pprCLbl (RtsLabel (RtsInfoFS fs))
737 = ftext fs <> ptext SLIT("_info")
739 pprCLbl (RtsLabel (RtsEntryFS fs))
740 = ftext fs <> ptext SLIT("_entry")
742 pprCLbl (RtsLabel (RtsRetInfoFS fs))
743 = ftext fs <> ptext SLIT("_info")
745 pprCLbl (RtsLabel (RtsRetFS fs))
746 = ftext fs <> ptext SLIT("_ret")
748 pprCLbl (RtsLabel (RtsPrimOp primop))
749 = ppr primop <> ptext SLIT("_fast")
751 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
752 = ptext SLIT("SLOW_CALL_") <> text pat <> ptext SLIT("_ctr")
754 pprCLbl ModuleRegdLabel
755 = ptext SLIT("_module_registered")
757 pprCLbl (ForeignLabel str _ _)
760 pprCLbl (IdLabel name flavor) = ppr name <> ppIdFlavor flavor
762 pprCLbl (CC_Label cc) = ppr cc
763 pprCLbl (CCS_Label ccs) = ppr ccs
765 pprCLbl (ModuleInitLabel mod way)
766 = ptext SLIT("__stginit_") <> ppr mod
767 <> char '_' <> text way
768 pprCLbl (PlainModuleInitLabel mod)
769 = ptext SLIT("__stginit_") <> ppr mod
771 pprCLbl (HpcTicksLabel mod)
772 = ptext SLIT("_hpc_tickboxes_") <> ppr mod <> ptext SLIT("_hpc")
774 pprCLbl HpcModuleNameLabel
775 = ptext SLIT("_hpc_module_name_str")
777 ppIdFlavor :: IdLabelInfo -> SDoc
778 ppIdFlavor x = pp_cSEP <>
780 Closure -> ptext SLIT("closure")
781 SRT -> ptext SLIT("srt")
782 InfoTable -> ptext SLIT("info")
783 Entry -> ptext SLIT("entry")
784 Slow -> ptext SLIT("slow")
785 RednCounts -> ptext SLIT("ct")
786 ConEntry -> ptext SLIT("con_entry")
787 ConInfoTable -> ptext SLIT("con_info")
788 StaticConEntry -> ptext SLIT("static_entry")
789 StaticInfoTable -> ptext SLIT("static_info")
790 ClosureTable -> ptext SLIT("closure_tbl")
796 -- -----------------------------------------------------------------------------
797 -- Machine-dependent knowledge about labels.
799 underscorePrefix :: Bool -- leading underscore on assembler labels?
800 underscorePrefix = (cLeadingUnderscore == "YES")
802 asmTempLabelPrefix :: LitString -- for formatting labels
805 {- The alpha assembler likes temporary labels to look like $L123
806 instead of L123. (Don't toss the L, because then Lf28
810 #elif darwin_TARGET_OS
816 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
818 #if x86_64_TARGET_ARCH && darwin_TARGET_OS
819 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
820 = pprCLabel lbl <> text "@GOTPCREL"
821 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
823 pprDynamicLinkerAsmLabel _ _
824 = panic "pprDynamicLinkerAsmLabel"
825 #elif darwin_TARGET_OS
826 pprDynamicLinkerAsmLabel CodeStub lbl
827 = char 'L' <> pprCLabel lbl <> text "$stub"
828 pprDynamicLinkerAsmLabel SymbolPtr lbl
829 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
830 pprDynamicLinkerAsmLabel _ _
831 = panic "pprDynamicLinkerAsmLabel"
832 #elif powerpc_TARGET_ARCH && linux_TARGET_OS
833 pprDynamicLinkerAsmLabel CodeStub lbl
834 = pprCLabel lbl <> text "@plt"
835 pprDynamicLinkerAsmLabel SymbolPtr lbl
836 = text ".LC_" <> pprCLabel lbl
837 pprDynamicLinkerAsmLabel _ _
838 = panic "pprDynamicLinkerAsmLabel"
839 #elif x86_64_TARGET_ARCH && linux_TARGET_OS
840 pprDynamicLinkerAsmLabel CodeStub lbl
841 = pprCLabel lbl <> text "@plt"
842 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
843 = pprCLabel lbl <> text "@gotpcrel"
844 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
846 pprDynamicLinkerAsmLabel SymbolPtr lbl
847 = text ".LC_" <> pprCLabel lbl
848 #elif linux_TARGET_OS
849 pprDynamicLinkerAsmLabel CodeStub lbl
850 = pprCLabel lbl <> text "@plt"
851 pprDynamicLinkerAsmLabel SymbolPtr lbl
852 = text ".LC_" <> pprCLabel lbl
853 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
854 = pprCLabel lbl <> text "@got"
855 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
856 = pprCLabel lbl <> text "@gotoff"
857 #elif mingw32_TARGET_OS
858 pprDynamicLinkerAsmLabel SymbolPtr lbl
859 = text "__imp_" <> pprCLabel lbl
860 pprDynamicLinkerAsmLabel _ _
861 = panic "pprDynamicLinkerAsmLabel"
863 pprDynamicLinkerAsmLabel _ _
864 = panic "pprDynamicLinkerAsmLabel"