[project @ 2002-07-18 09:16:12 by simonmar]
[ghc-hetmet.git] / ghc / compiler / absCSyn / CLabel.lhs
index a40f559..442dc01 100644 (file)
@@ -1,7 +1,7 @@
 %
 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
-% $Id: CLabel.lhs,v 1.41 2000/11/06 08:15:20 simonpj Exp $
+% $Id: CLabel.lhs,v 1.54 2002/07/18 09:16:12 simonmar Exp $
 %
 \section[CLabel]{@CLabel@: Information to make C Labels}
 
@@ -34,6 +34,7 @@ module CLabel (
        mkAsmTempLabel,
 
        mkModuleInitLabel,
+       mkPlainModuleInitLabel,
 
        mkErrorStdEntryLabel,
 
@@ -44,10 +45,11 @@ module CLabel (
        mkIndInfoLabel,
        mkIndStaticInfoLabel,
        mkRtsGCEntryLabel,
-        mkMainRegTableLabel,
+        mkMainCapabilityLabel,
        mkCharlikeClosureLabel,
        mkIntlikeClosureLabel,
        mkMAP_FROZEN_infoLabel,
+        mkEMPTY_MVAR_infoLabel,
 
        mkTopTickyCtrLabel,
        mkBlackHoleInfoTableLabel,
@@ -69,9 +71,6 @@ module CLabel (
        CLabelType(..), labelType, labelDynamic,
 
        pprCLabel
-#if ! OMIT_NATIVE_CODEGEN
-       , pprCLabel_asm
-#endif
     ) where
 
 
@@ -85,13 +84,15 @@ import CmdLineOpts      ( opt_Static, opt_DoTickyProfiling )
 import CStrings                ( pp_cSEP )
 import DataCon         ( ConTag )
 import Module          ( moduleName, moduleNameFS, 
-                         Module, isModuleInThisPackage )
-import Name            ( Name, getName, isDllName, isExternallyVisibleName )
+                         Module, isHomeModule )
+import Name            ( Name, getName, isDllName, isExternalName )
 import TyCon           ( TyCon )
 import Unique          ( pprUnique, Unique )
-import PrimOp          ( PrimOp, pprPrimOp )
+import PrimOp          ( PrimOp )
 import CostCentre      ( CostCentre, CostCentreStack )
+import BasicTypes      ( Version )
 import Outputable
+import FastString
 \end{code}
 
 things we want to find out:
@@ -124,11 +125,20 @@ data CLabel
 
   | AsmTempLabel    Unique
 
-  | ModuleInitLabel Module
+  | ModuleInitLabel 
+       Module                  -- the module name
+       String                  -- its "way"
+       -- at some point we might want some kind of version number in
+       -- the module init label, to guard against compiling modules in
+       -- the wrong order.  We can't use the interface file version however,
+       -- because we don't always recompile modules which depend on a module
+       -- whose version has changed.
+
+  | PlainModuleInitLabel Module         -- without the vesrion & way info
 
   | RtsLabel       RtsLabelInfo
 
-  | ForeignLabel FAST_STRING Bool  -- a 'C' (or otherwise foreign) label
+  | ForeignLabel FastString Bool  -- a 'C' (or otherwise foreign) label
                                   -- Bool <=> is dynamic
 
   | CC_Label CostCentre
@@ -175,12 +185,12 @@ data CaseLabelInfo
 data RtsLabelInfo
   = RtsShouldNeverHappenCode
 
-  | RtsBlackHoleInfoTbl FAST_STRING  -- black hole with info table name
+  | RtsBlackHoleInfoTbl FastString  -- black hole with info table name
 
   | RtsUpdInfo                 -- upd_frame_info
   | RtsSeqInfo                 -- seq_frame_info
   | RtsGCEntryLabel String     -- a heap check fail handler, eg  stg_chk_2
-  | RtsMainRegTable             -- MainRegTable (??? Capabilities wurble ???)
+  | RtsMainCapability           -- MainCapability
   | Rts_Closure String         -- misc rts closures, eg CHARLIKE_closure
   | Rts_Info String            -- misc rts itbls, eg MUT_ARR_PTRS_FROZEN_info
   | Rts_Code String            -- misc rts code
@@ -238,6 +248,7 @@ mkClosureTblLabel tycon             = TyConLabel tycon
 mkAsmTempLabel                         = AsmTempLabel
 
 mkModuleInitLabel              = ModuleInitLabel
+mkPlainModuleInitLabel         = PlainModuleInitLabel
 
        -- Some fixed runtime system labels
 
@@ -246,19 +257,20 @@ mkStgUpdatePAPLabel               = RtsLabel (Rts_Code "stg_update_PAP")
 mkSplitMarkerLabel             = RtsLabel (Rts_Code "__stg_split_marker")
 mkUpdInfoLabel                 = RtsLabel RtsUpdInfo
 mkSeqInfoLabel                 = RtsLabel RtsSeqInfo
-mkIndInfoLabel                 = RtsLabel (Rts_Info "IND_info")
-mkIndStaticInfoLabel           = RtsLabel (Rts_Info "IND_STATIC_info")
+mkIndInfoLabel                 = RtsLabel (Rts_Info "stg_IND_info")
+mkIndStaticInfoLabel           = RtsLabel (Rts_Info "stg_IND_STATIC_info")
 mkRtsGCEntryLabel str          = RtsLabel (RtsGCEntryLabel str)
-mkMainRegTableLabel            = RtsLabel RtsMainRegTable
-mkCharlikeClosureLabel         = RtsLabel (Rts_Closure "CHARLIKE_closure")
-mkIntlikeClosureLabel          = RtsLabel (Rts_Closure "INTLIKE_closure")
-mkMAP_FROZEN_infoLabel         = RtsLabel (Rts_Info "MUT_ARR_PTRS_FROZEN_info")
+mkMainCapabilityLabel          = RtsLabel RtsMainCapability
+mkCharlikeClosureLabel         = RtsLabel (Rts_Closure "stg_CHARLIKE_closure")
+mkIntlikeClosureLabel          = RtsLabel (Rts_Closure "stg_INTLIKE_closure")
+mkMAP_FROZEN_infoLabel         = RtsLabel (Rts_Info "stg_MUT_ARR_PTRS_FROZEN_info")
+mkEMPTY_MVAR_infoLabel         = RtsLabel (Rts_Info "stg_EMPTY_MVAR_info")
 
 mkTopTickyCtrLabel             = RtsLabel RtsTopTickyCtr
-mkBlackHoleInfoTableLabel      = RtsLabel (RtsBlackHoleInfoTbl SLIT("BLACKHOLE_info"))
-mkCAFBlackHoleInfoTableLabel   = RtsLabel (RtsBlackHoleInfoTbl SLIT("CAF_BLACKHOLE_info"))
+mkBlackHoleInfoTableLabel      = RtsLabel (RtsBlackHoleInfoTbl FSLIT("stg_BLACKHOLE_info"))
+mkCAFBlackHoleInfoTableLabel   = RtsLabel (RtsBlackHoleInfoTbl FSLIT("stg_CAF_BLACKHOLE_info"))
 mkSECAFBlackHoleInfoTableLabel = if opt_DoTickyProfiling then
-                                    RtsLabel (RtsBlackHoleInfoTbl SLIT("SE_CAF_BLACKHOLE_info"))
+                                    RtsLabel (RtsBlackHoleInfoTbl FSLIT("stg_SE_CAF_BLACKHOLE_info"))
                                   else  -- RTS won't have info table unless -ticky is on
                                     panic "mkSECAFBlackHoleInfoTableLabel requires -ticky"
 mkRtsPrimOpLabel primop                = RtsLabel (RtsPrimOp primop)
@@ -273,7 +285,7 @@ mkApEntryLabel upd off              = RtsLabel (RtsApEntry   upd off)
 
        -- Foreign labels
 
-mkForeignLabel :: FAST_STRING -> Bool -> CLabel
+mkForeignLabel :: FastString -> Bool -> CLabel
 mkForeignLabel str is_dynamic  = ForeignLabel str is_dynamic
 
        -- Cost centres etc.
@@ -305,7 +317,8 @@ needsCDecl (IdLabel _ _)            = True
 needsCDecl (CaseLabel _ CaseReturnPt)  = True
 needsCDecl (DataConLabel _ _)          = True
 needsCDecl (TyConLabel _)              = True
-needsCDecl (ModuleInitLabel _)         = True
+needsCDecl (ModuleInitLabel _ _)       = True
+needsCDecl (PlainModuleInitLabel _)    = True
 
 needsCDecl (CaseLabel _ _)             = False
 needsCDecl (AsmTempLabel _)            = False
@@ -332,11 +345,12 @@ externallyVisibleCLabel (DataConLabel _ _) = True
 externallyVisibleCLabel (TyConLabel tc)    = True
 externallyVisibleCLabel (CaseLabel _ _)           = False
 externallyVisibleCLabel (AsmTempLabel _)   = False
-externallyVisibleCLabel (ModuleInitLabel _)= True
+externallyVisibleCLabel (ModuleInitLabel _ _)= True
+externallyVisibleCLabel (PlainModuleInitLabel _)= True
 externallyVisibleCLabel (RtsLabel RtsModuleRegd) = False --hack
 externallyVisibleCLabel (RtsLabel _)      = True
 externallyVisibleCLabel (ForeignLabel _ _) = True
-externallyVisibleCLabel (IdLabel id _)     = isExternallyVisibleName id
+externallyVisibleCLabel (IdLabel id _)     = isExternalName id
 externallyVisibleCLabel (CC_Label _)      = False -- not strictly true
 externallyVisibleCLabel (CCS_Label _)     = False -- not strictly true
 \end{code}
@@ -349,11 +363,13 @@ labelType (RtsLabel (RtsBlackHoleInfoTbl _))  = InfoTblType
 labelType (RtsLabel (RtsSelectorInfoTbl _ _)) = InfoTblType
 labelType (RtsLabel (RtsApInfoTbl _ _))       = InfoTblType
 labelType (RtsLabel RtsUpdInfo)              = InfoTblType
+labelType (RtsLabel (Rts_Info _))             = InfoTblType
 labelType (CaseLabel _ CaseReturnInfo)        = InfoTblType
 labelType (CaseLabel _ CaseReturnPt)         = CodeType
 labelType (CaseLabel _ CaseVecTbl)            = VecTblType
 labelType (TyConLabel _)                     = ClosureTblType
-labelType (ModuleInitLabel _ )                = CodeType
+labelType (ModuleInitLabel _ _)               = CodeType
+labelType (PlainModuleInitLabel _)            = CodeType
 
 labelType (IdLabel _ info) = 
   case info of
@@ -387,7 +403,8 @@ labelDynamic lbl =
    DataConLabel n k  -> isDllName n
    TyConLabel tc     -> isDllName (getName tc)
    ForeignLabel _ d  -> d
-   ModuleInitLabel m -> (not opt_Static) && (not (isModuleInThisPackage m))
+   ModuleInitLabel m _  -> (not opt_Static) && (not (isHomeModule m))
+   PlainModuleInitLabel m -> (not opt_Static) && (not (isHomeModule m))
    _                -> False
 \end{code}
 
@@ -429,11 +446,6 @@ internal names. <type> is one of the following:
         ccs                    Cost centre stack
 
 \begin{code}
--- specialised for PprAsm: saves lots of arg passing in NCG
-#if ! OMIT_NATIVE_CODEGEN
-pprCLabel_asm = pprCLabel
-#endif
-
 pprCLabel :: CLabel -> SDoc
 
 #if ! OMIT_NATIVE_CODEGEN
@@ -467,9 +479,9 @@ pprCLbl (RtsLabel RtsShouldNeverHappenCode) = ptext SLIT("NULL")
 -- used to be stg_error_entry but Windows can't have DLL entry points as static
 -- initialisers, and besides, this ShouldNeverHappen, right?
 
-pprCLbl (RtsLabel RtsUpdInfo)            = ptext SLIT("upd_frame_info")
-pprCLbl (RtsLabel RtsSeqInfo)            = ptext SLIT("seq_frame_info")
-pprCLbl (RtsLabel RtsMainRegTable)       = ptext SLIT("MainRegTable")
+pprCLbl (RtsLabel RtsUpdInfo)            = ptext SLIT("stg_upd_frame_info")
+pprCLbl (RtsLabel RtsSeqInfo)            = ptext SLIT("stg_seq_frame_info")
+pprCLbl (RtsLabel RtsMainCapability)     = ptext SLIT("MainCapability")
 pprCLbl (RtsLabel (RtsGCEntryLabel str)) = text str
 pprCLbl (RtsLabel (Rts_Closure str))     = text str
 pprCLbl (RtsLabel (Rts_Info str))        = text str
@@ -477,44 +489,44 @@ pprCLbl (RtsLabel (Rts_Code str))        = text str
 
 pprCLbl (RtsLabel RtsTopTickyCtr) = ptext SLIT("top_ct")
 
-pprCLbl (RtsLabel (RtsBlackHoleInfoTbl info)) = ptext info
+pprCLbl (RtsLabel (RtsBlackHoleInfoTbl info)) = ftext info
 
 pprCLbl (RtsLabel (RtsSelectorInfoTbl upd_reqd offset))
-  = hcat [ptext SLIT("__sel_"), text (show offset),
+  = hcat [ptext SLIT("stg_sel_"), text (show offset),
                ptext (if upd_reqd 
                        then SLIT("_upd_info") 
                        else SLIT("_noupd_info"))
        ]
 
 pprCLbl (RtsLabel (RtsSelectorEntry upd_reqd offset))
-  = hcat [ptext SLIT("__sel_"), text (show offset),
+  = hcat [ptext SLIT("stg_sel_"), text (show offset),
                ptext (if upd_reqd 
                        then SLIT("_upd_entry") 
                        else SLIT("_noupd_entry"))
        ]
 
 pprCLbl (RtsLabel (RtsApInfoTbl upd_reqd arity))
-  = hcat [ptext SLIT("__ap_"), text (show arity),
+  = hcat [ptext SLIT("stg_ap_"), text (show arity),
                ptext (if upd_reqd 
                        then SLIT("_upd_info") 
                        else SLIT("_noupd_info"))
        ]
 
 pprCLbl (RtsLabel (RtsApEntry upd_reqd arity))
-  = hcat [ptext SLIT("__ap_"), text (show arity),
+  = hcat [ptext SLIT("stg_ap_"), text (show arity),
                ptext (if upd_reqd 
                        then SLIT("_upd_entry") 
                        else SLIT("_noupd_entry"))
        ]
 
 pprCLbl (RtsLabel (RtsPrimOp primop)) 
-  = pprPrimOp primop <> ptext SLIT("_fast")
+  = ppr primop <> ptext SLIT("_fast")
 
 pprCLbl (RtsLabel RtsModuleRegd)
   = ptext SLIT("module_registered")
 
 pprCLbl (ForeignLabel str _)
-  = ptext str
+  = ftext str
 
 pprCLbl (TyConLabel tc)
   = hcat [ppr tc, pp_cSEP, ptext SLIT("closure_tbl")]
@@ -525,8 +537,12 @@ pprCLbl (DataConLabel con flavor) = ppr con <> ppConFlavor flavor
 pprCLbl (CC_Label cc)          = ppr cc
 pprCLbl (CCS_Label ccs)        = ppr ccs
 
-pprCLbl (ModuleInitLabel mod)  
-   = ptext SLIT("__init_") <> ptext (moduleNameFS (moduleName mod))
+pprCLbl (ModuleInitLabel mod way)      
+   = ptext SLIT("__stginit_") <> ftext (moduleNameFS (moduleName mod))
+       <> char '_' <> text way
+
+pprCLbl (PlainModuleInitLabel mod)     
+   = ptext SLIT("__stginit_") <> ftext (moduleNameFS (moduleName mod))
 
 ppIdFlavor :: IdLabelInfo -> SDoc