-{-% DrIFT (Automatic class derivations for Haskell) v1.1 %-}
-{-% DrIFT (Automatic class derivations for Haskell) v1.1 %-}
%
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
%
ForeignCall(..),
Safety(..), playSafe, playThreadSafe,
- CExportSpec(..),
+ CExportSpec(..), CLabelString, isCLabelString, pprCLabelString,
CCallSpec(..),
- CCallTarget(..), isDynamicTarget, isCasmTarget,
+ CCallTarget(..), isDynamicTarget,
CCallConv(..), defaultCCallConv, ccallConvToInt, ccallConvAttribute,
DNCallSpec(..), DNKind(..), DNType(..),
- withDNTypes,
-
- okToExposeFCall
+ withDNTypes
) where
#include "HsVersions.h"
-import CStrings ( CLabelString, pprCLabelString )
-import FastString ( FastString )
+import FastString ( FastString, unpackFS )
+import Char ( isAlphaNum )
import Binary
import Outputable
\end{code}
data CCallTarget
= StaticTarget CLabelString -- An "unboxed" ccall# to `fn'.
| DynamicTarget -- First argument (an Addr#) is the function pointer
- | CasmTarget CLabelString -- Inline C code (now seriously deprecated)
deriving( Eq )
{-! derive: Binary !-}
-isDynamicTarget, isCasmTarget :: CCallTarget -> Bool
+isDynamicTarget :: CCallTarget -> Bool
isDynamicTarget DynamicTarget = True
isDynamicTarget other = False
-
-isCasmTarget (CasmTarget _) = True
-isCasmTarget other = False
\end{code}
\begin{code}
ccallConvAttribute :: CCallConv -> String
-ccallConvAttribute StdCallConv = "__stdcall"
+ccallConvAttribute StdCallConv = "__attribute__((__stdcall__))"
ccallConvAttribute CCallConv = ""
\end{code}
+\begin{code}
+type CLabelString = FastString -- A C label, completely unencoded
+
+pprCLabelString :: CLabelString -> SDoc
+pprCLabelString lbl = ftext lbl
+
+isCLabelString :: CLabelString -> Bool -- Checks to see if this is a valid C label
+isCLabelString lbl
+ = all ok (unpackFS lbl)
+ where
+ ok c = isAlphaNum c || c == '_' || c == '.'
+ -- The '.' appears in e.g. "foo.so" in the
+ -- module part of a ExtName. Maybe it should be separate
+\end{code}
+
+
Printing into C files:
\begin{code}
ppr_fun DynamicTarget = text "__dyn_ccall" <> gc_suf <+> text "\"\""
ppr_fun (StaticTarget fn) = text "__ccall" <> gc_suf <+> pprCLabelString fn
- ppr_fun (CasmTarget fn) = text "__casm" <> gc_suf <+> text "``" <> pprCLabelString fn <> text "''"
\end{code}
%************************************************************************
\begin{code}
-okToExposeFCall :: ForeignCall -> Bool
--- OK to unfold a Foreign Call in an interface file
--- Yes, unless it's a _casm_
-okToExposeFCall (CCall (CCallSpec target _ _)) = not (isCasmTarget target)
-okToExposeFCall other = True
-\end{code}
-\begin{code}
{-* Generated by DrIFT-v1.0 : Look, but Don't Touch. *-}
instance Binary ForeignCall where
put_ bh (CCall aa) = do
put_ bh aa
put_ bh DynamicTarget = do
putByte bh 1
- put_ bh (CasmTarget ab) = do
- putByte bh 2
- put_ bh ab
get bh = do
h <- getByte bh
case h of
0 -> do aa <- get bh
return (StaticTarget aa)
- 1 -> do return DynamicTarget
- _ -> do ab <- get bh
- return (CasmTarget ab)
+ _ -> do return DynamicTarget
instance Binary CCallConv where
put_ bh CCallConv = do