, tcForeignExports
) where
-#include "../includes/ghcconfig.h"
#include "HsVersions.h"
import HsSyn
import TcHsType ( tcHsSigType, UserTypeCtxt(..) )
import TcExpr ( tcCheckSigma )
+import ForeignCall ( CCallConv(..) )
import ErrUtils ( Message )
import Id ( Id, mkLocalId, mkExportedLocalId )
#if alpha_TARGET_ARCH
CLabelString, isCLabelString,
isDynamicTarget, withDNTypes, DNKind(..), DNCallSpec(..) )
import PrelNames ( hasKey, ioTyConKey )
-import CmdLineOpts ( dopt_HscLang, HscLang(..) )
+import CmdLineOpts ( dopt_HscTarget, HscTarget(..) )
import Outputable
import SrcLoc ( Located(..), srcSpanStart )
import Bag ( consBag )
-- as ft -> IO Addr is accepted, too. The use of the latter two forms
-- is DEPRECATED, though.
checkCg checkCOrAsmOrInterp `thenM_`
+ checkCConv cconv `thenM_`
(case arg_tys of
[arg1_ty] -> checkForeignArgs isFFIExternalTy arg1_tys `thenM_`
checkForeignRes nonIOok isFFIExportResultTy res1_ty `thenM_`
other -> addErrTc (illegalForeignTyErr empty sig_ty) ) `thenM_`
return idecl
-tcCheckFIType sig_ty arg_tys res_ty idecl@(CImport _ safety _ _ (CFunction target))
+tcCheckFIType sig_ty arg_tys res_ty idecl@(CImport cconv safety _ _ (CFunction target))
| isDynamicTarget target -- Foreign import dynamic
= checkCg checkCOrAsmOrInterp `thenM_`
+ checkCConv cconv `thenM_`
case arg_tys of -- The first arg must be Ptr, FunPtr, or Addr
[] ->
check False (illegalForeignTyErr empty sig_ty) `thenM_`
return idecl
| otherwise -- Normal foreign import
= checkCg (checkCOrAsmOrDotNetOrInterp) `thenM_`
+ checkCConv cconv `thenM_`
checkCTarget target `thenM_`
getDOpts `thenM` \ dflags ->
checkForeignArgs (isFFIArgumentTy dflags safety) arg_tys `thenM_`
checkCg check
= getDOpts `thenM` \ dflags ->
- let hscLang = dopt_HscLang dflags in
- case hscLang of
+ let hscTarget = dopt_HscTarget dflags in
+ case hscTarget of
HscNothing -> returnM ()
otherwise ->
- case check hscLang of
+ case check hscTarget of
Nothing -> returnM ()
Just err -> addErrTc (text "Illegal foreign declaration:" <+> err)
\end{code}
+Calling conventions
+
+\begin{code}
+checkCConv :: CCallConv -> TcM ()
+checkCConv CCallConv = return ()
+#if i386_TARGET_ARCH
+checkCConv StdCallConv = return ()
+#else
+checkCConv StdCallConv = addErrTc (text "calling convention not supported on this architecture: stdcall")
+#endif
+\end{code}
+
Warnings
\begin{code}