{-# LANGUAGE ScopedTypeVariables #-}

module GHC.CmmToAsm.RV64.Ppr (pprNatCmmDecl, pprInstr) where

import GHC.Cmm hiding (topInfoTable)
import GHC.Cmm.BlockId
import GHC.Cmm.CLabel
import GHC.Cmm.Dataflow.Label
import GHC.CmmToAsm.Config
import GHC.CmmToAsm.Format
import GHC.CmmToAsm.Ppr
import GHC.CmmToAsm.RV64.Cond
import GHC.CmmToAsm.RV64.Instr
import GHC.CmmToAsm.RV64.Regs
import GHC.CmmToAsm.Types
import GHC.CmmToAsm.Utils
import GHC.Platform
import GHC.Platform.Reg
import GHC.Prelude hiding (EQ)
import GHC.Types.Basic (Alignment, alignmentBytes, mkAlignment)
import GHC.Types.Unique (getUnique, pprUniqueAlways)
import GHC.Utils.Outputable
import GHC.Utils.Panic

pprNatCmmDecl :: forall doc. (IsDoc doc) => NCGConfig -> NatCmmDecl RawCmmStatics Instr -> doc
pprNatCmmDecl :: forall doc.
IsDoc doc =>
NCGConfig -> NatCmmDecl RawCmmStatics Instr -> doc
pprNatCmmDecl NCGConfig
config (CmmData Section
section RawCmmStatics
dats) =
  NCGConfig -> Section -> doc
forall doc. IsDoc doc => NCGConfig -> Section -> doc
pprSectionAlign NCGConfig
config Section
section doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ NCGConfig -> RawCmmStatics -> doc
forall doc. IsDoc doc => NCGConfig -> RawCmmStatics -> doc
pprDatas NCGConfig
config RawCmmStatics
dats
pprNatCmmDecl NCGConfig
config proc :: NatCmmDecl RawCmmStatics Instr
proc@(CmmProc LabelMap RawCmmStatics
top_info CLabel
lbl [GlobalRegUse]
_ (ListGraph [GenBasicBlock Instr]
blocks)) =
  let platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config

      pprProcAlignment :: doc
      pprProcAlignment :: doc
pprProcAlignment = doc -> (Int -> doc) -> Maybe Int -> doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe doc
forall doc. IsOutput doc => doc
empty (Alignment -> doc
forall doc. IsDoc doc => Alignment -> doc
pprAlign (Alignment -> doc) -> (Int -> Alignment) -> Int -> doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Alignment
mkAlignment) (NCGConfig -> Maybe Int
ncgProcAlignment NCGConfig
config)
   in doc
pprProcAlignment
        doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ case NatCmmDecl RawCmmStatics Instr -> Maybe RawCmmStatics
forall a i b. GenCmmDecl a (LabelMap i) (ListGraph b) -> Maybe i
topInfoTable NatCmmDecl RawCmmStatics Instr
proc of
          Maybe RawCmmStatics
Nothing ->
            -- special case for code without info table:
            NCGConfig -> Section -> doc
forall doc. IsDoc doc => NCGConfig -> Section -> doc
pprSectionAlign NCGConfig
config (SectionType -> CLabel -> Section
Section SectionType
Text CLabel
lbl)
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$
              -- do not
              -- pprProcAlignment config $$
              Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprLabel Platform
platform CLabel
lbl
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [doc] -> doc
forall doc. IsDoc doc => [doc] -> doc
vcat ((GenBasicBlock Instr -> doc) -> [GenBasicBlock Instr] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map (NCGConfig -> LabelMap RawCmmStatics -> GenBasicBlock Instr -> doc
forall doc.
IsDoc doc =>
NCGConfig -> LabelMap RawCmmStatics -> GenBasicBlock Instr -> doc
pprBasicBlock NCGConfig
config LabelMap RawCmmStatics
top_info) [GenBasicBlock Instr]
blocks) -- blocks guaranteed not null, so label needed
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Bool -> doc -> doc
forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen
                (NCGConfig -> Bool
ncgDwarfEnabled NCGConfig
config)
                (Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprBlockEndLabel Platform
platform CLabel
lbl) doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprProcEndLabel Platform
platform CLabel
lbl))
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprSizeDecl Platform
platform CLabel
lbl
          Just (CmmStaticsRaw CLabel
info_lbl [CmmStatic]
_) ->
            NCGConfig -> Section -> doc
forall doc. IsDoc doc => NCGConfig -> Section -> doc
pprSectionAlign NCGConfig
config (SectionType -> CLabel -> Section
Section SectionType
Text CLabel
info_lbl)
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$
              -- pprProcAlignment config $$
              ( if Platform -> Bool
platformHasSubsectionsViaSymbols Platform
platform
                  then Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform (CLabel -> CLabel
mkDeadStripPreventer CLabel
info_lbl) Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> Line doc
forall doc. IsLine doc => Char -> doc
char Char
':')
                  else doc
forall doc. IsOutput doc => doc
empty
              )
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [doc] -> doc
forall doc. IsDoc doc => [doc] -> doc
vcat ((GenBasicBlock Instr -> doc) -> [GenBasicBlock Instr] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map (NCGConfig -> LabelMap RawCmmStatics -> GenBasicBlock Instr -> doc
forall doc.
IsDoc doc =>
NCGConfig -> LabelMap RawCmmStatics -> GenBasicBlock Instr -> doc
pprBasicBlock NCGConfig
config LabelMap RawCmmStatics
top_info) [GenBasicBlock Instr]
blocks)
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Bool -> doc -> doc
forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen (NCGConfig -> Bool
ncgDwarfEnabled NCGConfig
config) (Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprProcEndLabel Platform
platform CLabel
info_lbl))
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$
              -- above: Even the first block gets a label, because with branch-chain
              -- elimination, it might be the target of a goto.
              ( if Platform -> Bool
platformHasSubsectionsViaSymbols Platform
platform
                  then -- See Note [Subsections Via Symbols]

                    Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line
                      (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.long "
                      Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
info_lbl
                      Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Char -> Line doc
forall doc. IsLine doc => Char -> doc
char Char
'-'
                      Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform (CLabel -> CLabel
mkDeadStripPreventer CLabel
info_lbl)
                  else doc
forall doc. IsOutput doc => doc
empty
              )
              doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprSizeDecl Platform
platform CLabel
info_lbl
{-# SPECIALIZE pprNatCmmDecl :: NCGConfig -> NatCmmDecl RawCmmStatics Instr -> SDoc #-}
{-# SPECIALIZE pprNatCmmDecl :: NCGConfig -> NatCmmDecl RawCmmStatics Instr -> HDoc #-} -- see Note [SPECIALIZE to HDoc] in GHC.Utils.Outputable

pprLabel :: (IsDoc doc) => Platform -> CLabel -> doc
pprLabel :: forall doc. IsDoc doc => Platform -> CLabel -> doc
pprLabel Platform
platform CLabel
lbl =
  Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprGloblDecl Platform
platform CLabel
lbl
    doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprTypeDecl Platform
platform CLabel
lbl
    doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> Line doc
forall doc. IsLine doc => Char -> doc
char Char
':')

pprAlign :: (IsDoc doc) => Alignment -> doc
pprAlign :: forall doc. IsDoc doc => Alignment -> doc
pprAlign Alignment
alignment =
  -- "The .align directive for RISC-V is an alias to .p2align, which aligns to a
  -- power of two, so .align 2 means align to 4 bytes. Because the definition of
  -- the .align directive varies by architecture, it is recommended to use the
  -- unambiguous .p2align or .balign directives instead."
  -- (https://github.com/riscv-non-isa/riscv-asm-manual/blob/main/riscv-asm.md#-align)
  Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.balign " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int (Alignment -> Int
alignmentBytes Alignment
alignment)

-- | Print appropriate alignment for the given section type.
--
-- Currently, this always aligns to a full machine word (8 byte.) A future
-- improvement could be to really do this per section type (though, it's
-- probably not a big gain.)
pprAlignForSection :: (IsDoc doc) => SectionType -> doc
pprAlignForSection :: forall doc. IsDoc doc => SectionType -> doc
pprAlignForSection SectionType
_seg = Alignment -> doc
forall doc. IsDoc doc => Alignment -> doc
pprAlign (Alignment -> doc) -> (Int -> Alignment) -> Int -> doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Alignment
mkAlignment (Int -> doc) -> Int -> doc
forall a b. (a -> b) -> a -> b
$ Int
8

-- | Print section header and appropriate alignment for that section.
--
-- This will e.g. emit a header like:
--
--     .section .text
--     .balign 8
pprSectionAlign :: (IsDoc doc) => NCGConfig -> Section -> doc
pprSectionAlign :: forall doc. IsDoc doc => NCGConfig -> Section -> doc
pprSectionAlign NCGConfig
_config (Section (OtherSection String
_) CLabel
_) =
  String -> doc
forall a. HasCallStack => String -> a
panic String
"RV64.Ppr.pprSectionAlign: unknown section"
pprSectionAlign NCGConfig
config sec :: Section
sec@(Section SectionType
seg CLabel
_) =
  Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (NCGConfig -> Section -> Line doc
forall doc. IsLine doc => NCGConfig -> Section -> doc
pprSectionHeader NCGConfig
config Section
sec)
    doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SectionType -> doc
forall doc. IsDoc doc => SectionType -> doc
pprAlignForSection SectionType
seg

pprProcEndLabel ::
  (IsLine doc) =>
  Platform ->
  -- | Procedure name
  CLabel ->
  doc
pprProcEndLabel :: forall doc. IsLine doc => Platform -> CLabel -> doc
pprProcEndLabel Platform
platform CLabel
lbl =
  Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform (CLabel -> CLabel
mkAsmTempProcEndLabel CLabel
lbl) doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
colon

pprBlockEndLabel ::
  (IsLine doc) =>
  Platform ->
  -- | Block name
  CLabel ->
  doc
pprBlockEndLabel :: forall doc. IsLine doc => Platform -> CLabel -> doc
pprBlockEndLabel Platform
platform CLabel
lbl =
  Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform (CLabel -> CLabel
mkAsmTempEndLabel CLabel
lbl) doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
colon

-- | Output the ELF .size directive (if needed.)
pprSizeDecl :: (IsDoc doc) => Platform -> CLabel -> doc
pprSizeDecl :: forall doc. IsDoc doc => Platform -> CLabel -> doc
pprSizeDecl Platform
platform CLabel
lbl
  | OS -> Bool
osElfTarget (Platform -> OS
platformOS Platform
platform) =
      Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.size" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Line doc
asmLbl Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
", .-" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
asmLbl
  where
    asmLbl :: Line doc
asmLbl = Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl
pprSizeDecl Platform
_ CLabel
_ = doc
forall doc. IsOutput doc => doc
empty

pprBasicBlock ::
  (IsDoc doc) =>
  NCGConfig ->
  LabelMap RawCmmStatics ->
  NatBasicBlock Instr ->
  doc
pprBasicBlock :: forall doc.
IsDoc doc =>
NCGConfig -> LabelMap RawCmmStatics -> GenBasicBlock Instr -> doc
pprBasicBlock NCGConfig
config LabelMap RawCmmStatics
info_env (BasicBlock BlockId
blockid [Instr]
instrs) =
  doc -> doc
maybe_infotable
    (doc -> doc) -> doc -> doc
forall a b. (a -> b) -> a -> b
$ Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprLabel Platform
platform CLabel
asmLbl
    doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [doc] -> doc
forall doc. IsDoc doc => [doc] -> doc
vcat ((Instr -> doc) -> [Instr] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map (Platform -> Instr -> doc
forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform) ([Instr] -> [Instr]
forall a. a -> a
id {-detectTrivialDeadlock-} [Instr]
optInstrs))
    doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Bool -> doc -> doc
forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen
      (NCGConfig -> Bool
ncgDwarfEnabled NCGConfig
config)
      ( -- Emit both end labels since this may end up being a standalone
        -- top-level block
        Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line
          ( Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprBlockEndLabel Platform
platform CLabel
asmLbl
              Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprProcEndLabel Platform
platform CLabel
asmLbl
          )
      )
  where
    -- TODO: Check if we can  filter more instructions here.
    -- TODO: Shouldn't this be a more general check on a higher level?
    -- Filter out identity moves. E.g. mov x18, x18 will be dropped.
    optInstrs :: [Instr]
optInstrs = (Instr -> Bool) -> [Instr] -> [Instr]
forall a. (a -> Bool) -> [a] -> [a]
filter Instr -> Bool
f [Instr]
instrs
      where
        f :: Instr -> Bool
f (MOV Operand
o1 Operand
o2) | Operand
o1 Operand -> Operand -> Bool
forall a. Eq a => a -> a -> Bool
== Operand
o2 = Bool
False
        f Instr
_ = Bool
True

    asmLbl :: CLabel
asmLbl = BlockId -> CLabel
blockLbl BlockId
blockid
    platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config
    maybe_infotable :: doc -> doc
maybe_infotable doc
c = case BlockId -> LabelMap RawCmmStatics -> Maybe RawCmmStatics
forall a. BlockId -> LabelMap a -> Maybe a
mapLookup BlockId
blockid LabelMap RawCmmStatics
info_env of
      Maybe RawCmmStatics
Nothing -> doc
c
      Just (CmmStaticsRaw CLabel
info_lbl [CmmStatic]
info) ->
        --  pprAlignForSection platform Text $$
        doc
infoTableLoc
          doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ [doc] -> doc
forall doc. IsDoc doc => [doc] -> doc
vcat ((CmmStatic -> doc) -> [CmmStatic] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map (NCGConfig -> CmmStatic -> doc
forall doc. IsDoc doc => NCGConfig -> CmmStatic -> doc
pprData NCGConfig
config) [CmmStatic]
info)
          doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprLabel Platform
platform CLabel
info_lbl
          doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ doc
c
          doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Bool -> doc -> doc
forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen
            (NCGConfig -> Bool
ncgDwarfEnabled NCGConfig
config)
            (Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprBlockEndLabel Platform
platform CLabel
info_lbl))
    -- Make sure the info table has the right .loc for the block
    -- coming right after it. See Note [Info Offset]
    infoTableLoc :: doc
infoTableLoc = case [Instr]
instrs of
      (l :: Instr
l@LOCATION {} : [Instr]
_) -> Platform -> Instr -> doc
forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform Instr
l
      [Instr]
_other -> doc
forall doc. IsOutput doc => doc
empty

pprDatas :: (IsDoc doc) => NCGConfig -> RawCmmStatics -> doc
-- See Note [emit-time elimination of static indirections] in "GHC.Cmm.CLabel".
pprDatas :: forall doc. IsDoc doc => NCGConfig -> RawCmmStatics -> doc
pprDatas NCGConfig
config (CmmStaticsRaw CLabel
alias [CmmStaticLit (CmmLabel CLabel
lbl), CmmStaticLit CmmLit
ind, CmmStatic
_, CmmStatic
_])
  | CLabel
lbl CLabel -> CLabel -> Bool
forall a. Eq a => a -> a -> Bool
== CLabel
mkIndStaticInfoLabel,
    let labelInd :: CmmLit -> Maybe CLabel
labelInd (CmmLabelOff CLabel
l Int
_) = CLabel -> Maybe CLabel
forall a. a -> Maybe a
Just CLabel
l
        labelInd (CmmLabel CLabel
l) = CLabel -> Maybe CLabel
forall a. a -> Maybe a
Just CLabel
l
        labelInd CmmLit
_ = Maybe CLabel
forall a. Maybe a
Nothing,
    Just CLabel
ind' <- CmmLit -> Maybe CLabel
labelInd CmmLit
ind,
    CLabel
alias CLabel -> CLabel -> Bool
`mayRedirectTo` CLabel
ind' =
      Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprGloblDecl (NCGConfig -> Platform
ncgPlatform NCGConfig
config) CLabel
alias
        doc -> doc -> doc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
".equiv" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel (NCGConfig -> Platform
ncgPlatform NCGConfig
config) CLabel
alias Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel (NCGConfig -> Platform
ncgPlatform NCGConfig
config) CLabel
ind')
pprDatas NCGConfig
config (CmmStaticsRaw CLabel
lbl [CmmStatic]
dats) =
  [doc] -> doc
forall doc. IsDoc doc => [doc] -> doc
vcat (Platform -> CLabel -> doc
forall doc. IsDoc doc => Platform -> CLabel -> doc
pprLabel Platform
platform CLabel
lbl doc -> [doc] -> [doc]
forall a. a -> [a] -> [a]
: (CmmStatic -> doc) -> [CmmStatic] -> [doc]
forall a b. (a -> b) -> [a] -> [b]
map (NCGConfig -> CmmStatic -> doc
forall doc. IsDoc doc => NCGConfig -> CmmStatic -> doc
pprData NCGConfig
config) [CmmStatic]
dats)
  where
    platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config

pprData :: (IsDoc doc) => NCGConfig -> CmmStatic -> doc
pprData :: forall doc. IsDoc doc => NCGConfig -> CmmStatic -> doc
pprData NCGConfig
_config (CmmString ByteString
str) = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (ByteString -> Line doc
forall doc. IsLine doc => ByteString -> doc
pprString ByteString
str)
pprData NCGConfig
_config (CmmFileEmbed String
path Int
_) = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (String -> Line doc
forall doc. IsLine doc => String -> doc
pprFileEmbed String
path)
-- TODO: AFAIK there no Darwin for RISCV, so we may consider to simplify this.
pprData NCGConfig
config (CmmUninitialised Int
bytes) =
  Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line
    (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ let platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config
       in if Platform -> OS
platformOS Platform
platform OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
== OS
OSDarwin
            then String -> Line doc
forall doc. IsLine doc => String -> doc
text String
".space " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
bytes
            else String -> Line doc
forall doc. IsLine doc => String -> doc
text String
".skip " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
bytes
pprData NCGConfig
config (CmmStaticLit CmmLit
lit) = NCGConfig -> CmmLit -> doc
forall doc. IsDoc doc => NCGConfig -> CmmLit -> doc
pprDataItem NCGConfig
config CmmLit
lit

pprGloblDecl :: (IsDoc doc) => Platform -> CLabel -> doc
pprGloblDecl :: forall doc. IsDoc doc => Platform -> CLabel -> doc
pprGloblDecl Platform
platform CLabel
lbl
  | Bool -> Bool
not (CLabel -> Bool
externallyVisibleCLabel CLabel
lbl) = doc
forall doc. IsOutput doc => doc
empty
  | Bool
otherwise = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.globl " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl)

-- Note [Always use objects for info tables]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- See discussion in X86.Ppr for why this is necessary.  Essentially we need to
-- ensure that we never pass function symbols when we might want to lookup the
-- info table.  If we did, we could end up with procedure linking tables
-- (PLT)s, and thus the lookup wouldn't point to the function, but into the
-- jump table.
--
-- Fun fact: The LLVMMangler exists to patch this issue on the LLVM side as
-- well.
pprLabelType' :: (IsLine doc) => Platform -> CLabel -> doc
pprLabelType' :: forall doc. IsLine doc => Platform -> CLabel -> doc
pprLabelType' Platform
platform CLabel
lbl =
  if CLabel -> Bool
isCFunctionLabel CLabel
lbl Bool -> Bool -> Bool
|| Bool
functionOkInfoTable
    then String -> doc
forall doc. IsLine doc => String -> doc
text String
"@function"
    else String -> doc
forall doc. IsLine doc => String -> doc
text String
"@object"
  where
    functionOkInfoTable :: Bool
functionOkInfoTable =
      Platform -> Bool
platformTablesNextToCode Platform
platform
        Bool -> Bool -> Bool
&& CLabel -> Bool
isInfoTableLabel CLabel
lbl
        Bool -> Bool -> Bool
&& Bool -> Bool
not (CLabel -> Bool
isCmmInfoTableLabel CLabel
lbl)
        Bool -> Bool -> Bool
&& Bool -> Bool
not (CLabel -> Bool
isConInfoTableLabel CLabel
lbl)

-- this is called pprTypeAndSizeDecl in PPC.Ppr
pprTypeDecl :: (IsDoc doc) => Platform -> CLabel -> doc
pprTypeDecl :: forall doc. IsDoc doc => Platform -> CLabel -> doc
pprTypeDecl Platform
platform CLabel
lbl =
  if OS -> Bool
osElfTarget (Platform -> OS
platformOS Platform
platform) Bool -> Bool -> Bool
&& CLabel -> Bool
externallyVisibleCLabel CLabel
lbl
    then Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
".type " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
", " Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprLabelType' Platform
platform CLabel
lbl)
    else doc
forall doc. IsOutput doc => doc
empty

pprDataItem :: (IsDoc doc) => NCGConfig -> CmmLit -> doc
pprDataItem :: forall doc. IsDoc doc => NCGConfig -> CmmLit -> doc
pprDataItem NCGConfig
config CmmLit
lit =
  [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ (Format -> CmmLit -> [Line doc]
ppr_item (CmmType -> Format
cmmTypeFormat (CmmType -> Format) -> CmmType -> Format
forall a b. (a -> b) -> a -> b
$ Platform -> CmmLit -> CmmType
cmmLitType Platform
platform CmmLit
lit) CmmLit
lit)
  where
    platform :: Platform
platform = NCGConfig -> Platform
ncgPlatform NCGConfig
config

    imm :: Imm
imm = CmmLit -> Imm
litToImm CmmLit
lit

    ppr_item :: Format -> CmmLit -> [Line doc]
ppr_item Format
II8 CmmLit
_ = [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.byte\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> Line doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
platform Imm
imm]
    ppr_item Format
II16 CmmLit
_ = [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.short\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> Line doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
platform Imm
imm]
    ppr_item Format
II32 CmmLit
_ = [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.long\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> Line doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
platform Imm
imm]
    ppr_item Format
II64 CmmLit
_ = [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.quad\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> Line doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
platform Imm
imm]
    ppr_item Format
FF32 (CmmFloat Rational
r Width
_) =
      let bs :: [Word8]
bs = Float -> [Word8]
floatToBytes (Rational -> Float
forall a. Fractional a => Rational -> a
fromRational Rational
r)
       in (Word8 -> Line doc) -> [Word8] -> [Line doc]
forall a b. (a -> b) -> [a] -> [b]
map (\Word8
b -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.byte\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)) [Word8]
bs
    ppr_item Format
FF64 (CmmFloat Rational
r Width
_) =
      let bs :: [Word8]
bs = Double -> [Word8]
doubleToBytes (Rational -> Double
forall a. Fractional a => Rational -> a
fromRational Rational
r)
       in (Word8 -> Line doc) -> [Word8] -> [Line doc]
forall a b. (a -> b) -> [a] -> [b]
map (\Word8
b -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.byte\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int (Word8 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
b)) [Word8]
bs
    ppr_item Format
_ CmmLit
_ = String -> SDoc -> [Line doc]
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"pprDataItem:ppr_item" (String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ CmmLit -> String
forall a. Show a => a -> String
show CmmLit
lit)

-- | Pretty print an immediate value in the @data@ section
--
-- This does not include any checks. We rely on the Assembler to check for
-- errors. Use `pprOpImm` for immediates in instructions (operands.)
pprDataImm :: (IsLine doc) => Platform -> Imm -> doc
pprDataImm :: forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
_ (ImmInt Int
i) = Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
i
pprDataImm Platform
_ (ImmInteger Integer
i) = Integer -> doc
forall doc. IsLine doc => Integer -> doc
integer Integer
i
pprDataImm Platform
p (ImmCLbl CLabel
l) = Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
p CLabel
l
pprDataImm Platform
p (ImmIndex CLabel
l Int
i) = Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
p CLabel
l doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'+' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
i
pprDataImm Platform
_ (ImmLit FastString
s) = FastString -> doc
forall doc. IsLine doc => FastString -> doc
ftext FastString
s
pprDataImm Platform
_ (ImmFloat Rational
f) = Float -> doc
forall doc. IsLine doc => Float -> doc
float (Rational -> Float
forall a. Fractional a => Rational -> a
fromRational Rational
f)
pprDataImm Platform
_ (ImmDouble Rational
d) = Double -> doc
forall doc. IsLine doc => Double -> doc
double (Rational -> Double
forall a. Fractional a => Rational -> a
fromRational Rational
d)
pprDataImm Platform
p (ImmConstantSum Imm
a Imm
b) = Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
p Imm
a doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'+' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
p Imm
b
pprDataImm Platform
p (ImmConstantDiff Imm
a Imm
b) =
  Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
p Imm
a
    doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'-'
    doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
lparen
    doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprDataImm Platform
p Imm
b
    doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
rparen

-- | Comment @c@ with @# c@
asmComment :: SDoc -> SDoc
asmComment :: SDoc -> SDoc
asmComment SDoc
c = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"#" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
c

-- | Commen @c@ with @// c@
asmDoubleslashComment :: SDoc -> SDoc
asmDoubleslashComment :: SDoc -> SDoc
asmDoubleslashComment SDoc
c = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"//" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
c

-- | Comment @c@ with @/* c */@ (multiline comment)
asmMultilineComment :: SDoc -> SDoc
asmMultilineComment :: SDoc -> SDoc
asmMultilineComment SDoc
c = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"/*" SDoc -> SDoc -> SDoc
$+$ SDoc
c SDoc -> SDoc -> SDoc
$+$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"*/"

-- | Pretty print an immediate operand of an instruction
--
-- The kinds of immediates we can use here is pretty limited: RISCV doesn't
-- support index expressions (as e.g. Aarch64 does.) Floating points need to
-- fit in range. As we don't need them, forbit them to save us from future
-- troubles.
pprOpImm :: (IsLine doc) => Platform -> Imm -> doc
pprOpImm :: forall doc. IsLine doc => Platform -> Imm -> doc
pprOpImm Platform
platform Imm
im = case Imm
im of
  ImmInt Int
i -> Int -> doc
forall doc. IsLine doc => Int -> doc
int Int
i
  ImmInteger Integer
i -> Integer -> doc
forall doc. IsLine doc => Integer -> doc
integer Integer
i
  ImmCLbl CLabel
l -> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'=' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
l
  Imm
_ -> String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.Ppr.pprOpImm" (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Unsupported immediate for instruction operands" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
colon SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> (Imm -> String) -> Imm -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Imm -> String
forall a. Show a => a -> String
show) Imm
im)

-- | Negate integer immediate operand
--
-- This function is partial and will panic if the operand is not an integer.
negOp :: Operand -> Operand
negOp :: Operand -> Operand
negOp (OpImm (ImmInt Int
i)) = Imm -> Operand
OpImm (Int -> Imm
ImmInt (Int -> Int
forall a. Num a => a -> a
negate Int
i))
negOp (OpImm (ImmInteger Integer
i)) = Imm -> Operand
OpImm (Integer -> Imm
ImmInteger (Integer -> Integer
forall a. Num a => a -> a
negate Integer
i))
negOp Operand
op = String -> SDoc -> Operand
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.negOp" (String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ Operand -> String
forall a. Show a => a -> String
show Operand
op)

-- | Pretty print an operand
pprOp :: (IsLine doc) => Platform -> Operand -> doc
pprOp :: forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
plat Operand
op = case Operand
op of
  OpReg Width
w Reg
r -> Width -> Reg -> doc
forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
w Reg
r
  OpImm Imm
im -> Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprOpImm Platform
plat Imm
im
  OpAddr (AddrRegImm Reg
r1 Imm
im) -> Platform -> Imm -> doc
forall doc. IsLine doc => Platform -> Imm -> doc
pprOpImm Platform
plat Imm
im doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
'(' doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Width -> Reg -> doc
forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
W64 Reg
r1 doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
')'
  OpAddr (AddrReg Reg
r1) -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"0(" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Width -> Reg -> doc
forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
W64 Reg
r1 doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Char -> doc
forall doc. IsLine doc => Char -> doc
char Char
')'

-- | Pretty print register with calling convention name
--
-- This representation makes it easier to reason about the emitted assembly
-- code.
pprReg :: forall doc. (IsLine doc) => Width -> Reg -> doc
pprReg :: forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
w Reg
r = case Reg
r of
  RegReal (RealRegSingle Int
i) -> Int -> doc
ppr_reg_no Int
i
  -- virtual regs should not show up, but this is helpful for debugging.
  RegVirtual (VirtualRegI Unique
u) -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"%vI_" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Unique -> doc
forall doc. IsLine doc => Unique -> doc
pprUniqueAlways Unique
u
  RegVirtual (VirtualRegD Unique
u) -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"%vD_" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Unique -> doc
forall doc. IsLine doc => Unique -> doc
pprUniqueAlways Unique
u
  Reg
_ -> String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RiscV64.pprReg" (String -> SDoc
forall doc. IsLine doc => String -> doc
text (Reg -> String
forall a. Show a => a -> String
show Reg
r) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w)
  where
    ppr_reg_no :: Int -> doc
    -- General Purpose Registers
    ppr_reg_no :: Int -> doc
ppr_reg_no Int
0 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"zero"
    ppr_reg_no Int
1 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ra"
    ppr_reg_no Int
2 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"sp"
    ppr_reg_no Int
3 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"gp"
    ppr_reg_no Int
4 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"tp"
    ppr_reg_no Int
5 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t0"
    ppr_reg_no Int
6 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t1"
    ppr_reg_no Int
7 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t2"
    ppr_reg_no Int
8 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s0"
    ppr_reg_no Int
9 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s1"
    ppr_reg_no Int
10 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a0"
    ppr_reg_no Int
11 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a1"
    ppr_reg_no Int
12 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a2"
    ppr_reg_no Int
13 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a3"
    ppr_reg_no Int
14 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a4"
    ppr_reg_no Int
15 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a5"
    ppr_reg_no Int
16 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a6"
    ppr_reg_no Int
17 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"a7"
    ppr_reg_no Int
18 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s2"
    ppr_reg_no Int
19 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s3"
    ppr_reg_no Int
20 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s4"
    ppr_reg_no Int
21 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s5"
    ppr_reg_no Int
22 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s6"
    ppr_reg_no Int
23 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s7"
    ppr_reg_no Int
24 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s8"
    ppr_reg_no Int
25 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s9"
    ppr_reg_no Int
26 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s10"
    ppr_reg_no Int
27 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"s11"
    ppr_reg_no Int
28 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t3"
    ppr_reg_no Int
29 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t4"
    ppr_reg_no Int
30 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t5"
    ppr_reg_no Int
31 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"t6"
    -- Floating Point Registers
    ppr_reg_no Int
32 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft0"
    ppr_reg_no Int
33 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft1"
    ppr_reg_no Int
34 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft2"
    ppr_reg_no Int
35 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft3"
    ppr_reg_no Int
36 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft4"
    ppr_reg_no Int
37 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft5"
    ppr_reg_no Int
38 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft6"
    ppr_reg_no Int
39 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft7"
    ppr_reg_no Int
40 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs0"
    ppr_reg_no Int
41 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs1"
    ppr_reg_no Int
42 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa0"
    ppr_reg_no Int
43 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa1"
    ppr_reg_no Int
44 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa2"
    ppr_reg_no Int
45 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa3"
    ppr_reg_no Int
46 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa4"
    ppr_reg_no Int
47 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa5"
    ppr_reg_no Int
48 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa6"
    ppr_reg_no Int
49 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fa7"
    ppr_reg_no Int
50 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs2"
    ppr_reg_no Int
51 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs3"
    ppr_reg_no Int
52 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs4"
    ppr_reg_no Int
53 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs5"
    ppr_reg_no Int
54 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs6"
    ppr_reg_no Int
55 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs7"
    ppr_reg_no Int
56 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs8"
    ppr_reg_no Int
57 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs9"
    ppr_reg_no Int
58 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs10"
    ppr_reg_no Int
59 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"fs11"
    ppr_reg_no Int
60 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft8"
    ppr_reg_no Int
61 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft9"
    ppr_reg_no Int
62 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft10"
    ppr_reg_no Int
63 = String -> doc
forall doc. IsLine doc => String -> doc
text String
"ft11"
    ppr_reg_no Int
i
      | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 = String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Unexpected register number (min is 0)" (Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
i)
      | Int
i Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
63 = String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Unexpected register number (max is 63)" (Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
i)
      -- no support for widths > W64.
      | Bool
otherwise = String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Unsupported width in register (max is 64)" (Width -> SDoc
forall a. Outputable a => a -> SDoc
ppr Width
w SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
i)

-- | Single precission `Operand` (floating-point)
isSingleOp :: Operand -> Bool
isSingleOp :: Operand -> Bool
isSingleOp (OpReg Width
W32 Reg
_) = Bool
True
isSingleOp Operand
_ = Bool
False

-- | Double precission `Operand` (floating-point)
isDoubleOp :: Operand -> Bool
isDoubleOp :: Operand -> Bool
isDoubleOp (OpReg Width
W64 Reg
_) = Bool
True
isDoubleOp Operand
_ = Bool
False

-- | `Operand` is an immediate value
isImmOp :: Operand -> Bool
isImmOp :: Operand -> Bool
isImmOp (OpImm Imm
_) = Bool
True
isImmOp Operand
_ = Bool
False

-- | `Operand` is an immediate @0@ value
isImmZero :: Operand -> Bool
isImmZero :: Operand -> Bool
isImmZero (OpImm (ImmFloat Rational
0)) = Bool
True
isImmZero (OpImm (ImmDouble Rational
0)) = Bool
True
isImmZero (OpImm (ImmInt Int
0)) = Bool
True
isImmZero Operand
_ = Bool
False

-- | `Target` represents a label
isLabel :: Target -> Bool
isLabel :: Target -> Bool
isLabel (TBlock BlockId
_) = Bool
True
isLabel Target
_ = Bool
False

-- | Get the pretty-printed label from a `Target`
--
-- This function is partial and will panic if the `Target` is not a label.
getLabel :: (IsLine doc) => Platform -> Target -> doc
getLabel :: forall doc. IsLine doc => Platform -> Target -> doc
getLabel Platform
platform (TBlock BlockId
bid) = Platform -> BlockId -> doc
forall doc. IsLine doc => Platform -> BlockId -> doc
pprBlockId Platform
platform BlockId
bid
  where
    pprBlockId :: (IsLine doc) => Platform -> BlockId -> doc
    pprBlockId :: forall doc. IsLine doc => Platform -> BlockId -> doc
pprBlockId Platform
platform BlockId
bid = Platform -> CLabel -> doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform (Unique -> CLabel
mkLocalBlockLabel (BlockId -> Unique
forall a. Uniquable a => a -> Unique
getUnique BlockId
bid))
getLabel Platform
_platform Target
_other = String -> doc
forall a. HasCallStack => String -> a
panic String
"Cannot turn this into a label"

-- | Pretty-print an `Instr`
--
-- This function is partial and will panic if the `Instr` is not supported. This
-- can happen due to invalid operands or unexpected meta instructions.
pprInstr :: (IsDoc doc) => Platform -> Instr -> doc
pprInstr :: forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform Instr
instr = case Instr
instr of
  -- see Note [dualLine and dualDoc] in GHC.Utils.Outputable
  COMMENT SDoc
s -> SDoc -> HDoc -> doc
forall doc. IsDoc doc => SDoc -> HDoc -> doc
dualDoc (SDoc -> SDoc
asmComment SDoc
s) HDoc
forall doc. IsOutput doc => doc
empty
  MULTILINE_COMMENT SDoc
s -> SDoc -> HDoc -> doc
forall doc. IsDoc doc => SDoc -> HDoc -> doc
dualDoc (SDoc -> SDoc
asmMultilineComment SDoc
s) HDoc
forall doc. IsOutput doc => doc
empty
  ANN SDoc
d Instr
i -> SDoc -> HDoc -> doc
forall doc. IsDoc doc => SDoc -> HDoc -> doc
dualDoc (Platform -> Instr -> SDoc
forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform Instr
i SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
asmDoubleslashComment SDoc
d) (Platform -> Instr -> HDoc
forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform Instr
i)
  LOCATION Int
file Int
line' Int
col LexicalFastString
_name ->
    Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t.loc" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
file Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
line' Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
col)
  DELTA Int
d -> SDoc -> HDoc -> doc
forall doc. IsDoc doc => SDoc -> HDoc -> doc
dualDoc (SDoc -> SDoc
asmComment (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"\tdelta = " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Int -> SDoc
forall doc. IsLine doc => Int -> doc
int Int
d) HDoc
forall doc. IsOutput doc => doc
empty
  NEWBLOCK BlockId
_ -> String -> doc
forall a. HasCallStack => String -> a
panic String
"PprInstr: NEWBLOCK"
  LDATA Section
_ RawCmmStatics
_ -> String -> doc
forall a. HasCallStack => String -> a
panic String
"pprInstr: LDATA"
  Instr
PUSH_STACK_FRAME ->
    [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
      [ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi sp, sp, -16",
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsd x1, 8(sp)", -- store RA
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsd x8, 0(sp)", -- store FP/s0
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi x8, sp, 16"
      ]
  Instr
POP_STACK_FRAME ->
    [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
      [ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tld x8, 0(sp)", -- restore FP/s0
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tld x1, 8(sp)", -- restore RA
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi sp, sp, 16"
      ]
  ADD Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfadd." Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> if Operand -> Bool
isSingleOp Operand
o1 then String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"s" else String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"d") Operand
o1 Operand
o2 Operand
o3
    -- This case is used for sign extension: SEXT.W op
    | OpReg Width
W64 Reg
_ <- Operand
o1, OpReg Width
W32 Reg
_ <- Operand
o2, Operand -> Bool
isImmOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddiw") Operand
o1 Operand
o2 Operand
o3
    | Bool
otherwise -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tadd") Operand
o1 Operand
o2 Operand
o3
  MUL Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmul." Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> if Operand -> Bool
isSingleOp Operand
o1 then String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"s" else String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"d") Operand
o1 Operand
o2 Operand
o3
    | Bool
otherwise -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tmul") Operand
o1 Operand
o2 Operand
o3
  MULH Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tmulh") Operand
o1 Operand
o2 Operand
o3
  NEG Operand
o1 Operand
o2 | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfneg.s") Operand
o1 Operand
o2
  NEG Operand
o1 Operand
o2 | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfneg.d") Operand
o1 Operand
o2
  NEG Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tneg") Operand
o1 Operand
o2
  DIV Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o3 ->
        -- TODO: This must (likely) be refined regarding width
        Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfdiv." Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> if Operand -> Bool
isSingleOp Operand
o1 then String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"s" else String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"d") Operand
o1 Operand
o2 Operand
o3
  DIV Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tdiv") Operand
o1 Operand
o2 Operand
o3
  REM Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
|| Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
|| Operand -> Bool
isFloatOp Operand
o3 ->
        String -> doc
forall a. HasCallStack => String -> a
panic String
"pprInstr - REM not implemented for floats (yet)"
  REM Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\trem") Operand
o1 Operand
o2 Operand
o3
  REMU Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tremu") Operand
o1 Operand
o2 Operand
o3
  SUB Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfsub." Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> if Operand -> Bool
isSingleOp Operand
o1 then String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"s" else String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"d") Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isImmOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi") Operand
o1 Operand
o2 (Operand -> Operand
negOp Operand
o3)
    | Bool
otherwise -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsub") Operand
o1 Operand
o2 Operand
o3
  DIVU Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tdivu") Operand
o1 Operand
o2 Operand
o3
  AND Operand
o1 Operand
o2 Operand
o3
    | Operand -> Bool
isImmOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tandi") Operand
o1 Operand
o2 Operand
o3
    | Bool
otherwise -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tand") Operand
o1 Operand
o2 Operand
o3
  OR Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tor") Operand
o1 Operand
o2 Operand
o3
  SRA Operand
o1 Operand
o2 Operand
o3 | Operand -> Bool
isImmOp Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsrai") Operand
o1 Operand
o2 Operand
o3
  SRA Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsra") Operand
o1 Operand
o2 Operand
o3
  XOR Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txor") Operand
o1 Operand
o2 Operand
o3
  SLL Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsll") Operand
o1 Operand
o2 Operand
o3
  SRL Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsrl") Operand
o1 Operand
o2 Operand
o3
  MOV Operand
o1 Operand
o2
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.d") Operand
o1 Operand
o2 -- fmv.d rd, rs is pseudo op fsgnj.d rd, rs, rs
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.s") Operand
o1 Operand
o2 -- fmv.s rd, rs is pseudo op fsgnj.s rd, rs, rs
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isImmZero Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
o1 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.d.w") Operand
o1 Operand
zero
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Operand -> Bool
isImmZero Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
o1 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.s.w") Operand
o1 Operand
zero
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Bool -> Bool
not (Operand -> Bool
isFloatOp Operand
o2) Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
o1 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.w.x") Operand
o1 Operand
o2
    | Operand -> Bool
isFloatOp Operand
o1 Bool -> Bool -> Bool
&& Bool -> Bool
not (Operand -> Bool
isFloatOp Operand
o2) Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
o1 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.d.x") Operand
o1 Operand
o2
    | Bool -> Bool
not (Operand -> Bool
isFloatOp Operand
o1) Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.x.w") Operand
o1 Operand
o2
    | Bool -> Bool
not (Operand -> Bool
isFloatOp Operand
o1) Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
o2 Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmv.x.d") Operand
o1 Operand
o2
    | (OpImm (ImmInteger Integer
i)) <- Operand
o2,
      Integer -> Bool
forall a. (Num a, Ord a) => a -> Bool
fitsIn12bitImm Integer
i ->
        [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
x0 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2]
    | (OpImm (ImmInt Int
i)) <- Operand
o2,
      Int -> Bool
forall a. (Num a, Ord a) => a -> Bool
fitsIn12bitImm Int
i ->
        [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
x0 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2]
    | (OpImm (ImmInteger Integer
i)) <- Operand
o2,
      Integer -> Bool
forall a. (Num a, Ord a, Bits a) => a -> Bool
fitsIn32bits Integer
i ->
        [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
          [ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlui" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"%hi(" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
")",
            String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddw" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"%lo(" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
")"
          ]
    | (OpImm (ImmInt Int
i)) <- Operand
o2,
      Int -> Bool
forall a. (Num a, Ord a, Bits a) => a -> Bool
fitsIn32bits Int
i ->
        [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
          [ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlui" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"%hi(" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
")",
            String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddw" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"%lo(" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
")"
          ]
    | Operand -> Bool
isImmOp Operand
o2 ->
        -- Surrender! Let the assembler figure out the right expressions with pseudo-op LI.
        [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tli" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2]
    | Bool
otherwise -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi") Operand
o1 Operand
o2 (Imm -> Operand
OpImm (Int -> Imm
ImmInt Int
0))
  ORI Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tori") Operand
o1 Operand
o2 Operand
o3
  XORI Operand
o1 Operand
o2 Operand
o3 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori") Operand
o1 Operand
o2 Operand
o3
  J_TBL [Maybe BlockId]
_ Maybe CLabel
_ Reg
r -> Platform -> Instr -> doc
forall doc. IsDoc doc => Platform -> Instr -> doc
pprInstr Platform
platform (Target -> Instr
B (Reg -> Target
TReg Reg
r))
  B Target
l | Target -> Bool
isLabel Target
l -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tjal" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
x0 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Target -> Line doc
forall doc. IsLine doc => Platform -> Target -> doc
getLabel Platform
platform Target
l
  B (TReg Reg
r) -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tjalr" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
x0 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Width -> Reg -> Line doc
forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
W64 Reg
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"0"
  BL Reg
r [Reg]
_ -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tjalr" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"x1" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Width -> Reg -> Line doc
forall doc. IsLine doc => Width -> Reg -> doc
pprReg Width
W64 Reg
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"0"
  BCOND Cond
c Operand
l Operand
r Target
t
    | Target -> Bool
isLabel Target
t ->
        Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\t" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Cond -> Line doc
forall doc. IsLine doc => Cond -> doc
pprBcond Cond
c Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Target -> Line doc
forall doc. IsLine doc => Platform -> Target -> doc
getLabel Platform
platform Target
t
  BCOND Cond
_ Operand
_ Operand
_ (TReg Reg
_) -> String -> doc
forall a. HasCallStack => String -> a
panic String
"RV64.ppr: No conditional branching to registers!"
  CSET Operand
o Operand
l Operand
r Cond
c -> case Cond
c of
    Cond
EQ
      | Operand -> Bool
isIntOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isIntOp Operand
r ->
          [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
            [ Operand -> Operand -> Line doc
subFor Operand
l Operand
r,
              String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tseqz" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o
            ]
    Cond
EQ | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tfeq." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r)
    Cond
NE
      | Operand -> Bool
isIntOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isIntOp Operand
r ->
          [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
            [ Operand -> Operand -> Line doc
subFor Operand
l Operand
r,
              String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsnez" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o
            ]
    Cond
NE
      | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r ->
          [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
            [ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tfeq." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r),
              String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"1"
            ]
    Cond
SLT -> [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r]
    Cond
SLE ->
      [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
        [ Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l,
          String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"1"
        ]
    Cond
SGE ->
      [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
        [ Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r,
          String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"1"
        ]
    Cond
SGT -> [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l]
    Cond
ULT -> [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltuFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r]
    Cond
ULE ->
      [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
        [ Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltuFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l,
          String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"1"
        ]
    Cond
UGE ->
      [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
        [ Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltuFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r,
          String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\txori" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"1"
        ]
    Cond
UGT -> [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_ [Operand -> Operand -> Line doc
forall {doc}. IsLine doc => Operand -> Operand -> doc
sltuFor Operand
l Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l]
    Cond
FLT | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tflt." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r)
    Cond
FLE | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tfle." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r)
    Cond
FGT | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tfgt." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r)
    Cond
FGE | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
binOp (String
"\tfge." String -> String -> String
forall a. [a] -> [a] -> [a]
++ Platform -> Operand -> Operand -> String
floatOpPrecision Platform
platform Operand
l Operand
r)
    Cond
x -> String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.ppr: unhandled CSET conditional" (String -> SDoc
forall doc. IsLine doc => String -> doc
text (Cond -> String
forall a. Show a => a -> String
show Cond
x) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
comma SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l)
    where
      subFor :: Operand -> Operand -> Line doc
subFor Operand
l Operand
r
        | (OpImm Imm
_) <- Operand
r = String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform (Operand -> Operand
negOp Operand
r)
        | (OpImm Imm
_) <- Operand
l = String -> Line doc
forall a. HasCallStack => String -> a
panic String
"RV64.ppr: Cannot SUB IMM _"
        | Bool
otherwise = String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsub" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r
      sltFor :: Operand -> Operand -> doc
sltFor Operand
l Operand
r
        | (OpImm Imm
_) <- Operand
r = String -> doc
forall doc. IsLine doc => String -> doc
text String
"\tslti"
        | (OpImm Imm
_) <- Operand
l = String -> doc
forall a. HasCallStack => String -> a
panic String
"PV64.ppr: Cannot SLT IMM _"
        | Bool
otherwise = String -> doc
forall doc. IsLine doc => String -> doc
text String
"\tslt"
      sltuFor :: Operand -> Operand -> doc
sltuFor Operand
l Operand
r
        | (OpImm Imm
_) <- Operand
r = String -> doc
forall doc. IsLine doc => String -> doc
text String
"\tsltui"
        | (OpImm Imm
_) <- Operand
l = String -> doc
forall a. HasCallStack => String -> a
panic String
"PV64.ppr: Cannot SLTU IMM _"
        | Bool
otherwise = String -> doc
forall doc. IsLine doc => String -> doc
text String
"\tsltu"
      binOp :: (IsLine doc) => String -> doc
      binOp :: forall doc. IsLine doc => String -> doc
binOp String
op = String -> doc
forall doc. IsLine doc => String -> doc
text String
op doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
comma doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
l doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> doc
forall doc. IsLine doc => doc
comma doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
r
  STR Format
II8 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsb") Operand
o1 Operand
o2
  STR Format
II16 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsh") Operand
o1 Operand
o2
  STR Format
II32 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsw") Operand
o1 Operand
o2
  STR Format
II64 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tsd") Operand
o1 Operand
o2
  STR Format
FF32 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfsw") Operand
o1 Operand
o2
  STR Format
FF64 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfsd") Operand
o1 Operand
o2
  LDR Format
_f Operand
o1 (OpImm (ImmIndex CLabel
lbl Int
off)) ->
    [Line doc] -> doc
forall doc. IsDoc doc => [Line doc] -> doc
lines_
      [ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tla" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl,
        String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\taddi" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> Line doc
forall doc. IsLine doc => Int -> doc
int Int
off
      ]
  LDR Format
_f Operand
o1 (OpImm (ImmCLbl CLabel
lbl)) ->
    Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tla" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> CLabel -> Line doc
forall doc. IsLine doc => Platform -> CLabel -> doc
pprAsmLabel Platform
platform CLabel
lbl
  LDR Format
II8 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlb") Operand
o1 Operand
o2
  LDR Format
II16 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlh") Operand
o1 Operand
o2
  LDR Format
II32 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlw") Operand
o1 Operand
o2
  LDR Format
II64 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tld") Operand
o1 Operand
o2
  LDR Format
FF32 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tflw") Operand
o1 Operand
o2
  LDR Format
FF64 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfld") Operand
o1 Operand
o2
  LDRU Format
II8 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlbu") Operand
o1 Operand
o2
  LDRU Format
II16 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlhu") Operand
o1 Operand
o2
  LDRU Format
II32 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tlwu") Operand
o1 Operand
o2
  -- double words (64bit) cannot be sign extended by definition
  LDRU Format
II64 Operand
o1 Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tld") Operand
o1 Operand
o2
  LDRU Format
FF32 Operand
o1 o2 :: Operand
o2@(OpAddr (AddrReg Reg
_)) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tflw") Operand
o1 Operand
o2
  LDRU Format
FF32 Operand
o1 o2 :: Operand
o2@(OpAddr (AddrRegImm Reg
_ Imm
_)) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tflw") Operand
o1 Operand
o2
  LDRU Format
FF64 Operand
o1 o2 :: Operand
o2@(OpAddr (AddrReg Reg
_)) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfld") Operand
o1 Operand
o2
  LDRU Format
FF64 Operand
o1 o2 :: Operand
o2@(OpAddr (AddrRegImm Reg
_ Imm
_)) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfld") Operand
o1 Operand
o2
  LDRU Format
f Operand
o1 Operand
o2 -> String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Unsupported unsigned load" ((String -> SDoc
forall doc. IsLine doc => String -> doc
text (String -> SDoc) -> (Format -> String) -> Format -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Format -> String
forall a. Show a => a -> String
show) Format
f SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2)
  FENCE FenceType
r FenceType
w -> Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfence" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> FenceType -> Line doc
forall {doc}. IsLine doc => FenceType -> doc
pprFenceType FenceType
r Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Char -> Line doc
forall doc. IsLine doc => Char -> doc
char Char
',' Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> FenceType -> Line doc
forall {doc}. IsLine doc => FenceType -> doc
pprFenceType FenceType
w
  FCVT FcvtVariant
FloatToFloat o1 :: Operand
o1@(OpReg Width
W32 Reg
_) o2 :: Operand
o2@(OpReg Width
W64 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.s.d") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToFloat o1 :: Operand
o1@(OpReg Width
W64 Reg
_) o2 :: Operand
o2@(OpReg Width
W32 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.d.s") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToFloat Operand
o1 Operand
o2 ->
    String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.pprInstr - impossible float to float conversion"
      (SDoc -> doc) -> SDoc -> doc
forall a b. (a -> b) -> a -> b
$ Line SDoc -> SDoc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"->" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2)
  FCVT FcvtVariant
IntToFloat o1 :: Operand
o1@(OpReg Width
W32 Reg
_) o2 :: Operand
o2@(OpReg Width
W32 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.s.w") Operand
o1 Operand
o2
  FCVT FcvtVariant
IntToFloat o1 :: Operand
o1@(OpReg Width
W32 Reg
_) o2 :: Operand
o2@(OpReg Width
W64 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.s.l") Operand
o1 Operand
o2
  FCVT FcvtVariant
IntToFloat o1 :: Operand
o1@(OpReg Width
W64 Reg
_) o2 :: Operand
o2@(OpReg Width
W32 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.d.w") Operand
o1 Operand
o2
  FCVT FcvtVariant
IntToFloat o1 :: Operand
o1@(OpReg Width
W64 Reg
_) o2 :: Operand
o2@(OpReg Width
W64 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.d.l") Operand
o1 Operand
o2
  FCVT FcvtVariant
IntToFloat Operand
o1 Operand
o2 ->
    String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.pprInstr - impossible integer to float conversion"
      (SDoc -> doc) -> SDoc -> doc
forall a b. (a -> b) -> a -> b
$ Line SDoc -> SDoc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"->" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2)
  FCVT FcvtVariant
FloatToInt o1 :: Operand
o1@(OpReg Width
W32 Reg
_) o2 :: Operand
o2@(OpReg Width
W32 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.w.s") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToInt o1 :: Operand
o1@(OpReg Width
W32 Reg
_) o2 :: Operand
o2@(OpReg Width
W64 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.w.d") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToInt o1 :: Operand
o1@(OpReg Width
W64 Reg
_) o2 :: Operand
o2@(OpReg Width
W32 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.l.s") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToInt o1 :: Operand
o1@(OpReg Width
W64 Reg
_) o2 :: Operand
o2@(OpReg Width
W64 Reg
_) -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfcvt.l.d") Operand
o1 Operand
o2
  FCVT FcvtVariant
FloatToInt Operand
o1 Operand
o2 ->
    String -> SDoc -> doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"RV64.pprInstr - impossible float to integer conversion"
      (SDoc -> doc) -> SDoc -> doc
forall a b. (a -> b) -> a -> b
$ Line SDoc -> SDoc
forall doc. IsDoc doc => Line doc -> doc
line (Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"->" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2)
  FABS Operand
o1 Operand
o2 | Operand -> Bool
isSingleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfabs.s") Operand
o1 Operand
o2
  FABS Operand
o1 Operand
o2 | Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> doc
op2 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfabs.d") Operand
o1 Operand
o2
  FMIN Operand
o1 Operand
o2 Operand
o3 | Operand -> Bool
isSingleOp Operand
o1 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmin.s") Operand
o1 Operand
o2 Operand
o3
                | Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmin.d") Operand
o1 Operand
o2 Operand
o3
  FMAX Operand
o1 Operand
o2 Operand
o3 | Operand -> Bool
isSingleOp Operand
o1 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmax.s") Operand
o1 Operand
o2 Operand
o3
                | Operand -> Bool
isDoubleOp Operand
o2 -> Line doc -> Operand -> Operand -> Operand -> doc
op3 (String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmax.d") Operand
o1 Operand
o2 Operand
o3
  FMA FMASign
variant Operand
d Operand
r1 Operand
r2 Operand
r3 ->
    let fma :: Line doc
fma = case FMASign
variant of
          FMASign
FMAdd -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmadd" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
dot Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Operand -> Line doc
floatPrecission Operand
d
          FMASign
FMSub -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfmsub" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
dot Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Operand -> Line doc
floatPrecission Operand
d
          FMASign
FNMAdd -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfnmadd" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
dot Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Operand -> Line doc
floatPrecission Operand
d
          FMASign
FNMSub -> String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"\tfnmsub" Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
dot Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Operand -> Line doc
floatPrecission Operand
d
     in Line doc -> Operand -> Operand -> Operand -> Operand -> doc
op4 Line doc
fma Operand
d Operand
r1 Operand
r2 Operand
r3
  Instr
instr -> String -> doc
forall a. HasCallStack => String -> a
panic (String -> doc) -> String -> doc
forall a b. (a -> b) -> a -> b
$ String
"RV64.pprInstr - Unknown instruction: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Instr -> String
instrCon Instr
instr
  where
    op2 :: Line doc -> Operand -> Operand -> doc
op2 Line doc
op Operand
o1 Operand
o2 = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ Line doc
op Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2
    op3 :: Line doc -> Operand -> Operand -> Operand -> doc
op3 Line doc
op Operand
o1 Operand
o2 Operand
o3 = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ Line doc
op Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o3
    op4 :: Line doc -> Operand -> Operand -> Operand -> Operand -> doc
op4 Line doc
op Operand
o1 Operand
o2 Operand
o3 Operand
o4 = Line doc -> doc
forall doc. IsDoc doc => Line doc -> doc
line (Line doc -> doc) -> Line doc -> doc
forall a b. (a -> b) -> a -> b
$ Line doc
op Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o1 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o2 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o3 Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<> Line doc
forall doc. IsLine doc => doc
comma Line doc -> Line doc -> Line doc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> Line doc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o4
    pprFenceType :: FenceType -> doc
pprFenceType FenceType
FenceRead = String -> doc
forall doc. IsLine doc => String -> doc
text String
"r"
    pprFenceType FenceType
FenceWrite = String -> doc
forall doc. IsLine doc => String -> doc
text String
"w"
    pprFenceType FenceType
FenceReadWrite = String -> doc
forall doc. IsLine doc => String -> doc
text String
"rw"
    floatPrecission :: Operand -> Line doc
floatPrecission Operand
o
      | Operand -> Bool
isSingleOp Operand
o = String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"s"
      | Operand -> Bool
isDoubleOp Operand
o = String -> Line doc
forall doc. IsLine doc => String -> doc
text String
"d"
      | Bool
otherwise = String -> SDoc -> Line doc
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Impossible floating point precission: " (Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
platform Operand
o)

floatOpPrecision :: Platform -> Operand -> Operand -> String
floatOpPrecision :: Platform -> Operand -> Operand -> String
floatOpPrecision Platform
_p Operand
l Operand
r | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isSingleOp Operand
r = String
"s" -- single precision
floatOpPrecision Platform
_p Operand
l Operand
r | Operand -> Bool
isFloatOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isFloatOp Operand
r Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
l Bool -> Bool -> Bool
&& Operand -> Bool
isDoubleOp Operand
r = String
"d" -- double precision
floatOpPrecision Platform
p Operand
l Operand
r = String -> SDoc -> String
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Cannot determine floating point precission" (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"op1" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
p Operand
l SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"op2" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Platform -> Operand -> SDoc
forall doc. IsLine doc => Platform -> Operand -> doc
pprOp Platform
p Operand
r)

-- | Pretty print a conditional branch
--
-- This function is partial and will panic if the conditional is not supported;
-- i.e. if its floating point related.
pprBcond :: (IsLine doc) => Cond -> doc
pprBcond :: forall doc. IsLine doc => Cond -> doc
pprBcond Cond
c = String -> doc
forall doc. IsLine doc => String -> doc
text String
"b" doc -> doc -> doc
forall doc. IsLine doc => doc -> doc -> doc
<> Cond -> doc
forall doc. IsLine doc => Cond -> doc
pprCond Cond
c
  where
    pprCond :: (IsLine doc) => Cond -> doc
    pprCond :: forall doc. IsLine doc => Cond -> doc
pprCond Cond
c = case Cond
c of
      Cond
EQ -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"eq"
      Cond
NE -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"ne"
      Cond
SLT -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"lt"
      Cond
SLE -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"le"
      Cond
SGE -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"ge"
      Cond
SGT -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"gt"
      Cond
ULT -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"ltu"
      Cond
ULE -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"leu"
      Cond
UGE -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"geu"
      Cond
UGT -> String -> doc
forall doc. IsLine doc => String -> doc
text String
"gtu"
      -- BCOND cannot handle floating point comparisons / registers
      Cond
_ -> String -> doc
forall a. HasCallStack => String -> a
panic (String -> doc) -> String -> doc
forall a b. (a -> b) -> a -> b
$ String
"RV64.ppr: unhandled BCOND conditional: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Cond -> String
forall a. Show a => a -> String
show Cond
c