[project @ 2000-04-21 12:57:54 by simonpj]
[ghc-hetmet.git] / ghc / compiler / absCSyn / AbsCUtils.lhs
index e76042f..e7a563e 100644 (file)
@@ -22,15 +22,15 @@ module AbsCUtils (
 import AbsCSyn
 import Digraph         ( stronglyConnComp, SCC(..) )
 import DataCon         ( fIRST_TAG, ConTag )
-import Const           ( literalPrimRep, mkMachWord )
+import Literal         ( literalPrimRep, mkMachWord )
 import PrimRep         ( getPrimRepSize, PrimRep(..) )
 import Unique          ( Unique{-instance Eq-} )
 import UniqSupply      ( uniqFromSupply, uniqsFromSupply, splitUniqSupply, 
                          UniqSupply )
-import CmdLineOpts      ( opt_ProduceC )
+import CmdLineOpts      ( opt_OutputLanguage, opt_EmitCExternDecls )
 import Maybes          ( maybeToBool )
-import PrimOp          ( PrimOp(..) )
-import Util            ( panic )
+import PrimOp          ( PrimOp(..), CCall(..), CCallTarget(..) )
+import Panic           ( panic )
 
 infixr 9 `thenFlt`
 \end{code}
@@ -152,17 +152,13 @@ getAmodeRep (CVal _ kind)             = kind
 getAmodeRep (CAddr _)                      = PtrRep
 getAmodeRep (CReg magic_id)                = magicIdPrimRep magic_id
 getAmodeRep (CTemp uniq kind)              = kind
-getAmodeRep (CLbl label kind)              = kind
+getAmodeRep (CLbl _ kind)                  = kind
 getAmodeRep (CCharLike _)                  = PtrRep
 getAmodeRep (CIntLike _)                   = PtrRep
-getAmodeRep (CString _)                            = PtrRep
 getAmodeRep (CLit lit)                     = literalPrimRep lit
 getAmodeRep (CLitLit _ kind)               = kind
-getAmodeRep (CTableEntry _ _ kind)         = kind
 getAmodeRep (CMacroExpr kind _ _)          = kind
-#ifdef DEBUG
 getAmodeRep (CJoinPoint _)                 = panic "getAmodeRep:CJoinPoint"
-#endif
 \end{code}
 
 @mixedTypeLocn@ tells whether an amode identifies an ``StgWord''
@@ -305,16 +301,16 @@ flatAbsC (AbsCStmts s1 s2)
     returnFlt (mkAbsCStmts inline_s1 inline_s2,
               mkAbsCStmts top_s1    top_s2)
 
-flatAbsC (CClosureInfoAndCode cl_info slow maybe_fast srt descr)
+flatAbsC (CClosureInfoAndCode cl_info slow maybe_fast descr)
   = flatAbsC slow              `thenFlt` \ (slow_heres, slow_tops) ->
     flat_maybe maybe_fast      `thenFlt` \ (fast_heres, fast_tops) ->
     returnFlt (AbsCNop, mkAbstractCs [slow_tops, fast_tops,
-       CClosureInfoAndCode cl_info slow_heres fast_heres srt descr]
+       CClosureInfoAndCode cl_info slow_heres fast_heres descr]
     )
 
-flatAbsC (CCodeBlock label abs_C)
+flatAbsC (CCodeBlock lbl abs_C)
   = flatAbsC abs_C         `thenFlt` \ (absC_heres, absC_tops) ->
-    returnFlt (AbsCNop, absC_tops `mkAbsCStmts` CCodeBlock label absC_heres)
+    returnFlt (AbsCNop, absC_tops `mkAbsCStmts` CCodeBlock lbl absC_heres)
 
 flatAbsC (CRetDirect uniq slow_code srt liveness)
   = flatAbsC slow_code         `thenFlt` \ (heres, tops) ->
@@ -333,11 +329,16 @@ flatAbsC (CSwitch discrim alts deflt)
       = flatAbsC absC  `thenFlt` \ (alt_heres, alt_tops) ->
        returnFlt ( (tag, alt_heres), alt_tops )
 
-flatAbsC stmt@(COpStmt results td@(CCallOp (Right _) _ _ _) args vol_regs)
-  | maybeToBool opt_ProduceC
+flatAbsC stmt@(COpStmt results (CCallOp ccall) args vol_regs)
+  | isCandidate && opt_OutputLanguage == Just "C"      -- Urgh
   = returnFlt (stmt, tdef)
   where
-    tdef = CCallTypedef td results args
+    (isCandidate, isDyn) =
+      case ccall of 
+        CCall (DynamicTarget _) _ _ _      -> (True, True)
+       CCall (StaticTarget _) is_asm _ _  -> (opt_EmitCExternDecls && not is_asm, False)
+
+    tdef = CCallTypedef isDyn ccall results args
 
 flatAbsC stmt@(CSimultaneous abs_c)
   = flatAbsC abs_c             `thenFlt` \ (stmts_here, tops) ->
@@ -348,9 +349,14 @@ flatAbsC stmt@(CCheck macro amodes code)
   = flatAbsC code              `thenFlt` \ (code_here, code_tops) ->
     returnFlt (CCheck macro amodes code_here, code_tops)
 
+-- the TICKY_CTR macro always needs to be hoisted out to the top level. 
+-- This is a HACK.
+flatAbsC stmt@(CCallProfCtrMacro str amodes)
+  | str == SLIT("TICK_CTR")    = returnFlt (AbsCNop, stmt)
+  | otherwise                  = returnFlt (stmt, AbsCNop)
+
 -- Some statements need no flattening at all:
 flatAbsC stmt@(CMacroStmt macro amodes)        = returnFlt (stmt, AbsCNop)
-flatAbsC stmt@(CCallProfCtrMacro str amodes)   = returnFlt (stmt, AbsCNop)
 flatAbsC stmt@(CCallProfCCMacro str amodes)    = returnFlt (stmt, AbsCNop)
 flatAbsC stmt@(CAssign dest source)            = returnFlt (stmt, AbsCNop)
 flatAbsC stmt@(CJump target)                   = returnFlt (stmt, AbsCNop)
@@ -362,12 +368,14 @@ flatAbsC stmt@(COpStmt results op args vol_regs)= returnFlt (stmt, AbsCNop)
 -- Some statements only make sense at the top level, so we always float
 -- them.  This probably isn't necessary.
 flatAbsC stmt@(CStaticClosure _ _ _ _)         = returnFlt (AbsCNop, stmt)
+flatAbsC stmt@(CClosureTbl _)                  = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CSRT _ _)                       = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CBitmap _ _)                    = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CCostCentreDecl _ _)            = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CCostCentreStackDecl _)         = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CSplitMarker)                   = returnFlt (AbsCNop, stmt)
 flatAbsC stmt@(CRetVector _ _ _ _)              = returnFlt (AbsCNop, stmt)
+flatAbsC stmt@(CModuleInitBlock _ _)            = returnFlt (AbsCNop, stmt)
 \end{code}
 
 \begin{code}