ghc-7.8.2: The GHC API

Safe Haskell | None
Language | Haskell98

Literal

Contents

- Main data type
  - Creating Literals
  - Operations on Literals
  - Predicates on Literals and their contents
  - Coercions

Synopsis

- data Literal
  - = MachChar Char
  - | MachStr ByteString
  - | MachNullAddr
  - | MachInt Integer
  - | MachInt64 Integer
  - | MachWord Integer
  - | MachWord64 Integer
  - | MachFloat Rational
  - | MachDouble Rational
  - | MachLabel FastString (Maybe Int) FunctionOrData
  - | LitInteger Integer Type
- mkMachInt :: DynFlags -> Integer -> Literal
- mkMachWord :: DynFlags -> Integer -> Literal
- mkMachInt64 :: Integer -> Literal
- mkMachWord64 :: Integer -> Literal
- mkMachFloat :: Rational -> Literal
- mkMachDouble :: Rational -> Literal
- mkMachChar :: Char -> Literal
- mkMachString :: String -> Literal
- mkLitInteger :: Integer -> Type -> Literal
- literalType :: Literal -> Type
- hashLiteral :: Literal -> Int
- absentLiteralOf :: TyCon -> Maybe Literal
- pprLiteral :: (SDoc -> SDoc) -> Literal -> SDoc
- litIsDupable :: DynFlags -> Literal -> Bool
- litIsTrivial :: Literal -> Bool
- litIsLifted :: Literal -> Bool
- inIntRange :: DynFlags -> Integer -> Bool
- inWordRange :: DynFlags -> Integer -> Bool
- tARGET_MAX_INT :: DynFlags -> Integer
- inCharRange :: Char -> Bool
- isZeroLit :: Literal -> Bool
- litFitsInChar :: Literal -> Bool
- word2IntLit :: DynFlags -> Literal -> Literal
- int2WordLit :: DynFlags -> Literal -> Literal
- narrow8IntLit :: Literal -> Literal
- narrow16IntLit :: Literal -> Literal
- narrow32IntLit :: Literal -> Literal
- narrow8WordLit :: Literal -> Literal
- narrow16WordLit :: Literal -> Literal
- narrow32WordLit :: Literal -> Literal
- char2IntLit :: Literal -> Literal
- int2CharLit :: Literal -> Literal
- float2IntLit :: Literal -> Literal
- int2FloatLit :: Literal -> Literal
- double2IntLit :: Literal -> Literal
- int2DoubleLit :: Literal -> Literal
- nullAddrLit :: Literal
- float2DoubleLit :: Literal -> Literal
- double2FloatLit :: Literal -> Literal

# Main data type

data Literal

So-called `Literal`s are one of:

- An unboxed (machine) literal (`MachInt`, `MachFloat`, etc.), which is presumed to be surrounded by appropriate constructors (`Int#`, etc.), so that the overall thing makes sense.
- The literal derived from the label mentioned in a "foreign label" declaration (`MachLabel`)

Constructors

MachChar Char | `Char#` - at least 31 bits. Create with `mkMachChar`
MachStr ByteString | A string-literal: stored and emitted UTF-8 encoded, we'll arrange to decode it at runtime. Also emitted with a `'\0'` terminator. Create with `mkMachString`
MachNullAddr | The `NULL` pointer, the only pointer value that can be represented as a Literal. Create with `nullAddrLit`
MachInt Integer | `Int#` - at least `WORD_SIZE_IN_BITS` bits. Create with `mkMachInt`
MachInt64 Integer | `Int64#` - at least 64 bits. Create with `mkMachInt64`
MachWord Integer | `Word#` - at least `WORD_SIZE_IN_BITS` bits. Create with `mkMachWord`
MachWord64 Integer | `Word64#` - at least 64 bits. Create with `mkMachWord64`
MachFloat Rational | `Float#`. Create with `mkMachFloat`
MachDouble Rational | `Double#`. Create with `mkMachDouble`
MachLabel FastString (Maybe Int) FunctionOrData | A label literal. Parameters: 1) The name of the symbol mentioned in the declaration 2) The size (in bytes) of the arguments the label expects. Only applicable with `stdcall` labels. `Just x` => `<x>` will be appended to label name when emitting assembly.
LitInteger Integer Type |

Instances

Eq Literal |
Data Literal |
Ord Literal |
Outputable Literal |
Binary Literal |
Typeable * Literal |

## Creating Literals

mkMachInt :: DynFlags -> Integer -> Literal

Creates a `Literal` of type `Int#`

mkMachWord :: DynFlags -> Integer -> Literal

Creates a `Literal` of type `Word#`

mkMachInt64 :: Integer -> Literal

Creates a `Literal` of type `Int64#`

mkMachWord64 :: Integer -> Literal

Creates a `Literal` of type `Word64#`

mkMachFloat :: Rational -> Literal

Creates a `Literal` of type `Float#`

mkMachDouble :: Rational -> Literal

Creates a `Literal` of type `Double#`

mkMachChar :: Char -> Literal

Creates a `Literal` of type `Char#`

mkMachString :: String -> Literal

Creates a `Literal` of type `Addr#`, which is appropriate for passing to e.g. some of the "error" functions in GHC.Err such as `GHC.Err.runtimeError`

mkLitInteger :: Integer -> Type -> Literal

## Operations on Literals

literalType :: Literal -> Type

Find the Haskell `Type` the literal occupies

hashLiteral :: Literal -> Int

absentLiteralOf :: TyCon -> Maybe Literal

pprLiteral :: (SDoc -> SDoc) -> Literal -> SDoc

## Predicates on Literals and their contents

litIsDupable :: DynFlags -> Literal -> Bool

True if code space does not go bad if we duplicate this literal Currently we treat it just like `litIsTrivial`

litIsTrivial :: Literal -> Bool

True if there is absolutely no penalty to duplicating the literal. False principally of strings

litIsLifted :: Literal -> Bool

inIntRange :: DynFlags -> Integer -> Bool

inWordRange :: DynFlags -> Integer -> Bool

tARGET_MAX_INT :: DynFlags -> Integer

inCharRange :: Char -> Bool

isZeroLit :: Literal -> Bool

Tests whether the literal represents a zero of whatever type it is

litFitsInChar :: Literal -> Bool

## Coercions

word2IntLit :: DynFlags -> Literal -> Literal

int2WordLit :: DynFlags -> Literal -> Literal

narrow8IntLit :: Literal -> Literal

narrow16IntLit :: Literal -> Literal

narrow32IntLit :: Literal -> Literal

narrow8WordLit :: Literal -> Literal

narrow16WordLit :: Literal -> Literal

narrow32WordLit :: Literal -> Literal

char2IntLit :: Literal -> Literal

int2CharLit :: Literal -> Literal

float2IntLit :: Literal -> Literal

int2FloatLit :: Literal -> Literal

double2IntLit :: Literal -> Literal

int2DoubleLit :: Literal -> Literal

nullAddrLit :: Literal

float2DoubleLit :: Literal -> Literal

double2FloatLit :: Literal -> Literal