1 -----------------------------------------------------------------------------
3 -- Object-file symbols (called CLabel for histerical raisins).
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 CLabel, -- abstract type
18 mkStaticConEntryLabel,
21 mkStaticInfoTableLabel,
28 mkLocalInfoTableLabel,
31 mkLocalStaticConEntryLabel,
32 mkLocalConInfoTableLabel,
33 mkLocalStaticInfoTableLabel,
34 mkLocalClosureTableLabel,
46 mkPlainModuleInitLabel,
49 mkDirty_MUT_VAR_Label,
52 mkMainCapabilityLabel,
53 mkMAP_FROZEN_infoLabel,
54 mkMAP_DIRTY_infoLabel,
55 mkEMPTY_MVAR_infoLabel,
58 mkCAFBlackHoleInfoTableLabel,
59 mkSECAFBlackHoleInfoTableLabel,
61 mkRtsSlowTickyCtrLabel,
86 mkCCLabel, mkCCSLabel,
88 DynamicLinkerLabelInfo(..),
90 dynamicLinkerLabelInfo,
98 infoLblToEntryLbl, entryLblToInfoLbl,
99 needsCDecl, isAsmTemp, maybeAsmTemp, externallyVisibleCLabel,
100 CLabelType(..), labelType, labelDynamic,
106 #include "HsVersions.h"
121 -- -----------------------------------------------------------------------------
125 CLabel is an abstract type that supports the following operations:
129 - In a C file, does it need to be declared before use? (i.e. is it
130 guaranteed to be already in scope in the places we need to refer to it?)
132 - If it needs to be declared, what type (code or data) should it be
135 - Is it visible outside this object file or not?
137 - Is it "dynamic" (see details below)
139 - Eq and Ord, so that we can make sets of CLabels (currently only
140 used in outputting C as far as I can tell, to avoid generating
141 more than one declaration for any given label).
143 - Converting an info table label into an entry label.
147 = IdLabel -- A family of labels related to the
148 Name -- definition of a particular Id or Con
151 | DynIdLabel -- like IdLabel, but in a separate package,
152 Name -- and might therefore need a dynamic
153 IdLabelInfo -- reference.
155 | CaseLabel -- A family of labels related to a particular
157 {-# UNPACK #-} !Unique -- Unique says which case expression
161 {-# UNPACK #-} !Unique
164 {-# UNPACK #-} !Unique
167 Module -- the module name
169 Bool -- True <=> is in a different package
170 -- at some point we might want some kind of version number in
171 -- the module init label, to guard against compiling modules in
172 -- the wrong order. We can't use the interface file version however,
173 -- because we don't always recompile modules which depend on a module
174 -- whose version has changed.
176 | PlainModuleInitLabel -- without the vesrion & way info
178 Bool -- True <=> is in a different package
182 | RtsLabel RtsLabelInfo
184 | ForeignLabel FastString -- a 'C' (or otherwise foreign) label
185 (Maybe Int) -- possible '@n' suffix for stdcall functions
186 -- When generating C, the '@n' suffix is omitted, but when
187 -- generating assembler we must add it to the label.
188 Bool -- True <=> is dynamic
190 | CC_Label CostCentre
191 | CCS_Label CostCentreStack
193 -- Dynamic Linking in the NCG:
194 -- generated and used inside the NCG only,
195 -- see module PositionIndependentCode for details.
197 | DynamicLinkerLabel DynamicLinkerLabelInfo CLabel
198 -- special variants of a label used for dynamic linking
200 | PicBaseLabel -- a label used as a base for PIC calculations
201 -- on some platforms.
202 -- It takes the form of a local numeric
203 -- assembler label '1'; it is pretty-printed
204 -- as 1b, referring to the previous definition
205 -- of 1: in the assembler source file.
207 | DeadStripPreventer CLabel
208 -- label before an info table to prevent excessive dead-stripping on darwin
210 | HpcTicksLabel Module -- Per-module table of tick locations
211 | HpcModuleNameLabel -- Per-module name of the module for Hpc
213 | LargeSRTLabel -- Label of an StgLargeSRT
214 {-# UNPACK #-} !Unique
219 = Closure -- Label for closure
220 | SRT -- Static reference table
221 | InfoTable -- Info tables for closures; always read-only
222 | Entry -- entry point
223 | Slow -- slow entry point
225 | RednCounts -- Label of place to keep Ticky-ticky info for
228 | Bitmap -- A bitmap (function or case return)
230 | ConEntry -- constructor entry point
231 | ConInfoTable -- corresponding info table
232 | StaticConEntry -- static constructor entry point
233 | StaticInfoTable -- corresponding info table
235 | ClosureTable -- table of closures for Enum tycons
249 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- Selector thunks
250 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
252 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- AP thunks
253 | RtsApEntry Bool{-updatable-} Int{-arity-}
257 | RtsInfo LitString -- misc rts info tables
258 | RtsEntry LitString -- misc rts entry points
259 | RtsRetInfo LitString -- misc rts ret info tables
260 | RtsRet LitString -- misc rts return points
261 | RtsData LitString -- misc rts data bits, eg CHARLIKE_closure
262 | RtsCode LitString -- misc rts code
264 | RtsInfoFS FastString -- misc rts info tables
265 | RtsEntryFS FastString -- misc rts entry points
266 | RtsRetInfoFS FastString -- misc rts ret info tables
267 | RtsRetFS FastString -- misc rts return points
268 | RtsDataFS FastString -- misc rts data bits, eg CHARLIKE_closure
269 | RtsCodeFS FastString -- misc rts code
271 | RtsApFast LitString -- _fast versions of generic apply
273 | RtsSlowTickyCtr String
276 -- NOTE: Eq on LitString compares the pointer only, so this isn't
279 data DynamicLinkerLabelInfo
280 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
281 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
282 | GotSymbolPtr -- ELF: foo@got
283 | GotSymbolOffset -- ELF: foo@gotoff
287 -- -----------------------------------------------------------------------------
288 -- Constructing CLabels
290 -- These are always local:
291 mkSRTLabel name = IdLabel name SRT
292 mkSlowEntryLabel name = IdLabel name Slow
293 mkBitmapLabel name = IdLabel name Bitmap
294 mkRednCountsLabel name = IdLabel name RednCounts
296 -- These have local & (possibly) external variants:
297 mkLocalClosureLabel name = IdLabel name Closure
298 mkLocalInfoTableLabel name = IdLabel name InfoTable
299 mkLocalEntryLabel name = IdLabel name Entry
300 mkLocalClosureTableLabel name = IdLabel name ClosureTable
302 mkClosureLabel this_pkg name
303 | isDllName this_pkg name = DynIdLabel name Closure
304 | otherwise = IdLabel name Closure
306 mkInfoTableLabel this_pkg name
307 | isDllName this_pkg name = DynIdLabel name InfoTable
308 | otherwise = IdLabel name InfoTable
310 mkEntryLabel this_pkg name
311 | isDllName this_pkg name = DynIdLabel name Entry
312 | otherwise = IdLabel name Entry
314 mkClosureTableLabel this_pkg name
315 | isDllName this_pkg name = DynIdLabel name ClosureTable
316 | otherwise = IdLabel name ClosureTable
318 mkLocalConInfoTableLabel con = IdLabel con ConInfoTable
319 mkLocalConEntryLabel con = IdLabel con ConEntry
320 mkLocalStaticInfoTableLabel con = IdLabel con StaticInfoTable
321 mkLocalStaticConEntryLabel con = IdLabel con StaticConEntry
323 mkConInfoTableLabel name False = IdLabel name ConInfoTable
324 mkConInfoTableLabel name True = DynIdLabel name ConInfoTable
326 mkStaticInfoTableLabel name False = IdLabel name StaticInfoTable
327 mkStaticInfoTableLabel name True = DynIdLabel name StaticInfoTable
329 mkConEntryLabel this_pkg name
330 | isDllName this_pkg name = DynIdLabel name ConEntry
331 | otherwise = IdLabel name ConEntry
333 mkStaticConEntryLabel this_pkg name
334 | isDllName this_pkg name = DynIdLabel name StaticConEntry
335 | otherwise = IdLabel name StaticConEntry
337 mkLargeSRTLabel uniq = LargeSRTLabel uniq
339 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
340 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
341 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
342 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
344 mkStringLitLabel = StringLitLabel
345 mkAsmTempLabel = AsmTempLabel
347 mkModuleInitLabel :: PackageId -> Module -> String -> CLabel
348 mkModuleInitLabel this_pkg mod way
349 = ModuleInitLabel mod way $! modulePackageId mod /= this_pkg
351 mkPlainModuleInitLabel :: PackageId -> Module -> CLabel
352 mkPlainModuleInitLabel this_pkg mod
353 = PlainModuleInitLabel mod $! modulePackageId mod /= this_pkg
355 -- Some fixed runtime system labels
357 mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
358 mkDirty_MUT_VAR_Label = RtsLabel (RtsCode SLIT("dirty_MUT_VAR"))
359 mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
360 mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
361 mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
362 mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN0"))
363 mkMAP_DIRTY_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_DIRTY"))
364 mkEMPTY_MVAR_infoLabel = RtsLabel (RtsInfo SLIT("stg_EMPTY_MVAR"))
366 mkTopTickyCtrLabel = RtsLabel (RtsData SLIT("top_ct"))
367 mkCAFBlackHoleInfoTableLabel = RtsLabel (RtsInfo SLIT("stg_CAF_BLACKHOLE"))
368 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
369 RtsLabel (RtsInfo SLIT("stg_SE_CAF_BLACKHOLE"))
370 else -- RTS won't have info table unless -ticky is on
371 panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
372 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
374 moduleRegdLabel = ModuleRegdLabel
376 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
377 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
379 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
380 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
384 mkForeignLabel :: FastString -> Maybe Int -> Bool -> CLabel
385 mkForeignLabel str mb_sz is_dynamic = ForeignLabel str mb_sz is_dynamic
389 mkCCLabel cc = CC_Label cc
390 mkCCSLabel ccs = CCS_Label ccs
392 mkRtsInfoLabel str = RtsLabel (RtsInfo str)
393 mkRtsEntryLabel str = RtsLabel (RtsEntry str)
394 mkRtsRetInfoLabel str = RtsLabel (RtsRetInfo str)
395 mkRtsRetLabel str = RtsLabel (RtsRet str)
396 mkRtsCodeLabel str = RtsLabel (RtsCode str)
397 mkRtsDataLabel str = RtsLabel (RtsData str)
399 mkRtsInfoLabelFS str = RtsLabel (RtsInfoFS str)
400 mkRtsEntryLabelFS str = RtsLabel (RtsEntryFS str)
401 mkRtsRetInfoLabelFS str = RtsLabel (RtsRetInfoFS str)
402 mkRtsRetLabelFS str = RtsLabel (RtsRetFS str)
403 mkRtsCodeLabelFS str = RtsLabel (RtsCodeFS str)
404 mkRtsDataLabelFS str = RtsLabel (RtsDataFS str)
406 mkRtsApFastLabel str = RtsLabel (RtsApFast str)
408 mkRtsSlowTickyCtrLabel :: String -> CLabel
409 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
413 mkHpcTicksLabel = HpcTicksLabel
414 mkHpcModuleNameLabel = HpcModuleNameLabel
418 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
419 mkDynamicLinkerLabel = DynamicLinkerLabel
421 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
422 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
423 dynamicLinkerLabelInfo _ = Nothing
425 -- Position independent code
427 mkPicBaseLabel :: CLabel
428 mkPicBaseLabel = PicBaseLabel
430 mkDeadStripPreventer :: CLabel -> CLabel
431 mkDeadStripPreventer lbl = DeadStripPreventer lbl
433 -- -----------------------------------------------------------------------------
434 -- Converting info labels to entry labels.
436 infoLblToEntryLbl :: CLabel -> CLabel
437 infoLblToEntryLbl (IdLabel n InfoTable) = IdLabel n Entry
438 infoLblToEntryLbl (IdLabel n ConInfoTable) = IdLabel n ConEntry
439 infoLblToEntryLbl (IdLabel n StaticInfoTable) = IdLabel n StaticConEntry
440 infoLblToEntryLbl (DynIdLabel n InfoTable) = DynIdLabel n Entry
441 infoLblToEntryLbl (DynIdLabel n ConInfoTable) = DynIdLabel n ConEntry
442 infoLblToEntryLbl (DynIdLabel n StaticInfoTable) = DynIdLabel n StaticConEntry
443 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
444 infoLblToEntryLbl (RtsLabel (RtsInfo s)) = RtsLabel (RtsEntry s)
445 infoLblToEntryLbl (RtsLabel (RtsRetInfo s)) = RtsLabel (RtsRet s)
446 infoLblToEntryLbl (RtsLabel (RtsInfoFS s)) = RtsLabel (RtsEntryFS s)
447 infoLblToEntryLbl (RtsLabel (RtsRetInfoFS s)) = RtsLabel (RtsRetFS s)
448 infoLblToEntryLbl _ = panic "CLabel.infoLblToEntryLbl"
450 entryLblToInfoLbl :: CLabel -> CLabel
451 entryLblToInfoLbl (IdLabel n Entry) = IdLabel n InfoTable
452 entryLblToInfoLbl (IdLabel n ConEntry) = IdLabel n ConInfoTable
453 entryLblToInfoLbl (IdLabel n StaticConEntry) = IdLabel n StaticInfoTable
454 entryLblToInfoLbl (DynIdLabel n Entry) = DynIdLabel n InfoTable
455 entryLblToInfoLbl (DynIdLabel n ConEntry) = DynIdLabel n ConInfoTable
456 entryLblToInfoLbl (DynIdLabel n StaticConEntry) = DynIdLabel n StaticInfoTable
457 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
458 entryLblToInfoLbl (RtsLabel (RtsEntry s)) = RtsLabel (RtsInfo s)
459 entryLblToInfoLbl (RtsLabel (RtsRet s)) = RtsLabel (RtsRetInfo s)
460 entryLblToInfoLbl (RtsLabel (RtsEntryFS s)) = RtsLabel (RtsInfoFS s)
461 entryLblToInfoLbl (RtsLabel (RtsRetFS s)) = RtsLabel (RtsRetInfoFS s)
462 entryLblToInfoLbl l = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
464 -- -----------------------------------------------------------------------------
465 -- Does a CLabel need declaring before use or not?
467 needsCDecl :: CLabel -> Bool
468 -- False <=> it's pre-declared; don't bother
469 -- don't bother declaring SRT & Bitmap labels, we always make sure
470 -- they are defined before use.
471 needsCDecl (IdLabel _ SRT) = False
472 needsCDecl (LargeSRTLabel _) = False
473 needsCDecl (IdLabel _ Bitmap) = False
474 needsCDecl (IdLabel _ _) = True
475 needsCDecl (DynIdLabel _ _) = True
476 needsCDecl (CaseLabel _ _) = True
477 needsCDecl (ModuleInitLabel _ _ _) = True
478 needsCDecl (PlainModuleInitLabel _ _) = True
479 needsCDecl ModuleRegdLabel = False
481 needsCDecl (StringLitLabel _) = False
482 needsCDecl (AsmTempLabel _) = False
483 needsCDecl (RtsLabel _) = False
484 needsCDecl (ForeignLabel _ _ _) = False
485 needsCDecl (CC_Label _) = True
486 needsCDecl (CCS_Label _) = True
487 needsCDecl (HpcTicksLabel _) = True
488 needsCDecl HpcModuleNameLabel = False
490 -- Whether the label is an assembler temporary:
492 isAsmTemp :: CLabel -> Bool -- is a local temporary for native code generation
493 isAsmTemp (AsmTempLabel _) = True
496 maybeAsmTemp :: CLabel -> Maybe Unique
497 maybeAsmTemp (AsmTempLabel uq) = Just uq
498 maybeAsmTemp _ = Nothing
500 -- -----------------------------------------------------------------------------
501 -- Is a CLabel visible outside this object file or not?
503 -- From the point of view of the code generator, a name is
504 -- externally visible if it has to be declared as exported
505 -- in the .o file's symbol table; that is, made non-static.
507 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
508 externallyVisibleCLabel (CaseLabel _ _) = False
509 externallyVisibleCLabel (StringLitLabel _) = False
510 externallyVisibleCLabel (AsmTempLabel _) = False
511 externallyVisibleCLabel (ModuleInitLabel _ _ _)= True
512 externallyVisibleCLabel (PlainModuleInitLabel _ _)= True
513 externallyVisibleCLabel ModuleRegdLabel = False
514 externallyVisibleCLabel (RtsLabel _) = True
515 externallyVisibleCLabel (ForeignLabel _ _ _) = True
516 externallyVisibleCLabel (IdLabel name _) = isExternalName name
517 externallyVisibleCLabel (DynIdLabel name _) = isExternalName name
518 externallyVisibleCLabel (CC_Label _) = True
519 externallyVisibleCLabel (CCS_Label _) = True
520 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
521 externallyVisibleCLabel (HpcTicksLabel _) = True
522 externallyVisibleCLabel HpcModuleNameLabel = False
524 -- -----------------------------------------------------------------------------
525 -- Finding the "type" of a CLabel
527 -- For generating correct types in label declarations:
533 labelType :: CLabel -> CLabelType
534 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
535 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
536 labelType (RtsLabel (RtsData _)) = DataLabel
537 labelType (RtsLabel (RtsCode _)) = CodeLabel
538 labelType (RtsLabel (RtsInfo _)) = DataLabel
539 labelType (RtsLabel (RtsEntry _)) = CodeLabel
540 labelType (RtsLabel (RtsRetInfo _)) = DataLabel
541 labelType (RtsLabel (RtsRet _)) = CodeLabel
542 labelType (RtsLabel (RtsDataFS _)) = DataLabel
543 labelType (RtsLabel (RtsCodeFS _)) = CodeLabel
544 labelType (RtsLabel (RtsInfoFS _)) = DataLabel
545 labelType (RtsLabel (RtsEntryFS _)) = CodeLabel
546 labelType (RtsLabel (RtsRetInfoFS _)) = DataLabel
547 labelType (RtsLabel (RtsRetFS _)) = CodeLabel
548 labelType (RtsLabel (RtsApFast _)) = CodeLabel
549 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
550 labelType (CaseLabel _ _) = CodeLabel
551 labelType (ModuleInitLabel _ _ _) = CodeLabel
552 labelType (PlainModuleInitLabel _ _) = CodeLabel
554 labelType (IdLabel _ info) = idInfoLabelType info
555 labelType (DynIdLabel _ info) = idInfoLabelType info
556 labelType _ = DataLabel
558 idInfoLabelType info =
560 InfoTable -> DataLabel
563 ConInfoTable -> DataLabel
564 StaticInfoTable -> DataLabel
565 ClosureTable -> DataLabel
566 -- krc: aie! a ticky counter label is data
567 RednCounts -> DataLabel
571 -- -----------------------------------------------------------------------------
572 -- Does a CLabel need dynamic linkage?
574 -- When referring to data in code, we need to know whether
575 -- that data resides in a DLL or not. [Win32 only.]
576 -- @labelDynamic@ returns @True@ if the label is located
577 -- in a DLL, be it a data reference or not.
579 labelDynamic :: CLabel -> Bool
582 RtsLabel _ -> not opt_Static -- i.e., is the RTS in a DLL or not?
584 DynIdLabel n k -> True
585 #if mingw32_TARGET_OS
586 ForeignLabel _ _ d -> d
588 -- On Mac OS X and on ELF platforms, false positives are OK,
589 -- so we claim that all foreign imports come from dynamic libraries
590 ForeignLabel _ _ _ -> True
592 ModuleInitLabel m _ dyn -> not opt_Static && dyn
593 PlainModuleInitLabel m dyn -> not opt_Static && dyn
595 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
599 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
600 right places. It is used to detect when the abstractC statement of an
601 CCodeBlock actually contains the code for a slow entry point. -- HWL
603 We need at least @Eq@ for @CLabels@, because we want to avoid
604 duplicate declarations in generating C (see @labelSeenTE@ in
608 -----------------------------------------------------------------------------
609 -- Printing out CLabels.
616 where <name> is <Module>_<name> for external names and <unique> for
617 internal names. <type> is one of the following:
620 srt Static reference table
621 srtd Static reference table descriptor
622 entry Entry code (function, closure)
623 slow Slow entry code (if any)
624 ret Direct return address
626 <n>_alt Case alternative (tag n)
627 dflt Default case alternative
628 btm Large bitmap vector
629 closure Static closure
630 con_entry Dynamic Constructor entry code
631 con_info Dynamic Constructor info table
632 static_entry Static Constructor entry code
633 static_info Static Constructor info table
634 sel_info Selector info table
635 sel_entry Selector entry code
637 ccs Cost centre stack
639 Many of these distinctions are only for documentation reasons. For
640 example, _ret is only distinguished from _entry to make it easy to
641 tell whether a code fragment is a return point or a closure/function
645 instance Outputable CLabel where
648 pprCLabel :: CLabel -> SDoc
650 #if ! OMIT_NATIVE_CODEGEN
651 pprCLabel (AsmTempLabel u)
652 = getPprStyle $ \ sty ->
654 ptext asmTempLabelPrefix <> pprUnique u
656 char '_' <> pprUnique u
658 pprCLabel (DynamicLinkerLabel info lbl)
659 = pprDynamicLinkerAsmLabel info lbl
661 pprCLabel PicBaseLabel
664 pprCLabel (DeadStripPreventer lbl)
665 = pprCLabel lbl <> ptext SLIT("_dsp")
669 #if ! OMIT_NATIVE_CODEGEN
670 getPprStyle $ \ sty ->
672 maybe_underscore (pprAsmCLbl lbl)
678 | underscorePrefix = pp_cSEP <> doc
681 #ifdef mingw32_TARGET_OS
682 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
683 -- (The C compiler does this itself).
684 pprAsmCLbl (ForeignLabel fs (Just sz) _)
685 = ftext fs <> char '@' <> int sz
690 pprCLbl (StringLitLabel u)
691 = pprUnique u <> ptext SLIT("_str")
693 pprCLbl (CaseLabel u CaseReturnPt)
694 = hcat [pprUnique u, ptext SLIT("_ret")]
695 pprCLbl (CaseLabel u CaseReturnInfo)
696 = hcat [pprUnique u, ptext SLIT("_info")]
697 pprCLbl (CaseLabel u (CaseAlt tag))
698 = hcat [pprUnique u, pp_cSEP, int tag, ptext SLIT("_alt")]
699 pprCLbl (CaseLabel u CaseDefault)
700 = hcat [pprUnique u, ptext SLIT("_dflt")]
702 pprCLbl (LargeSRTLabel u) = pprUnique u <> pp_cSEP <> ptext SLIT("srtd")
704 pprCLbl (RtsLabel (RtsCode str)) = ptext str
705 pprCLbl (RtsLabel (RtsData str)) = ptext str
706 pprCLbl (RtsLabel (RtsCodeFS str)) = ftext str
707 pprCLbl (RtsLabel (RtsDataFS str)) = ftext str
709 pprCLbl (RtsLabel (RtsApFast str)) = ptext str <> ptext SLIT("_fast")
711 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
712 = hcat [ptext SLIT("stg_sel_"), text (show offset),
714 then SLIT("_upd_info")
715 else SLIT("_noupd_info"))
718 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
719 = hcat [ptext SLIT("stg_sel_"), text (show offset),
721 then SLIT("_upd_entry")
722 else SLIT("_noupd_entry"))
725 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
726 = hcat [ptext SLIT("stg_ap_"), text (show arity),
728 then SLIT("_upd_info")
729 else SLIT("_noupd_info"))
732 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
733 = hcat [ptext SLIT("stg_ap_"), text (show arity),
735 then SLIT("_upd_entry")
736 else SLIT("_noupd_entry"))
739 pprCLbl (RtsLabel (RtsInfo fs))
740 = ptext fs <> ptext SLIT("_info")
742 pprCLbl (RtsLabel (RtsEntry fs))
743 = ptext fs <> ptext SLIT("_entry")
745 pprCLbl (RtsLabel (RtsRetInfo fs))
746 = ptext fs <> ptext SLIT("_info")
748 pprCLbl (RtsLabel (RtsRet fs))
749 = ptext fs <> ptext SLIT("_ret")
751 pprCLbl (RtsLabel (RtsInfoFS fs))
752 = ftext fs <> ptext SLIT("_info")
754 pprCLbl (RtsLabel (RtsEntryFS fs))
755 = ftext fs <> ptext SLIT("_entry")
757 pprCLbl (RtsLabel (RtsRetInfoFS fs))
758 = ftext fs <> ptext SLIT("_info")
760 pprCLbl (RtsLabel (RtsRetFS fs))
761 = ftext fs <> ptext SLIT("_ret")
763 pprCLbl (RtsLabel (RtsPrimOp primop))
764 = ppr primop <> ptext SLIT("_fast")
766 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
767 = ptext SLIT("SLOW_CALL_") <> text pat <> ptext SLIT("_ctr")
769 pprCLbl ModuleRegdLabel
770 = ptext SLIT("_module_registered")
772 pprCLbl (ForeignLabel str _ _)
775 pprCLbl (IdLabel name flavor) = ppr name <> ppIdFlavor flavor
776 pprCLbl (DynIdLabel name flavor) = ppr name <> ppIdFlavor flavor
778 pprCLbl (CC_Label cc) = ppr cc
779 pprCLbl (CCS_Label ccs) = ppr ccs
781 pprCLbl (ModuleInitLabel mod way _)
782 = ptext SLIT("__stginit_") <> ppr mod
783 <> char '_' <> text way
784 pprCLbl (PlainModuleInitLabel mod _)
785 = ptext SLIT("__stginit_") <> ppr mod
787 pprCLbl (HpcTicksLabel mod)
788 = ptext SLIT("_hpc_tickboxes_") <> ppr mod <> ptext SLIT("_hpc")
790 pprCLbl HpcModuleNameLabel
791 = ptext SLIT("_hpc_module_name_str")
793 ppIdFlavor :: IdLabelInfo -> SDoc
794 ppIdFlavor x = pp_cSEP <>
796 Closure -> ptext SLIT("closure")
797 SRT -> ptext SLIT("srt")
798 InfoTable -> ptext SLIT("info")
799 Entry -> ptext SLIT("entry")
800 Slow -> ptext SLIT("slow")
801 RednCounts -> ptext SLIT("ct")
802 Bitmap -> ptext SLIT("btm")
803 ConEntry -> ptext SLIT("con_entry")
804 ConInfoTable -> ptext SLIT("con_info")
805 StaticConEntry -> ptext SLIT("static_entry")
806 StaticInfoTable -> ptext SLIT("static_info")
807 ClosureTable -> ptext SLIT("closure_tbl")
813 -- -----------------------------------------------------------------------------
814 -- Machine-dependent knowledge about labels.
816 underscorePrefix :: Bool -- leading underscore on assembler labels?
817 underscorePrefix = (cLeadingUnderscore == "YES")
819 asmTempLabelPrefix :: LitString -- for formatting labels
822 {- The alpha assembler likes temporary labels to look like $L123
823 instead of L123. (Don't toss the L, because then Lf28
827 #elif darwin_TARGET_OS
833 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
835 #if x86_64_TARGET_ARCH && darwin_TARGET_OS
836 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
837 = pprCLabel lbl <> text "@GOTPCREL"
838 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
840 pprDynamicLinkerAsmLabel _ _
841 = panic "pprDynamicLinkerAsmLabel"
842 #elif darwin_TARGET_OS
843 pprDynamicLinkerAsmLabel CodeStub lbl
844 = char 'L' <> pprCLabel lbl <> text "$stub"
845 pprDynamicLinkerAsmLabel SymbolPtr lbl
846 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
847 pprDynamicLinkerAsmLabel _ _
848 = panic "pprDynamicLinkerAsmLabel"
849 #elif powerpc_TARGET_ARCH && linux_TARGET_OS
850 pprDynamicLinkerAsmLabel CodeStub lbl
851 = pprCLabel lbl <> text "@plt"
852 pprDynamicLinkerAsmLabel SymbolPtr lbl
853 = text ".LC_" <> pprCLabel lbl
854 pprDynamicLinkerAsmLabel _ _
855 = panic "pprDynamicLinkerAsmLabel"
856 #elif x86_64_TARGET_ARCH && linux_TARGET_OS
857 pprDynamicLinkerAsmLabel CodeStub lbl
858 = pprCLabel lbl <> text "@plt"
859 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
860 = pprCLabel lbl <> text "@gotpcrel"
861 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
863 pprDynamicLinkerAsmLabel SymbolPtr lbl
864 = text ".LC_" <> pprCLabel lbl
865 #elif linux_TARGET_OS
866 pprDynamicLinkerAsmLabel CodeStub lbl
867 = pprCLabel lbl <> text "@plt"
868 pprDynamicLinkerAsmLabel SymbolPtr lbl
869 = text ".LC_" <> pprCLabel lbl
870 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
871 = pprCLabel lbl <> text "@got"
872 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
873 = pprCLabel lbl <> text "@gotoff"
874 #elif mingw32_TARGET_OS
875 pprDynamicLinkerAsmLabel SymbolPtr lbl
876 = text "__imp_" <> pprCLabel lbl
877 pprDynamicLinkerAsmLabel _ _
878 = panic "pprDynamicLinkerAsmLabel"
880 pprDynamicLinkerAsmLabel _ _
881 = panic "pprDynamicLinkerAsmLabel"