Use OPTIONS rather than OPTIONS_GHC for pragmas
[ghc-hetmet.git] / compiler / codeGen / CgInfoTbls.hs
index f6277f1..3d28a58 100644 (file)
@@ -6,6 +6,13 @@
 --
 -----------------------------------------------------------------------------
 
+{-# OPTIONS -w #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+--     http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings
+-- for details
+
 module CgInfoTbls (
        emitClosureCodeAndInfoTable,
        emitInfoTableAndCode,
@@ -15,6 +22,7 @@ module CgInfoTbls (
        stdInfoTableSizeB,
        entryCode, closureInfoPtr,
        getConstrTag,
+        cmmGetClosureType,
        infoTable, infoTableClosureType,
        infoTablePtrs, infoTableNonPtrs,
        funInfoTable, makeRelativeRefTo
@@ -60,7 +68,7 @@ emitClosureCodeAndInfoTable :: ClosureInfo -> CmmFormals -> CgStmts -> Code
 emitClosureCodeAndInfoTable cl_info args body
  = do  { blks <- cgStmtsToBlocks body
         ; info <- mkCmmInfo cl_info
-        ; emitInfoTableAndCode info_lbl info args blks }
+        ; emitInfoTableAndCode (infoLblToEntryLbl info_lbl) info args blks }
   where
     info_lbl  = infoTableLabelFromCI cl_info
 
@@ -73,13 +81,11 @@ dataConTagZ con = dataConTag con - fIRST_TAG
 -- Not used for return points.  (The 'smRepClosureTypeInt' call would panic.)
 mkCmmInfo :: ClosureInfo -> FCode CmmInfo
 mkCmmInfo cl_info = do
-  prof <- 
-      if opt_SccProfilingOn 
+  prof <-
+      if opt_SccProfilingOn
       then do ty_descr_lit <- mkStringCLit (closureTypeDescr cl_info)
               cl_descr_lit <- mkStringCLit (closureValDescr cl_info)
-              return $ ProfilingInfo
-                         (makeRelativeRefTo info_lbl ty_descr_lit)
-                         (makeRelativeRefTo info_lbl cl_descr_lit)
+              return $ ProfilingInfo ty_descr_lit cl_descr_lit
       else return $ ProfilingInfo (mkIntCLit 0) (mkIntCLit 0)
 
   case cl_info of
@@ -151,7 +157,7 @@ emitReturnTarget name stmts
                         (ProfilingInfo zeroCLit zeroCLit)
                         rET_SMALL -- cmmToRawCmm may convert it to rET_BIG
                         (ContInfo frame srt_info))
-        ; emitInfoTableAndCode info_lbl info args blks
+        ; emitInfoTableAndCode (infoLblToEntryLbl info_lbl) info args blks
        ; return info_lbl }
   where
     args      = {- trace "emitReturnTarget: missing args" -} []
@@ -273,14 +279,24 @@ emitAlgReturnTarget
 
 emitAlgReturnTarget name branches mb_deflt fam_sz
   = do  { blks <- getCgStmts $
-                   emitSwitch tag_expr branches mb_deflt 0 (fam_sz - 1)
-               -- NB: tag_expr is zero-based
+                    -- is the constructor tag in the node reg?
+                    if isSmallFamily fam_sz
+                        then do -- yes, node has constr. tag
+                          let tag_expr = cmmConstrTag1 (CmmReg nodeReg)
+                              branches' = [(tag+1,branch)|(tag,branch)<-branches]
+                          emitSwitch tag_expr branches' mb_deflt 1 fam_sz
+                        else do -- no, get tag from info table
+                          let -- Note that ptr _always_ has tag 1
+                              -- when the family size is big enough
+                              untagged_ptr = cmmRegOffB nodeReg (-1)
+                              tag_expr = getConstrTag (untagged_ptr)
+                          emitSwitch tag_expr branches mb_deflt 0 (fam_sz - 1)
        ; lbl <- emitReturnTarget name blks
        ; return (lbl, Nothing) }
                -- Nothing: the internal branches in the switch don't have
                -- global labels, so we can't use them at the 'call site'
   where
-    tag_expr = getConstrTag (CmmReg nodeReg)
+    uniq = getUnique name 
 
 --------------------------------
 emitReturnInstr :: Code
@@ -346,6 +362,14 @@ getConstrTag closure_ptr
   where
     info_table = infoTable (closureInfoPtr closure_ptr)
 
+cmmGetClosureType :: CmmExpr -> CmmExpr
+-- Takes a closure pointer, and return the closure type
+-- obtained from the info table
+cmmGetClosureType closure_ptr 
+  = CmmMachOp (MO_U_Conv halfWordRep wordRep) [infoTableClosureType info_table]
+  where
+    info_table = infoTable (closureInfoPtr closure_ptr)
+
 infoTable :: CmmExpr -> CmmExpr
 -- Takes an info pointer (the first word of a closure)
 -- and returns a pointer to the first word of the standard-form
@@ -401,16 +425,14 @@ funInfoTable info_ptr
 -- put the info table next to the code
 
 emitInfoTableAndCode 
-       :: CLabel               -- Label of info table
+       :: CLabel               -- Label of entry or ret
        -> CmmInfo              -- ...the info table
        -> CmmFormals           -- ...args
        -> [CmmBasicBlock]      -- ...and body
        -> Code
 
-emitInfoTableAndCode info_lbl info args blocks
-  = emitProc info entry_lbl args blocks
-  where
-       entry_lbl = infoLblToEntryLbl info_lbl
+emitInfoTableAndCode entry_ret_lbl info args blocks
+  = emitProc info entry_ret_lbl args blocks
 
 -------------------------------------------------------------------------
 --