[project @ 2001-01-09 17:43:57 by rrt]
[ghc-hetmet.git] / ghc / compiler / codeGen / CgConTbls.lhs
index d2fddad..9c205cc 100644 (file)
@@ -11,23 +11,16 @@ module CgConTbls ( genStaticConBits ) where
 import AbsCSyn
 import CgMonad
 
-import StgSyn          ( SRT(..) )
-import AbsCUtils       ( mkAbstractCs )
+import AbsCUtils       ( mkAbstractCs, mkAbsCStmts )
 import CgTailCall      ( performReturn, mkStaticAlgReturnCode )
-import CLabel          ( mkConEntryLabel, mkStaticClosureLabel )
 import ClosureInfo     ( layOutStaticClosure, layOutDynCon,
                          mkConLFInfo, ClosureInfo
                        )
-import CostCentre      ( dontCareCCS )
-import FiniteMap       ( fmToList, FiniteMap )
-import DataCon         ( DataCon, dataConTag, dataConName, dataConRawArgTys )
-import Const           ( Con(..) )
-import Name            ( getOccString )
-import PrimRep         ( getPrimRepSize, PrimRep(..) )
-import TyCon           ( tyConDataCons, TyCon )
-import Type            ( typePrimRep, Type )
-import BasicTypes      ( TopLevelFlag(..) )
-import Outputable      
+import DataCon         ( DataCon, dataConName, dataConRepArgTys, isNullaryDataCon )
+import Name            ( getOccName )
+import OccName         ( occNameUserString )
+import TyCon           ( tyConDataCons, isEnumerationTyCon, TyCon )
+import Type            ( typePrimRep )
 \end{code}
 
 For every constructor we generate the following info tables:
@@ -59,12 +52,9 @@ Static occurrences of the constructor
 macro: @STATIC_INFO_TABLE@.
 \end{description}
 
-For zero-arity constructors, \tr{con}, we also generate a static closure:
 
-\begin{description}
-\item[@_closure@:]
-A single static copy of the (zero-arity) constructor itself.
-\end{description}
+For zero-arity constructors, \tr{con}, we NO LONGER generate a static closure;
+it's place is taken by the top level defn of the constructor.
 
 For charlike and intlike closures there is a fixed array of static
 closures predeclared.
@@ -72,15 +62,10 @@ closures predeclared.
 \begin{code}
 genStaticConBits :: CompilationInfo    -- global info about the compilation
                 -> [TyCon]             -- tycons to generate
-                -> FiniteMap TyCon [(Bool, [Maybe Type])]
-                                       -- tycon specialisation info
                 -> AbstractC           -- output
 
-genStaticConBits comp_info gen_tycons tycon_specs
-  = ASSERT( null (fmToList tycon_specs) )
-       -- We don't do specialised type constructors any more
-
-    -- for each type constructor:
+genStaticConBits comp_info gen_tycons
+  = -- for each type constructor:
     --  grab all its data constructors;
     --     for each one, generate an info table
     -- for each specialised type constructor
@@ -96,7 +81,13 @@ genStaticConBits comp_info gen_tycons tycon_specs
   where
     gen_for_tycon :: TyCon -> AbstractC
     gen_for_tycon tycon
-      = mkAbstractCs (map (genConInfo comp_info tycon) (tyConDataCons tycon))
+      = mkAbstractCs (map (genConInfo comp_info tycon) (tyConDataCons tycon)) 
+       `mkAbsCStmts` (
+         -- after the con decls, so we don't need to declare the constructor labels
+         if (isEnumerationTyCon tycon)
+           then CClosureTbl tycon
+           else AbsCNop
+       )
 \end{code}
 
 %************************************************************************
@@ -115,8 +106,7 @@ genConInfo comp_info tycon data_con
   = mkAbstractCs [
                  CSplitMarker,
                  closure_code,
-                 static_code,
-                 closure_maybe]
+                 static_code]
        -- Order of things is to reduce forward references
   where
     (closure_info, body_code) = mkConCodeAndInfo data_con
@@ -131,45 +121,22 @@ genConInfo comp_info tycon data_con
                      profCtrC SLIT("TICK_ENT_CON") [CReg node] `thenC`
                      body_code))
 
-    entry_addr = CLbl entry_label CodePtrRep
-    con_descr  = getOccString data_con
+    con_descr  = occNameUserString (getOccName data_con)
 
     -- Don't need any dynamic closure code for zero-arity constructors
     closure_code = if zero_arity_con then 
                        AbsCNop 
                   else 
-                       CClosureInfoAndCode closure_info body Nothing 
-                          srt_info con_descr
-
-    srt_info = (error "genConInfo: no srt label", NoSRT)
-
-    static_code  = CClosureInfoAndCode static_ci body Nothing 
-                       srt_info con_descr
-
-    tag                 = dataConTag data_con
-
-    cost_centre  = mkCCostCentreStack dontCareCCS -- not worried about static data costs
-
-    -- For zero-arity data constructors, or, more accurately,
-    --          those which only have VoidRep args (or none):
-    --         We make the closure too (not just info tbl), so that we can share
-    --  one copy throughout.
-    closure_maybe = if not zero_arity_con then
-                       AbsCNop
-                   else
-                       CStaticClosure  closure_label           -- Label for closure
-                                       static_ci               -- Info table
-                                       cost_centre
-                                       [{-No args!  A slight lie for constrs 
-                                          with VoidRep args-}]
+                       CClosureInfoAndCode closure_info body Nothing con_descr
 
-    zero_size arg_ty = getPrimRepSize (typePrimRep arg_ty) == 0
+    static_code  = CClosureInfoAndCode static_ci body Nothing con_descr
 
-    zero_arity_con   = all zero_size arg_tys
+    zero_arity_con   = isNullaryDataCon data_con
+       -- We used to check that all the arg-sizes were zero, but we don't
+       -- really have any constructors with only zero-size args, and it's
+       -- just one more thing to go wrong.
 
-    arg_tys        = dataConRawArgTys     data_con
-    entry_label     = mkConEntryLabel      con_name
-    closure_label   = mkStaticClosureLabel con_name
+    arg_tys        = dataConRepArgTys  data_con
     con_name       = dataConName data_con
 \end{code}
 
@@ -179,7 +146,7 @@ mkConCodeAndInfo :: DataCon         -- Data constructor
 
 mkConCodeAndInfo con
   = let
-       arg_tys = dataConRawArgTys con
+       arg_tys = dataConRepArgTys con
 
        (closure_info, arg_things)
                = layOutDynCon con typePrimRep arg_tys