X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FbasicTypes%2FLiteral.lhs;h=da8685e6b3f094ae51d141b6dbd787b9cba0b35a;hp=d6e9274ae630b9134463e5be73f035e16cb47d15;hb=c1c2c25355bc462e521b2c5fb41ac79307da22ff;hpb=b71760aac3a1b2e7d772a4c0457ff3f19eac8631 diff --git a/compiler/basicTypes/Literal.lhs b/compiler/basicTypes/Literal.lhs index d6e9274..da8685e 100644 --- a/compiler/basicTypes/Literal.lhs +++ b/compiler/basicTypes/Literal.lhs @@ -11,6 +11,7 @@ -- any warnings in the module. See -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings -- for details +{-# LANGUAGE DeriveDataTypeable #-} module Literal ( @@ -26,6 +27,7 @@ module Literal -- ** Operations on Literals , literalType , hashLiteral + , absentLiteralOf -- ** Predicates on Literals and their contents , litIsDupable, litIsTrivial @@ -43,48 +45,26 @@ module Literal ) where import TysPrim +import PrelNames import Type +import TyCon import Outputable import FastTypes import FastString import BasicTypes import Binary -import Ratio - +import Constants +import UniqFM import Data.Int +import Data.Ratio import Data.Word import Data.Char +import Data.Data( Data, Typeable ) \end{code} %************************************************************************ %* * -\subsection{Sizes} -%* * -%************************************************************************ - -If we're compiling with GHC (and we're not cross-compiling), then we -know that minBound and maxBound :: Int are the right values for the -target architecture. Otherwise, we assume -2^31 and 2^31-1 -respectively (which will be wrong on a 64-bit machine). - -\begin{code} -tARGET_MIN_INT, tARGET_MAX_INT, tARGET_MAX_WORD :: Integer -#ifdef __GLASGOW_HASKELL__ -tARGET_MIN_INT = toInteger (minBound :: Int) -tARGET_MAX_INT = toInteger (maxBound :: Int) -#else -tARGET_MIN_INT = -2147483648 -tARGET_MAX_INT = 2147483647 -#endif -tARGET_MAX_WORD = (tARGET_MAX_INT * 2) + 1 - -tARGET_MAX_CHAR :: Int -tARGET_MAX_CHAR = 0x10ffff -\end{code} - -%************************************************************************ -%* * \subsection{Literals} %* * %************************************************************************ @@ -131,6 +111,7 @@ data Literal -- the label expects. Only applicable with -- @stdcall@ labels. @Just x@ => @\@ will -- be appended to label name when emitting assembly. + deriving (Data, Typeable) \end{code} Binary instance @@ -348,6 +329,21 @@ literalType (MachWord64 _) = word64PrimTy literalType (MachFloat _) = floatPrimTy literalType (MachDouble _) = doublePrimTy literalType (MachLabel _ _ _) = addrPrimTy + +absentLiteralOf :: TyCon -> Maybe Literal +-- Return a literal of the appropriate primtive +-- TyCon, to use as a placeholder when it doesn't matter +absentLiteralOf tc = lookupUFM absent_lits (tyConName tc) + +absent_lits :: UniqFM Literal +absent_lits = listToUFM [ (addrPrimTyConKey, MachNullAddr) + , (charPrimTyConKey, MachChar 'x') + , (intPrimTyConKey, MachInt 0) + , (int64PrimTyConKey, MachInt64 0) + , (floatPrimTyConKey, MachFloat 0) + , (doublePrimTyConKey, MachDouble 0) + , (wordPrimTyConKey, MachWord 0) + , (word64PrimTyConKey, MachWord64 0) ] \end{code}