1 -----------------------------------------------------------------------------
3 -- Object-file symbols (called CLabel for histerical raisins).
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 CLabel, -- abstract type
19 mkStaticConEntryLabel,
22 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
216 = Closure -- Label for closure
217 | SRT -- Static reference table
218 | SRTDesc -- Static reference table descriptor
219 | InfoTable -- Info tables for closures; always read-only
220 | Entry -- entry point
221 | Slow -- slow entry point
223 | RednCounts -- Label of place to keep Ticky-ticky info for
226 | Bitmap -- A bitmap (function or case return)
228 | ConEntry -- constructor entry point
229 | ConInfoTable -- corresponding info table
230 | StaticConEntry -- static constructor entry point
231 | StaticInfoTable -- corresponding info table
233 | ClosureTable -- table of closures for Enum tycons
247 = RtsSelectorInfoTable Bool{-updatable-} Int{-offset-} -- Selector thunks
248 | RtsSelectorEntry Bool{-updatable-} Int{-offset-}
250 | RtsApInfoTable Bool{-updatable-} Int{-arity-} -- AP thunks
251 | RtsApEntry Bool{-updatable-} Int{-arity-}
255 | RtsInfo LitString -- misc rts info tables
256 | RtsEntry LitString -- misc rts entry points
257 | RtsRetInfo LitString -- misc rts ret info tables
258 | RtsRet LitString -- misc rts return points
259 | RtsData LitString -- misc rts data bits, eg CHARLIKE_closure
260 | RtsCode LitString -- misc rts code
262 | RtsInfoFS FastString -- misc rts info tables
263 | RtsEntryFS FastString -- misc rts entry points
264 | RtsRetInfoFS FastString -- misc rts ret info tables
265 | RtsRetFS FastString -- misc rts return points
266 | RtsDataFS FastString -- misc rts data bits, eg CHARLIKE_closure
267 | RtsCodeFS FastString -- misc rts code
269 | RtsApFast LitString -- _fast versions of generic apply
271 | RtsSlowTickyCtr String
274 -- NOTE: Eq on LitString compares the pointer only, so this isn't
277 data DynamicLinkerLabelInfo
278 = CodeStub -- MachO: Lfoo$stub, ELF: foo@plt
279 | SymbolPtr -- MachO: Lfoo$non_lazy_ptr, Windows: __imp_foo
280 | GotSymbolPtr -- ELF: foo@got
281 | GotSymbolOffset -- ELF: foo@gotoff
285 -- -----------------------------------------------------------------------------
286 -- Constructing CLabels
288 -- These are always local:
289 mkSRTLabel name = IdLabel name SRT
290 mkSRTDescLabel name = IdLabel name SRTDesc
291 mkSlowEntryLabel name = IdLabel name Slow
292 mkBitmapLabel name = IdLabel name Bitmap
293 mkRednCountsLabel name = IdLabel name RednCounts
295 -- These have local & (possibly) external variants:
296 mkLocalClosureLabel name = IdLabel name Closure
297 mkLocalInfoTableLabel name = IdLabel name InfoTable
298 mkLocalEntryLabel name = IdLabel name Entry
299 mkLocalClosureTableLabel name = IdLabel name ClosureTable
301 mkClosureLabel this_pkg name
302 | isDllName this_pkg name = DynIdLabel name Closure
303 | otherwise = IdLabel name Closure
305 mkInfoTableLabel this_pkg name
306 | isDllName this_pkg name = DynIdLabel name InfoTable
307 | otherwise = IdLabel name InfoTable
309 mkEntryLabel this_pkg name
310 | isDllName this_pkg name = DynIdLabel name Entry
311 | otherwise = IdLabel name Entry
313 mkClosureTableLabel this_pkg name
314 | isDllName this_pkg name = DynIdLabel name ClosureTable
315 | otherwise = IdLabel name ClosureTable
317 mkLocalConInfoTableLabel con = IdLabel con ConInfoTable
318 mkLocalConEntryLabel con = IdLabel con ConEntry
319 mkLocalStaticInfoTableLabel con = IdLabel con StaticInfoTable
320 mkLocalStaticConEntryLabel con = IdLabel con StaticConEntry
322 mkConInfoTableLabel name False = IdLabel name ConInfoTable
323 mkConInfoTableLabel name True = DynIdLabel name ConInfoTable
325 mkStaticInfoTableLabel name False = IdLabel name StaticInfoTable
326 mkStaticInfoTableLabel name True = DynIdLabel name StaticInfoTable
328 mkConEntryLabel this_pkg name
329 | isDllName this_pkg name = DynIdLabel name ConEntry
330 | otherwise = IdLabel name ConEntry
332 mkStaticConEntryLabel this_pkg name
333 | isDllName this_pkg name = DynIdLabel name StaticConEntry
334 | otherwise = IdLabel name StaticConEntry
337 mkReturnPtLabel uniq = CaseLabel uniq CaseReturnPt
338 mkReturnInfoLabel uniq = CaseLabel uniq CaseReturnInfo
339 mkAltLabel uniq tag = CaseLabel uniq (CaseAlt tag)
340 mkDefaultLabel uniq = CaseLabel uniq CaseDefault
342 mkStringLitLabel = StringLitLabel
343 mkAsmTempLabel = AsmTempLabel
345 mkModuleInitLabel :: PackageId -> Module -> String -> CLabel
346 mkModuleInitLabel this_pkg mod way
347 = ModuleInitLabel mod way $! modulePackageId mod /= this_pkg
349 mkPlainModuleInitLabel :: PackageId -> Module -> CLabel
350 mkPlainModuleInitLabel this_pkg mod
351 = PlainModuleInitLabel mod $! modulePackageId mod /= this_pkg
353 -- Some fixed runtime system labels
355 mkSplitMarkerLabel = RtsLabel (RtsCode SLIT("__stg_split_marker"))
356 mkDirty_MUT_VAR_Label = RtsLabel (RtsCode SLIT("dirty_MUT_VAR"))
357 mkUpdInfoLabel = RtsLabel (RtsInfo SLIT("stg_upd_frame"))
358 mkIndStaticInfoLabel = RtsLabel (RtsInfo SLIT("stg_IND_STATIC"))
359 mkMainCapabilityLabel = RtsLabel (RtsData SLIT("MainCapability"))
360 mkMAP_FROZEN_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_FROZEN0"))
361 mkMAP_DIRTY_infoLabel = RtsLabel (RtsInfo SLIT("stg_MUT_ARR_PTRS_DIRTY"))
362 mkEMPTY_MVAR_infoLabel = RtsLabel (RtsInfo SLIT("stg_EMPTY_MVAR"))
364 mkTopTickyCtrLabel = RtsLabel (RtsData SLIT("top_ct"))
365 mkCAFBlackHoleInfoTableLabel = RtsLabel (RtsInfo SLIT("stg_CAF_BLACKHOLE"))
366 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
367 RtsLabel (RtsInfo SLIT("stg_SE_CAF_BLACKHOLE"))
368 else -- RTS won't have info table unless -ticky is on
369 panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
370 mkRtsPrimOpLabel primop = RtsLabel (RtsPrimOp primop)
372 moduleRegdLabel = ModuleRegdLabel
374 mkSelectorInfoLabel upd off = RtsLabel (RtsSelectorInfoTable upd off)
375 mkSelectorEntryLabel upd off = RtsLabel (RtsSelectorEntry upd off)
377 mkApInfoTableLabel upd off = RtsLabel (RtsApInfoTable upd off)
378 mkApEntryLabel upd off = RtsLabel (RtsApEntry upd off)
382 mkForeignLabel :: FastString -> Maybe Int -> Bool -> CLabel
383 mkForeignLabel str mb_sz is_dynamic = ForeignLabel str mb_sz is_dynamic
387 mkCCLabel cc = CC_Label cc
388 mkCCSLabel ccs = CCS_Label ccs
390 mkRtsInfoLabel str = RtsLabel (RtsInfo str)
391 mkRtsEntryLabel str = RtsLabel (RtsEntry str)
392 mkRtsRetInfoLabel str = RtsLabel (RtsRetInfo str)
393 mkRtsRetLabel str = RtsLabel (RtsRet str)
394 mkRtsCodeLabel str = RtsLabel (RtsCode str)
395 mkRtsDataLabel str = RtsLabel (RtsData str)
397 mkRtsInfoLabelFS str = RtsLabel (RtsInfoFS str)
398 mkRtsEntryLabelFS str = RtsLabel (RtsEntryFS str)
399 mkRtsRetInfoLabelFS str = RtsLabel (RtsRetInfoFS str)
400 mkRtsRetLabelFS str = RtsLabel (RtsRetFS str)
401 mkRtsCodeLabelFS str = RtsLabel (RtsCodeFS str)
402 mkRtsDataLabelFS str = RtsLabel (RtsDataFS str)
404 mkRtsApFastLabel str = RtsLabel (RtsApFast str)
406 mkRtsSlowTickyCtrLabel :: String -> CLabel
407 mkRtsSlowTickyCtrLabel pat = RtsLabel (RtsSlowTickyCtr pat)
411 mkHpcTicksLabel = HpcTicksLabel
412 mkHpcModuleNameLabel = HpcModuleNameLabel
416 mkDynamicLinkerLabel :: DynamicLinkerLabelInfo -> CLabel -> CLabel
417 mkDynamicLinkerLabel = DynamicLinkerLabel
419 dynamicLinkerLabelInfo :: CLabel -> Maybe (DynamicLinkerLabelInfo, CLabel)
420 dynamicLinkerLabelInfo (DynamicLinkerLabel info lbl) = Just (info, lbl)
421 dynamicLinkerLabelInfo _ = Nothing
423 -- Position independent code
425 mkPicBaseLabel :: CLabel
426 mkPicBaseLabel = PicBaseLabel
428 mkDeadStripPreventer :: CLabel -> CLabel
429 mkDeadStripPreventer lbl = DeadStripPreventer lbl
431 -- -----------------------------------------------------------------------------
432 -- Converting info labels to entry labels.
434 infoLblToEntryLbl :: CLabel -> CLabel
435 infoLblToEntryLbl (IdLabel n InfoTable) = IdLabel n Entry
436 infoLblToEntryLbl (IdLabel n ConInfoTable) = IdLabel n ConEntry
437 infoLblToEntryLbl (IdLabel n StaticInfoTable) = IdLabel n StaticConEntry
438 infoLblToEntryLbl (DynIdLabel n InfoTable) = DynIdLabel n Entry
439 infoLblToEntryLbl (DynIdLabel n ConInfoTable) = DynIdLabel n ConEntry
440 infoLblToEntryLbl (DynIdLabel n StaticInfoTable) = DynIdLabel n StaticConEntry
441 infoLblToEntryLbl (CaseLabel n CaseReturnInfo) = CaseLabel n CaseReturnPt
442 infoLblToEntryLbl (RtsLabel (RtsInfo s)) = RtsLabel (RtsEntry s)
443 infoLblToEntryLbl (RtsLabel (RtsRetInfo s)) = RtsLabel (RtsRet s)
444 infoLblToEntryLbl (RtsLabel (RtsInfoFS s)) = RtsLabel (RtsEntryFS s)
445 infoLblToEntryLbl (RtsLabel (RtsRetInfoFS s)) = RtsLabel (RtsRetFS s)
446 infoLblToEntryLbl _ = panic "CLabel.infoLblToEntryLbl"
448 entryLblToInfoLbl :: CLabel -> CLabel
449 entryLblToInfoLbl (IdLabel n Entry) = IdLabel n InfoTable
450 entryLblToInfoLbl (IdLabel n ConEntry) = IdLabel n ConInfoTable
451 entryLblToInfoLbl (IdLabel n StaticConEntry) = IdLabel n StaticInfoTable
452 entryLblToInfoLbl (DynIdLabel n Entry) = DynIdLabel n InfoTable
453 entryLblToInfoLbl (DynIdLabel n ConEntry) = DynIdLabel n ConInfoTable
454 entryLblToInfoLbl (DynIdLabel n StaticConEntry) = DynIdLabel n StaticInfoTable
455 entryLblToInfoLbl (CaseLabel n CaseReturnPt) = CaseLabel n CaseReturnInfo
456 entryLblToInfoLbl (RtsLabel (RtsEntry s)) = RtsLabel (RtsInfo s)
457 entryLblToInfoLbl (RtsLabel (RtsRet s)) = RtsLabel (RtsRetInfo s)
458 entryLblToInfoLbl (RtsLabel (RtsEntryFS s)) = RtsLabel (RtsInfoFS s)
459 entryLblToInfoLbl (RtsLabel (RtsRetFS s)) = RtsLabel (RtsRetInfoFS s)
460 entryLblToInfoLbl l = pprPanic "CLabel.entryLblToInfoLbl" (pprCLabel l)
462 -- -----------------------------------------------------------------------------
463 -- Does a CLabel need declaring before use or not?
465 needsCDecl :: CLabel -> Bool
466 -- False <=> it's pre-declared; don't bother
467 -- don't bother declaring SRT & Bitmap labels, we always make sure
468 -- they are defined before use.
469 needsCDecl (IdLabel _ SRT) = False
470 needsCDecl (IdLabel _ SRTDesc) = False
471 needsCDecl (IdLabel _ Bitmap) = False
472 needsCDecl (IdLabel _ _) = True
473 needsCDecl (DynIdLabel _ _) = True
474 needsCDecl (CaseLabel _ _) = True
475 needsCDecl (ModuleInitLabel _ _ _) = True
476 needsCDecl (PlainModuleInitLabel _ _) = True
477 needsCDecl ModuleRegdLabel = False
479 needsCDecl (StringLitLabel _) = False
480 needsCDecl (AsmTempLabel _) = False
481 needsCDecl (RtsLabel _) = False
482 needsCDecl (ForeignLabel _ _ _) = False
483 needsCDecl (CC_Label _) = True
484 needsCDecl (CCS_Label _) = True
485 needsCDecl (HpcTicksLabel _) = True
486 needsCDecl HpcModuleNameLabel = False
488 -- Whether the label is an assembler temporary:
490 isAsmTemp :: CLabel -> Bool -- is a local temporary for native code generation
491 isAsmTemp (AsmTempLabel _) = True
494 maybeAsmTemp :: CLabel -> Maybe Unique
495 maybeAsmTemp (AsmTempLabel uq) = Just uq
496 maybeAsmTemp _ = Nothing
498 -- -----------------------------------------------------------------------------
499 -- Is a CLabel visible outside this object file or not?
501 -- From the point of view of the code generator, a name is
502 -- externally visible if it has to be declared as exported
503 -- in the .o file's symbol table; that is, made non-static.
505 externallyVisibleCLabel :: CLabel -> Bool -- not C "static"
506 externallyVisibleCLabel (CaseLabel _ _) = False
507 externallyVisibleCLabel (StringLitLabel _) = False
508 externallyVisibleCLabel (AsmTempLabel _) = False
509 externallyVisibleCLabel (ModuleInitLabel _ _ _)= True
510 externallyVisibleCLabel (PlainModuleInitLabel _ _)= True
511 externallyVisibleCLabel ModuleRegdLabel = False
512 externallyVisibleCLabel (RtsLabel _) = True
513 externallyVisibleCLabel (ForeignLabel _ _ _) = True
514 externallyVisibleCLabel (IdLabel name _) = isExternalName name
515 externallyVisibleCLabel (DynIdLabel name _) = isExternalName name
516 externallyVisibleCLabel (CC_Label _) = True
517 externallyVisibleCLabel (CCS_Label _) = True
518 externallyVisibleCLabel (DynamicLinkerLabel _ _) = False
519 externallyVisibleCLabel (HpcTicksLabel _) = True
520 externallyVisibleCLabel HpcModuleNameLabel = False
522 -- -----------------------------------------------------------------------------
523 -- Finding the "type" of a CLabel
525 -- For generating correct types in label declarations:
531 labelType :: CLabel -> CLabelType
532 labelType (RtsLabel (RtsSelectorInfoTable _ _)) = DataLabel
533 labelType (RtsLabel (RtsApInfoTable _ _)) = DataLabel
534 labelType (RtsLabel (RtsData _)) = DataLabel
535 labelType (RtsLabel (RtsCode _)) = CodeLabel
536 labelType (RtsLabel (RtsInfo _)) = DataLabel
537 labelType (RtsLabel (RtsEntry _)) = CodeLabel
538 labelType (RtsLabel (RtsRetInfo _)) = DataLabel
539 labelType (RtsLabel (RtsRet _)) = CodeLabel
540 labelType (RtsLabel (RtsDataFS _)) = DataLabel
541 labelType (RtsLabel (RtsCodeFS _)) = CodeLabel
542 labelType (RtsLabel (RtsInfoFS _)) = DataLabel
543 labelType (RtsLabel (RtsEntryFS _)) = CodeLabel
544 labelType (RtsLabel (RtsRetInfoFS _)) = DataLabel
545 labelType (RtsLabel (RtsRetFS _)) = CodeLabel
546 labelType (RtsLabel (RtsApFast _)) = CodeLabel
547 labelType (CaseLabel _ CaseReturnInfo) = DataLabel
548 labelType (CaseLabel _ _) = CodeLabel
549 labelType (ModuleInitLabel _ _ _) = CodeLabel
550 labelType (PlainModuleInitLabel _ _) = CodeLabel
552 labelType (IdLabel _ info) = idInfoLabelType info
553 labelType (DynIdLabel _ info) = idInfoLabelType info
554 labelType _ = DataLabel
556 idInfoLabelType info =
558 InfoTable -> DataLabel
561 ConInfoTable -> DataLabel
562 StaticInfoTable -> DataLabel
563 ClosureTable -> DataLabel
564 -- krc: aie! a ticky counter label is data
565 RednCounts -> DataLabel
569 -- -----------------------------------------------------------------------------
570 -- Does a CLabel need dynamic linkage?
572 -- When referring to data in code, we need to know whether
573 -- that data resides in a DLL or not. [Win32 only.]
574 -- @labelDynamic@ returns @True@ if the label is located
575 -- in a DLL, be it a data reference or not.
577 labelDynamic :: CLabel -> Bool
580 RtsLabel _ -> not opt_Static -- i.e., is the RTS in a DLL or not?
582 DynIdLabel n k -> True
583 #if mingw32_TARGET_OS
584 ForeignLabel _ _ d -> d
586 -- On Mac OS X and on ELF platforms, false positives are OK,
587 -- so we claim that all foreign imports come from dynamic libraries
588 ForeignLabel _ _ _ -> True
590 ModuleInitLabel m _ dyn -> not opt_Static && dyn
591 PlainModuleInitLabel m dyn -> not opt_Static && dyn
593 -- Note that DynamicLinkerLabels do NOT require dynamic linking themselves.
597 OLD?: These GRAN functions are needed for spitting out GRAN_FETCH() at the
598 right places. It is used to detect when the abstractC statement of an
599 CCodeBlock actually contains the code for a slow entry point. -- HWL
601 We need at least @Eq@ for @CLabels@, because we want to avoid
602 duplicate declarations in generating C (see @labelSeenTE@ in
606 -----------------------------------------------------------------------------
607 -- Printing out CLabels.
614 where <name> is <Module>_<name> for external names and <unique> for
615 internal names. <type> is one of the following:
618 srt Static reference table
619 srtd Static reference table descriptor
620 entry Entry code (function, closure)
621 slow Slow entry code (if any)
622 ret Direct return address
624 <n>_alt Case alternative (tag n)
625 dflt Default case alternative
626 btm Large bitmap vector
627 closure Static closure
628 con_entry Dynamic Constructor entry code
629 con_info Dynamic Constructor info table
630 static_entry Static Constructor entry code
631 static_info Static Constructor info table
632 sel_info Selector info table
633 sel_entry Selector entry code
635 ccs Cost centre stack
637 Many of these distinctions are only for documentation reasons. For
638 example, _ret is only distinguished from _entry to make it easy to
639 tell whether a code fragment is a return point or a closure/function
643 instance Outputable CLabel where
646 pprCLabel :: CLabel -> SDoc
648 #if ! OMIT_NATIVE_CODEGEN
649 pprCLabel (AsmTempLabel u)
650 = getPprStyle $ \ sty ->
652 ptext asmTempLabelPrefix <> pprUnique u
654 char '_' <> pprUnique u
656 pprCLabel (DynamicLinkerLabel info lbl)
657 = pprDynamicLinkerAsmLabel info lbl
659 pprCLabel PicBaseLabel
662 pprCLabel (DeadStripPreventer lbl)
663 = pprCLabel lbl <> ptext SLIT("_dsp")
667 #if ! OMIT_NATIVE_CODEGEN
668 getPprStyle $ \ sty ->
670 maybe_underscore (pprAsmCLbl lbl)
676 | underscorePrefix = pp_cSEP <> doc
679 #ifdef mingw32_TARGET_OS
680 -- In asm mode, we need to put the suffix on a stdcall ForeignLabel.
681 -- (The C compiler does this itself).
682 pprAsmCLbl (ForeignLabel fs (Just sz) _)
683 = ftext fs <> char '@' <> int sz
688 pprCLbl (StringLitLabel u)
689 = pprUnique u <> ptext SLIT("_str")
691 pprCLbl (CaseLabel u CaseReturnPt)
692 = hcat [pprUnique u, ptext SLIT("_ret")]
693 pprCLbl (CaseLabel u CaseReturnInfo)
694 = hcat [pprUnique u, ptext SLIT("_info")]
695 pprCLbl (CaseLabel u (CaseAlt tag))
696 = hcat [pprUnique u, pp_cSEP, int tag, ptext SLIT("_alt")]
697 pprCLbl (CaseLabel u CaseDefault)
698 = hcat [pprUnique u, ptext SLIT("_dflt")]
700 pprCLbl (RtsLabel (RtsCode str)) = ptext str
701 pprCLbl (RtsLabel (RtsData str)) = ptext str
702 pprCLbl (RtsLabel (RtsCodeFS str)) = ftext str
703 pprCLbl (RtsLabel (RtsDataFS str)) = ftext str
705 pprCLbl (RtsLabel (RtsApFast str)) = ptext str <> ptext SLIT("_fast")
707 pprCLbl (RtsLabel (RtsSelectorInfoTable upd_reqd offset))
708 = hcat [ptext SLIT("stg_sel_"), text (show offset),
710 then SLIT("_upd_info")
711 else SLIT("_noupd_info"))
714 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
715 = hcat [ptext SLIT("stg_sel_"), text (show offset),
717 then SLIT("_upd_entry")
718 else SLIT("_noupd_entry"))
721 pprCLbl (RtsLabel (RtsApInfoTable upd_reqd arity))
722 = hcat [ptext SLIT("stg_ap_"), text (show arity),
724 then SLIT("_upd_info")
725 else SLIT("_noupd_info"))
728 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
729 = hcat [ptext SLIT("stg_ap_"), text (show arity),
731 then SLIT("_upd_entry")
732 else SLIT("_noupd_entry"))
735 pprCLbl (RtsLabel (RtsInfo fs))
736 = ptext fs <> ptext SLIT("_info")
738 pprCLbl (RtsLabel (RtsEntry fs))
739 = ptext fs <> ptext SLIT("_entry")
741 pprCLbl (RtsLabel (RtsRetInfo fs))
742 = ptext fs <> ptext SLIT("_info")
744 pprCLbl (RtsLabel (RtsRet fs))
745 = ptext fs <> ptext SLIT("_ret")
747 pprCLbl (RtsLabel (RtsInfoFS fs))
748 = ftext fs <> ptext SLIT("_info")
750 pprCLbl (RtsLabel (RtsEntryFS fs))
751 = ftext fs <> ptext SLIT("_entry")
753 pprCLbl (RtsLabel (RtsRetInfoFS fs))
754 = ftext fs <> ptext SLIT("_info")
756 pprCLbl (RtsLabel (RtsRetFS fs))
757 = ftext fs <> ptext SLIT("_ret")
759 pprCLbl (RtsLabel (RtsPrimOp primop))
760 = ppr primop <> ptext SLIT("_fast")
762 pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
763 = ptext SLIT("SLOW_CALL_") <> text pat <> ptext SLIT("_ctr")
765 pprCLbl ModuleRegdLabel
766 = ptext SLIT("_module_registered")
768 pprCLbl (ForeignLabel str _ _)
771 pprCLbl (IdLabel name flavor) = ppr name <> ppIdFlavor flavor
772 pprCLbl (DynIdLabel name flavor) = ppr name <> ppIdFlavor flavor
774 pprCLbl (CC_Label cc) = ppr cc
775 pprCLbl (CCS_Label ccs) = ppr ccs
777 pprCLbl (ModuleInitLabel mod way _)
778 = ptext SLIT("__stginit_") <> ppr mod
779 <> char '_' <> text way
780 pprCLbl (PlainModuleInitLabel mod _)
781 = ptext SLIT("__stginit_") <> ppr mod
783 pprCLbl (HpcTicksLabel mod)
784 = ptext SLIT("_hpc_tickboxes_") <> ppr mod <> ptext SLIT("_hpc")
786 pprCLbl HpcModuleNameLabel
787 = ptext SLIT("_hpc_module_name_str")
789 ppIdFlavor :: IdLabelInfo -> SDoc
790 ppIdFlavor x = pp_cSEP <>
792 Closure -> ptext SLIT("closure")
793 SRT -> ptext SLIT("srt")
794 SRTDesc -> ptext SLIT("srtd")
795 InfoTable -> ptext SLIT("info")
796 Entry -> ptext SLIT("entry")
797 Slow -> ptext SLIT("slow")
798 RednCounts -> ptext SLIT("ct")
799 Bitmap -> ptext SLIT("btm")
800 ConEntry -> ptext SLIT("con_entry")
801 ConInfoTable -> ptext SLIT("con_info")
802 StaticConEntry -> ptext SLIT("static_entry")
803 StaticInfoTable -> ptext SLIT("static_info")
804 ClosureTable -> ptext SLIT("closure_tbl")
810 -- -----------------------------------------------------------------------------
811 -- Machine-dependent knowledge about labels.
813 underscorePrefix :: Bool -- leading underscore on assembler labels?
814 underscorePrefix = (cLeadingUnderscore == "YES")
816 asmTempLabelPrefix :: LitString -- for formatting labels
819 {- The alpha assembler likes temporary labels to look like $L123
820 instead of L123. (Don't toss the L, because then Lf28
824 #elif darwin_TARGET_OS
830 pprDynamicLinkerAsmLabel :: DynamicLinkerLabelInfo -> CLabel -> SDoc
832 #if x86_64_TARGET_ARCH && darwin_TARGET_OS
833 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
834 = pprCLabel lbl <> text "@GOTPCREL"
835 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
837 pprDynamicLinkerAsmLabel _ _
838 = panic "pprDynamicLinkerAsmLabel"
839 #elif darwin_TARGET_OS
840 pprDynamicLinkerAsmLabel CodeStub lbl
841 = char 'L' <> pprCLabel lbl <> text "$stub"
842 pprDynamicLinkerAsmLabel SymbolPtr lbl
843 = char 'L' <> pprCLabel lbl <> text "$non_lazy_ptr"
844 pprDynamicLinkerAsmLabel _ _
845 = panic "pprDynamicLinkerAsmLabel"
846 #elif powerpc_TARGET_ARCH && linux_TARGET_OS
847 pprDynamicLinkerAsmLabel CodeStub lbl
848 = pprCLabel lbl <> text "@plt"
849 pprDynamicLinkerAsmLabel SymbolPtr lbl
850 = text ".LC_" <> pprCLabel lbl
851 pprDynamicLinkerAsmLabel _ _
852 = panic "pprDynamicLinkerAsmLabel"
853 #elif x86_64_TARGET_ARCH && linux_TARGET_OS
854 pprDynamicLinkerAsmLabel CodeStub lbl
855 = pprCLabel lbl <> text "@plt"
856 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
857 = pprCLabel lbl <> text "@gotpcrel"
858 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
860 pprDynamicLinkerAsmLabel _ _
861 = panic "pprDynamicLinkerAsmLabel"
862 #elif linux_TARGET_OS
863 pprDynamicLinkerAsmLabel CodeStub lbl
864 = pprCLabel lbl <> text "@plt"
865 pprDynamicLinkerAsmLabel SymbolPtr lbl
866 = text ".LC_" <> pprCLabel lbl
867 pprDynamicLinkerAsmLabel GotSymbolPtr lbl
868 = pprCLabel lbl <> text "@got"
869 pprDynamicLinkerAsmLabel GotSymbolOffset lbl
870 = pprCLabel lbl <> text "@gotoff"
871 #elif mingw32_TARGET_OS
872 pprDynamicLinkerAsmLabel SymbolPtr lbl
873 = text "__imp_" <> pprCLabel lbl
874 pprDynamicLinkerAsmLabel _ _
875 = panic "pprDynamicLinkerAsmLabel"
877 pprDynamicLinkerAsmLabel _ _
878 = panic "pprDynamicLinkerAsmLabel"