diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-09-18 11:44:44 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-23 20:43:48 -0400 |
commit | 667d63558a694e12974ace723b553950f6080365 (patch) | |
tree | 50167bdcff894b1ca9ca96a8ad73fe20a883d245 /compiler/GHC/CmmToC.hs | |
parent | d7385f7077c6258c2a76ae51b4ea80f6fa9c7015 (diff) | |
download | haskell-667d63558a694e12974ace723b553950f6080365.tar.gz |
Refactor CLabel pretty-printing
* Don't depend on the selected backend to know if we print Asm or C
labels: we already have PprStyle to determine this. Moreover even when
a native backend is used (NCG, LLVM) we may want to C headers
containing pretty-printed labels, so it wasn't a good predicate
anyway.
* Make pretty-printing code clearer and avoid partiality
Diffstat (limited to 'compiler/GHC/CmmToC.hs')
-rw-r--r-- | compiler/GHC/CmmToC.hs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs index db93ef8df8..6aa4f9b729 100644 --- a/compiler/GHC/CmmToC.hs +++ b/compiler/GHC/CmmToC.hs @@ -91,7 +91,7 @@ pprTop platform = \case blankLine, extern_decls, (if (externallyVisibleCLabel clbl) - then mkFN_ else mkIF_) (pprCLabel_ViaC platform clbl) <+> lbrace, + then mkFN_ else mkIF_) (pprCLabel platform CStyle clbl) <+> lbrace, nest 8 temp_decls, vcat (map (pprBBlock platform) blocks), rbrace ] @@ -110,14 +110,14 @@ pprTop platform = \case (CmmData section (CmmStaticsRaw lbl [CmmString str])) -> pprExternDecl platform lbl $$ hcat [ - pprLocalness lbl, pprConstness (isSecConstant section), text "char ", pprCLabel_ViaC platform lbl, + pprLocalness lbl, pprConstness (isSecConstant section), text "char ", pprCLabel platform CStyle lbl, text "[] = ", pprStringInCStyle str, semi ] (CmmData section (CmmStaticsRaw lbl [CmmUninitialised size])) -> pprExternDecl platform lbl $$ hcat [ - pprLocalness lbl, pprConstness (isSecConstant section), text "char ", pprCLabel_ViaC platform lbl, + pprLocalness lbl, pprConstness (isSecConstant section), text "char ", pprCLabel platform CStyle lbl, brackets (int size), semi ] @@ -153,7 +153,7 @@ pprWordArray platform is_ro lbl ds = -- TODO: align closures only pprExternDecl platform lbl $$ hcat [ pprLocalness lbl, pprConstness is_ro, text "StgWord" - , space, pprCLabel_ViaC platform lbl, text "[]" + , space, pprCLabel platform CStyle lbl, text "[]" -- See Note [StgWord alignment] , pprAlignment (wordWidth platform) , text "= {" ] @@ -238,7 +238,7 @@ pprStmt platform stmt = case fn of CmmLit (CmmLabel lbl) | StdCallConv <- cconv -> - pprCall platform (pprCLabel_ViaC platform lbl) cconv hresults hargs + pprCall platform (pprCLabel platform CStyle 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 @@ -247,7 +247,7 @@ pprStmt platform stmt = | CmmNeverReturns <- ret -> pprCall platform cast_fn cconv hresults hargs <> semi | not (isMathFun lbl) -> - pprForeignCall platform (pprCLabel_ViaC platform lbl) cconv hresults hargs + pprForeignCall platform (pprCLabel platform CStyle lbl) cconv hresults hargs _ -> pprCall platform cast_fn cconv hresults hargs <> semi -- for a dynamic call, no declaration is necessary. @@ -487,7 +487,7 @@ pprLit platform lit = case lit of -> mkW_ <> pprCLabelAddr clbl1 <> char '+' <> int i where - pprCLabelAddr lbl = char '&' <> pprCLabel_ViaC platform lbl + pprCLabelAddr lbl = char '&' <> pprCLabel platform CStyle lbl pprLit1 :: Platform -> CmmLit -> SDoc pprLit1 platform lit = case lit of @@ -1047,7 +1047,7 @@ pprExternDecl platform lbl | not (needsCDecl lbl) = empty | Just sz <- foreignLabelStdcallInfo lbl = stdcall_decl sz | otherwise = - hcat [ visibility, label_type lbl , lparen, pprCLabel_ViaC platform lbl, text ");" + hcat [ visibility, label_type lbl , lparen, pprCLabel platform CStyle lbl, text ");" -- occasionally useful to see label type -- , text "/* ", pprDebugCLabel lbl, text " */" ] @@ -1070,7 +1070,7 @@ pprExternDecl platform lbl -- we must generate an appropriate prototype for it, so that the C compiler will -- add the @n suffix to the label (#2276) stdcall_decl sz = - text "extern __attribute__((stdcall)) void " <> pprCLabel_ViaC platform lbl + text "extern __attribute__((stdcall)) void " <> pprCLabel platform CStyle lbl <> parens (commafy (replicate (sz `quot` platformWordSizeInBytes platform) (machRep_U_CType platform (wordWidth platform)))) <> semi |