diff options
Diffstat (limited to 'compiler/cmm/PprC.hs')
-rw-r--r-- | compiler/cmm/PprC.hs | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs index 45c415f35a..b0c9bd3f2f 100644 --- a/compiler/cmm/PprC.hs +++ b/compiler/cmm/PprC.hs @@ -189,7 +189,6 @@ pprStmt stmt = rep = cmmExprType dflags src CmmUnsafeForeignCall target@(ForeignTarget fn conv) results args -> - maybe_proto $$ fnCall where (res_hints, arg_hints) = foreignTargetHints target @@ -200,40 +199,29 @@ pprStmt stmt = cast_fn = parens (cCast (pprCFunType (char '*') cconv hresults hargs) fn) - real_fun_proto lbl = char ';' <> - pprCFunType (ppr lbl) cconv hresults hargs <> - noreturn_attr <> semi - - noreturn_attr = case ret of - CmmNeverReturns -> text "__attribute__ ((noreturn))" - CmmMayReturn -> empty - -- See wiki:Commentary/Compiler/Backends/PprC#Prototypes - (maybe_proto, fnCall) = + fnCall = case fn of CmmLit (CmmLabel lbl) | StdCallConv <- cconv -> - let myCall = pprCall (ppr lbl) cconv hresults hargs - in (real_fun_proto lbl, myCall) + pprCall (ppr lbl) cconv hresults hargs -- stdcall functions must be declared with -- a function type, otherwise the C compiler -- doesn't add the @n suffix to the label. We -- can't add the @n suffix ourselves, because -- it isn't valid C. | CmmNeverReturns <- ret -> - let myCall = pprCall (ppr lbl) cconv hresults hargs - in (real_fun_proto lbl, myCall) + pprCall cast_fn cconv hresults hargs <> semi | not (isMathFun lbl) -> pprForeignCall (ppr lbl) cconv hresults hargs _ -> - (empty {- no proto -}, - pprCall cast_fn cconv hresults hargs <> semi) + pprCall cast_fn cconv hresults hargs <> semi -- for a dynamic call, no declaration is necessary. CmmUnsafeForeignCall (PrimTarget MO_Touch) _results _args -> empty CmmUnsafeForeignCall target@(PrimTarget op) results args -> - proto $$ fn_call + fn_call where cconv = CCallConv fn = pprCallishMachOp_for_C op @@ -242,15 +230,16 @@ pprStmt stmt = hresults = zip results res_hints hargs = zip args arg_hints - (proto, fn_call) + fn_call -- The mem primops carry an extra alignment arg, must drop it. -- We could maybe emit an alignment directive using this info. -- We also need to cast mem primops to prevent conflicts with GCC -- builtins (see bug #5967). | op `elem` [MO_Memcpy, MO_Memset, MO_Memmove] - = pprForeignCall fn cconv hresults (init hargs) + = (ptext (sLit ";EF_(") <> fn <> char ')' <> semi) $$ + pprForeignCall fn cconv hresults (init hargs) | otherwise - = (empty, pprCall fn cconv hresults hargs) + = pprCall fn cconv hresults hargs CmmBranch ident -> pprBranch ident CmmCondBranch expr yes no -> pprCondBranch expr yes no @@ -263,8 +252,8 @@ pprStmt stmt = type Hinted a = (a, ForeignHint) pprForeignCall :: SDoc -> CCallConv -> [Hinted CmmFormal] -> [Hinted CmmActual] - -> (SDoc, SDoc) -pprForeignCall fn cconv results args = (proto, fn_call) + -> SDoc +pprForeignCall fn cconv results args = fn_call where fn_call = braces ( pprCFunType (char '*' <> text "ghcFunPtr") cconv results args <> semi @@ -272,7 +261,6 @@ pprForeignCall fn cconv results args = (proto, fn_call) $$ pprCall (text "ghcFunPtr") cconv results args <> semi ) cast_fn = parens (parens (pprCFunType (char '*') cconv results args) <> fn) - proto = ptext (sLit ";EF_(") <> fn <> char ')' <> semi pprCFunType :: SDoc -> CCallConv -> [Hinted CmmFormal] -> [Hinted CmmActual] -> SDoc pprCFunType ppr_fn cconv ress args @@ -750,6 +738,7 @@ pprCallishMachOp_for_C mop MO_Memcpy -> ptext (sLit "memcpy") MO_Memset -> ptext (sLit "memset") MO_Memmove -> ptext (sLit "memmove") + (MO_BSwap w) -> ptext (sLit $ bSwapLabel w) (MO_PopCnt w) -> ptext (sLit $ popCntLabel w) (MO_UF_Conv w) -> ptext (sLit $ word2FloatLabel w) |