<commit_before>-----------------------------------------------------------------------------
--
-- Pretty-printing assembly language
--
-- (c) The University of Glasgow 1993-2005
--
-----------------------------------------------------------------------------

module X86.Ppr (
        pprNatCmmTop,
        pprBasicBlock,
        pprSectionHeader,
        pprData,
        pprInstr,
        pprUserReg,
        pprSize,
        pprImm,
        pprDataItem,
)

where

#include "HsVersions.h"
#include "nativeGen/NCG.h"

import X86.Regs
import X86.Instr
import X86.Cond
import Instruction
import Size
import Reg
import PprBase


import OldCmm
import CLabel
import Config
import Unique           ( pprUnique, Uniquable(..) )
import Pretty
import FastString
import qualified Outputable
import Outputable       (panic, Outputable)

import Data.Word
import Distribution.System

#if i386_TARGET_ARCH && darwin_TARGET_OS
import Data.Bits
#endif

-- -----------------------------------------------------------------------------
-- Printing this stuff out

pprNatCmmTop :: NatCmmTop Instr -> Doc
pprNatCmmTop (CmmData section dats) =
  pprSectionHeader section $$ vcat (map pprData dats)

 -- special case for split markers:
pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel True lbl

pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
  pprSectionHeader Text $$
  (if null info then -- blocks guaranteed not null, so label needed
       pprLabel True lbl
   else
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
            pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                <> char ':' $$
#endif
       vcat (map pprData info) $$
       pprLabel True (entryLblToInfoLbl lbl)
  ) $$
  vcat (map pprBasicBlock blocks)
     -- above: Even the first block gets a label, because with branch-chain
     -- elimination, it might be the target of a goto.
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
        -- If we are using the .subsections_via_symbols directive
        -- (available on recent versions of Darwin),
        -- we have to make sure that there is some kind of reference
        -- from the entry code to a label on the _top_ of of the info table,
        -- so that the linker will not think it is unreferenced and dead-strip
        -- it. That's why the label is called a DeadStripPreventer (_dsp).
  $$ if not (null info)
                    then text "\t.long "
                      <+> pprCLabel_asm (entryLblToInfoLbl lbl)
                      <+> char '-'
                      <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                    else empty
#endif
  $$ pprSizeDecl (if null info then lbl else entryLblToInfoLbl lbl)


pprBasicBlock :: NatBasicBlock Instr -> Doc
pprBasicBlock (BasicBlock blockid instrs) =
  pprCLabel_asm (mkAsmTempLabel (getUnique blockid)) <> char ':' $$
  vcat (map pprInstr instrs)


pprData :: CmmStatic -> Doc
pprData (CmmAlign bytes)         = pprAlign bytes
pprData (CmmDataLabel lbl)       = pprLabel False lbl
pprData (CmmString str)          = pprASCII str

#if  darwin_TARGET_OS
pprData (CmmUninitialised bytes) = ptext (sLit ".space ") <> int bytes
#else
pprData (CmmUninitialised bytes) = ptext (sLit ".skip ") <> int bytes
#endif

pprData (CmmStaticLit lit)       = pprDataItem lit

pprGloblDecl :: CLabel -> Doc
pprGloblDecl lbl
  | not (externallyVisibleCLabel lbl) = empty
  | otherwise = ptext IF_ARCH_sparc((sLit ".global "),
                                    (sLit ".globl ")) <>
                pprCLabel_asm lbl

pprTypeDecl :: Bool -> CLabel -> Doc
#if elf_OBJ_FORMAT
pprTypeDecl isCode lbl =
    ptext (sLit "\t.type ") <> pprCLabel_asm lbl
    <> ptext (sLit (if isCode then ", @function" else ", @object"))
#else
pprTypeDecl _ _
  = empty
#endif

-- | Output the ELF .size directive.
pprSizeDecl :: CLabel -> Doc
#if elf_OBJ_FORMAT
pprSizeDecl lbl =
    ptext (sLit "\t.size") <+> pprCLabel_asm lbl
    <> ptext (sLit ", .-") <> pprCLabel_asm lbl
#else
pprSizeDecl _ = empty
#endif

pprLabel :: Bool -> CLabel -> Doc
pprLabel isCode lbl = pprGloblDecl lbl $$ pprTypeDecl isCode lbl
                      $$ (pprCLabel_asm lbl <> char ':')


pprASCII :: [Word8] -> Doc
pprASCII str
  = vcat (map do1 str) $$ do1 0
    where<commit_msg>Revert "Output ELF .size directives for functions"<commit_after>-----------------------------------------------------------------------------
--
-- Pretty-printing assembly language
--
-- (c) The University of Glasgow 1993-2005
--
-----------------------------------------------------------------------------

module X86.Ppr (
        pprNatCmmTop,
        pprBasicBlock,
        pprSectionHeader,
        pprData,
        pprInstr,
        pprUserReg,
        pprSize,
        pprImm,
        pprDataItem,
)

where

#include "HsVersions.h"
#include "nativeGen/NCG.h"

import X86.Regs
import X86.Instr
import X86.Cond
import Instruction
import Size
import Reg
import PprBase


import OldCmm
import CLabel
import Config
import Unique           ( pprUnique, Uniquable(..) )
import Pretty
import FastString
import qualified Outputable
import Outputable       (panic, Outputable)

import Data.Word
import Distribution.System

#if i386_TARGET_ARCH && darwin_TARGET_OS
import Data.Bits
#endif

-- -----------------------------------------------------------------------------
-- Printing this stuff out

pprNatCmmTop :: NatCmmTop Instr -> Doc
pprNatCmmTop (CmmData section dats) =
  pprSectionHeader section $$ vcat (map pprData dats)

 -- special case for split markers:
pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel lbl

pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
  pprSectionHeader Text $$
  (if null info then -- blocks guaranteed not null, so label needed
       pprLabel lbl
   else
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
            pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                <> char ':' $$
#endif
       vcat (map pprData info) $$
       pprLabel (entryLblToInfoLbl lbl)
  ) $$
  vcat (map pprBasicBlock blocks)
     -- above: Even the first block gets a label, because with branch-chain
     -- elimination, it might be the target of a goto.
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
        -- If we are using the .subsections_via_symbols directive
        -- (available on recent versions of Darwin),
        -- we have to make sure that there is some kind of reference
        -- from the entry code to a label on the _top_ of of the info table,
        -- so that the linker will not think it is unreferenced and dead-strip
        -- it. That's why the label is called a DeadStripPreventer (_dsp).
  $$ if not (null info)
                    then text "\t.long "
                      <+> pprCLabel_asm (entryLblToInfoLbl lbl)
                      <+> char '-'
                      <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
                    else empty
#endif


pprBasicBlock :: NatBasicBlock Instr -> Doc
pprBasicBlock (BasicBlock blockid instrs) =
  pprLabel (mkAsmTempLabel (getUnique blockid)) $$
  vcat (map pprInstr instrs)


pprData :: CmmStatic -> Doc
pprData (CmmAlign bytes)         = pprAlign bytes
pprData (CmmDataLabel lbl)       = pprLabel lbl
pprData (CmmString str)          = pprASCII str

#if  darwin_TARGET_OS
pprData (CmmUninitialised bytes) = ptext (sLit ".space ") <> int bytes
#else
pprData (CmmUninitialised bytes) = ptext (sLit ".skip ") <> int bytes
#endif

pprData (CmmStaticLit lit)       = pprDataItem lit

pprGloblDecl :: CLabel -> Doc
pprGloblDecl lbl
  | not (externallyVisibleCLabel lbl) = empty
  | otherwise = ptext IF_ARCH_sparc((sLit ".global "),
                                    (sLit ".globl ")) <>
                pprCLabel_asm lbl

pprTypeAndSizeDecl :: CLabel -> Doc
#if elf_OBJ_FORMAT
pprTypeAndSizeDecl lbl
  | not (externallyVisibleCLabel lbl) = empty
  | otherwise = ptext (sLit ".type ") <>
                pprCLabel_asm lbl <> ptext (sLit ", @object")
#else
pprTypeAndSizeDecl _
  = empty
#endif

pprLabel :: CLabel -> Doc
pprLabel lbl = pprGloblDecl lbl $$ pprTypeAndSizeDecl lbl $$ (pprCLabel_asm lbl <> char ':')


pprASCII :: [Word8] -> Doc
pprASCII str
  = vcat (map do1 str) $$ do1 0
    where
{'fraction_non_alphanumeric': 0.13980868285504047, 'fraction_numerical': 0.00564140299239637, 'mean_word_length': 2.2118944466325323, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924588', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2542, 'n_words': 783}