AbsCSyn.lhs 18.9 KB
 partain committed Jan 08, 1996 1 %  simonm committed Dec 02, 1998 2 3 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 %  simonpj committed Sep 13, 2002 4 % $Id: AbsCSyn.lhs,v 1.50 2002/09/13 15:02:25 simonpj Exp$  partain committed Jan 08, 1996 5 6 7 8 9 10 11 12 13 14 15 16 % \section[AbstractC]{Abstract C: the last stop before machine code} This Abstract C'' data type describes the raw Spineless Tagless machine model at a C-ish level; it is abstract'' in that it only includes C-like structures that we happen to need. The conversion of programs from @StgSyntax@ (basically a functional language) to @AbstractC@ (basically imperative C) is the heart of code generation. From @AbstractC@, one may convert to real C (for portability) or to raw assembler/machine code. \begin{code}  partain committed Apr 05, 1996 17 module AbsCSyn {- (  partain committed Jan 08, 1996 18 19  -- export everything AbstractC(..),  simonpj committed Sep 26, 2001 20  C_SRT(..)  partain committed Jan 08, 1996 21 22 23 24 25  CStmtMacro(..), CExprMacro(..), CAddrMode(..), ReturnInfo(..), mkAbstractCs, mkAbsCStmts, mkAlgAltsCSwitch,  partain committed Mar 19, 1996 26  mkIntCLit,  partain committed Jan 08, 1996 27 28 29 30 31 32 33 34  mkAbsCStmtList, mkCCostCentre, -- RegRelatives RegRelative(..), -- registers MagicId(..), node, infoptr,  simonm committed Dec 02, 1998 35  isVolatileReg,  partain committed May 17, 1996 36  CostRes(Cost)  partain committed Apr 05, 1996 37  )-} where  partain committed Jan 08, 1996 38   simonm committed Jan 08, 1998 39 40 #include "HsVersions.h"  sof committed Jul 25, 1997 41 import {-# SOURCE #-} ClosureInfo ( ClosureInfo )  simonm committed Jan 08, 1998 42   simonm committed Dec 02, 1998 43 import CLabel  simonpj committed Dec 19, 1996 44 import Constants ( mAX_Vanilla_REG, mAX_Float_REG,  simonm committed Dec 02, 1998 45 46  mAX_Double_REG, spRelToInt ) import CostCentre ( CostCentre, CostCentreStack )  simonpj committed Mar 23, 2000 47 import Literal ( mkMachInt, Literal(..) )  simonpj committed May 22, 2001 48 import ForeignCall ( CCallSpec )  simonm committed Dec 02, 1998 49 import PrimRep ( PrimRep(..) )  sewardj committed Dec 05, 2001 50 import MachOp ( MachOp(..) )  sof committed May 19, 1997 51 import Unique ( Unique )  simonpj committed Sep 26, 2001 52 import StgSyn ( StgOp )  simonm committed Apr 26, 1999 53 import TyCon ( TyCon )  simonm committed Dec 02, 1998 54 import BitSet -- for liveness masks  sewardj committed Oct 12, 2000 55 import FastTypes  simonmar committed Apr 29, 2002 56 import FastString  partain committed Jan 08, 1996 57 58 59 60 61 \end{code} @AbstractC@ is a list of Abstract~C statements, but the data structure is tree-ish, for easier and more efficient putting-together. \begin{code}  partain committed Apr 05, 1996 62 63 absCNop = AbsCNop  partain committed Jan 08, 1996 64 65 66 67 68 69 70 71 72 73 74 data AbstractC = AbsCNop | AbsCStmts AbstractC AbstractC -- and the individual stmts... \end{code} A note on @CAssign@: In general, the type associated with an assignment is the type of the lhs. However, when the lhs is a pointer to mixed types (e.g. SpB relative), the type of the assignment is the type of the rhs for float types, or the generic StgWord for all other types.  partain committed Mar 19, 1996 75 (In particular, a CharRep on the rhs is promoted to IntRep when  partain committed Jan 08, 1996 76 77 78 79 stored in a mixed type location.) \begin{code} | CAssign  simonm committed Mar 03, 1999 80 81  !CAddrMode -- target !CAddrMode -- source  partain committed Jan 08, 1996 82 83 84  | CJump CAddrMode -- Put this in the program counter  partain committed Mar 19, 1996 85  -- eg CJump (CReg (VanillaReg PtrRep 1))' puts Ret1 in PC  partain committed Jan 08, 1996 86 87 88 89 90 91 92 93  -- Enter can be done by: -- CJump (CVal NodeRel zeroOff) | CFallThrough CAddrMode -- Fall through into this routine -- (for the benefit of the native code generators) -- Equivalent to CJump in C land  simonm committed May 13, 1999 94 95 96  | CReturn -- Perform a return CAddrMode -- Address of a RET_ info table ReturnInfo -- Whether it's a direct or vectored return  partain committed Jan 08, 1996 97   simonm committed Mar 03, 1999 98  | CSwitch !CAddrMode  partain committed Mar 19, 1996 99  [(Literal, AbstractC)] -- alternatives  partain committed Jan 08, 1996 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115  AbstractC -- default; if there is no real Abstract C in here -- (e.g., all comments; see function "nonemptyAbsC"), -- then that means the default _cannot_ occur. -- If there is only one alternative & no default code, -- then there is no need to check the tag. -- Therefore, e.g.: -- CSwitch m [(tag,code)] AbsCNop == code | CCodeBlock CLabel AbstractC -- A labelled block of code; this "statement" is not -- executed; rather, the labelled code will be hoisted -- out to the top level (out of line) & it can be -- jumped to. | CInitHdr -- to initialise the header of a closure (both fixed/var parts) ClosureInfo  simonmar committed Jun 24, 1999 116  CAddrMode -- address of the info ptr  simonmar committed Jan 02, 2002 117  !CAddrMode -- cost centre to place in closure  partain committed Jan 08, 1996 118  -- CReg CurCostCentre or CC_HDR(R1.p{-Node-})  simonmar committed Nov 23, 2001 119  Int -- size of closure, for profiling  partain committed Jan 08, 1996 120   sewardj committed Dec 05, 2001 121 122 123  -- NEW CASES FOR EXPANDED PRIMOPS | CMachOpStmt -- Machine-level operation  sewardj committed Feb 06, 2002 124  CAddrMode -- result  sewardj committed Dec 05, 2001 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139  MachOp [CAddrMode] -- Arguments (Maybe [MagicId]) -- list of regs which need to be preserved -- across the primop. This is allowed to be Nothing only if -- machOpIsDefinitelyInline returns True. And that in turn may -- only return True if we are absolutely sure that the mach op -- can be done inline on all platforms. | CSequential -- Do the nested AbstractCs sequentially. [AbstractC] -- In particular, as far as the AbsCUtils.doSimultaneously -- is concerned, these stmts are to be treated as atomic -- and are not to be reordered. -- end of NEW CASES FOR EXPANDED PRIMOPS  partain committed Jan 08, 1996 140 141  | COpStmt [CAddrMode] -- Results  simonpj committed May 22, 2001 142  StgOp  partain committed Jan 08, 1996 143 144 145 146 147 148 149  [CAddrMode] -- Arguments [MagicId] -- Potentially volatile/live registers -- (to save/restore around the call/op) -- INVARIANT: When a PrimOp which can cause GC is used, the -- only live data is tidily on the STG stacks or in the STG -- registers (the code generator ensures this).  partain committed Mar 19, 1996 150  --  partain committed Jan 08, 1996 151 152 153 154  -- Why this? Because if the arguments were arbitrary -- addressing modes, they might be things like (Hp+6) which -- will get utterly spongled by GC.  partain committed Mar 19, 1996 155  | CSimultaneous -- Perform simultaneously all the statements  partain committed Jan 08, 1996 156 157 158 159 160 161 162  AbstractC -- in the nested AbstractC. They are only -- allowed to be CAssigns, COpStmts and AbsCNops, so the -- "simultaneous" part just concerns making -- sure that permutations work. -- For example { a := b, b := a } -- needs to go via (at least one) temporary  simonm committed Dec 02, 1998 163 164 165 166 167 168  | CCheck -- heap or stack checks, or both. CCheckMacro -- These might include some code to fill in tags [CAddrMode] -- on the stack, so we can't use CMacroStmt below. AbstractC | CRetDirect -- Direct return  simonm committed Mar 03, 1999 169  !Unique -- for making labels  simonm committed Dec 02, 1998 170  AbstractC -- return code  simonpj committed Sep 26, 2001 171  C_SRT -- SRT info  simonm committed Dec 02, 1998 172 173  Liveness -- stack liveness at the return point  partain committed Jan 08, 1996 174 175  -- see the notes about these next few; they follow below... | CMacroStmt CStmtMacro [CAddrMode]  simonmar committed Apr 29, 2002 176 177  | CCallProfCtrMacro FastString [CAddrMode] | CCallProfCCMacro FastString [CAddrMode]  partain committed Jan 08, 1996 178   sof committed Oct 21, 1998 179 180 181 182 183 184 185 186 187  {- The presence of this constructor is a makeshift solution; it being used to work around a gcc-related problem of handling typedefs within statement blocks (or, rather, the inability to do so.) The AbstractC flattener takes care of lifting out these typedefs if needs be (i.e., when generating .hc code and compiling 'foreign import dynamic's) -}  sof committed Oct 31, 1999 188  | CCallTypedef Bool {- True => use "typedef"; False => use "extern"-}  simonpj committed May 22, 2001 189  CCallSpec Unique [CAddrMode] [CAddrMode]  sof committed Oct 21, 1998 190   partain committed Jan 08, 1996 191 192 193  -- *** the next three [or so...] are DATA (those above are CODE) *** | CStaticClosure  simonmar committed Jan 02, 2002 194  ClosureInfo -- Todo: maybe info_lbl & closure_lbl instead?  simonm committed Dec 02, 1998 195 196  CAddrMode -- cost centre identifier to place in closure [CAddrMode] -- free vars; ptrs, then non-ptrs.  partain committed Jan 08, 1996 197   simonm committed Dec 02, 1998 198 199 200  | CSRT CLabel [CLabel] -- SRT declarations: basically an array of -- pointers to static closures.  ken committed Jul 24, 2001 201 202  | CBitmap CLabel LivenessMask -- A bitmap to be emitted if and only if -- it is larger than a target machine word.  partain committed Jan 08, 1996 203 204  | CClosureInfoAndCode  simonm committed Dec 02, 1998 205 206  ClosureInfo -- Explains placement and layout of closure AbstractC -- Slow entry point code  partain committed Jan 08, 1996 207  (Maybe AbstractC)  simonm committed Dec 02, 1998 208 209 210 211 212 213 214 215  -- Fast entry point code, if any String -- Closure description; NB we can't get this -- from ClosureInfo, because the latter refers -- to the *right* hand side of a defn, whereas -- the "description" refers to *left* hand side | CRetVector -- A labelled block of static data CLabel  partain committed Jan 08, 1996 216  [CAddrMode]  simonpj committed Sep 26, 2001 217  C_SRT -- SRT info  simonm committed Dec 02, 1998 218  Liveness -- stack liveness at the return point  partain committed Jan 08, 1996 219   simonm committed Apr 26, 1999 220 221 222  | CClosureTbl -- table of constructors for enumerated types TyCon -- which TyCon this table is for  simonmar committed Mar 08, 2000 223  | CModuleInitBlock -- module initialisation block  simonmar committed Jul 16, 2002 224 225  CLabel -- "plain" label for init block CLabel -- label for init block (with ver + way info)  simonmar committed Mar 08, 2000 226 227  AbstractC -- initialisation code  simonm committed Dec 02, 1998 228 229 230  | CCostCentreDecl -- A cost centre *declaration* Bool -- True <=> local => full declaration -- False <=> extern; just say so  partain committed Jan 08, 1996 231 232  CostCentre  simonm committed Dec 02, 1998 233 234 235 236  | CCostCentreStackDecl -- A cost centre stack *declaration* CostCentreStack -- this is the declaration for a -- pre-defined singleton CCS (see -- CostCentre.lhs)  partain committed Jan 08, 1996 237   simonm committed Dec 02, 1998 238  | CSplitMarker -- Split into separate object modules here  simonpj committed Sep 26, 2001 239 240 241 242 243 244 245 246 247 248  -- C_SRT is what StgSyn.SRT gets translated to... -- we add a label for the table, and expect only the 'offset/length' form data C_SRT = NoC_SRT | C_SRT CLabel !Int{-offset-} !Int{-length-} needsSRT :: C_SRT -> Bool needsSRT NoC_SRT = False needsSRT (C_SRT _ _ _) = True  partain committed Jan 08, 1996 249 250 251 252 253 254 255 256 257 258 259 260 261 262 \end{code} About @CMacroStmt@, etc.: notionally, they all just call some arbitrary C~macro or routine, passing the @CAddrModes@ as arguments. However, we distinguish between various flavours of these things, mostly just to keep things somewhat less wild and wooly. \begin{description} \item[@CMacroStmt@:] Some {\em essential} bits of the STG execution model are done with C macros. An example is @STK_CHK@, which checks for stack-space overflow. This enumeration type lists all such macros: \begin{code} data CStmtMacro  simonm committed Dec 02, 1998 263 264 265 266 267 268 269  = ARGS_CHK -- arg satisfaction check | ARGS_CHK_LOAD_NODE -- arg check for top-level functions | UPD_CAF -- update CAF closure with indirection | UPD_BH_UPDATABLE -- eager backholing | UPD_BH_SINGLE_ENTRY -- more eager blackholing | PUSH_UPD_FRAME -- push update frame | PUSH_SEQ_FRAME -- push seq frame  simonmar committed Jun 24, 1999 270  | UPDATE_SU_FROM_UPD_FRAME -- pull Su out of the update frame  simonm committed Dec 02, 1998 271  | SET_TAG -- set TagReg if it exists  sof committed Mar 02, 2002 272 273 274  -- dataToTag# primop -- *only* used in unregisterised builds. -- (see AbsCUtils.dsCOpStmt) | DATA_TO_TAGZH  simonmar committed Mar 08, 2000 275 276 277  | REGISTER_FOREIGN_EXPORT -- register a foreign exported fun | REGISTER_IMPORT -- register an imported module  rrt committed Aug 02, 2000 278 279  | REGISTER_DIMPORT -- register an imported module from -- another DLL  simonmar committed Mar 08, 2000 280   partain committed Mar 19, 1996 281 282 283 284  | GRAN_FETCH -- for GrAnSim only -- HWL | GRAN_RESCHEDULE -- for GrAnSim only -- HWL | GRAN_FETCH_AND_RESCHEDULE -- for GrAnSim only -- HWL | THREAD_CONTEXT_SWITCH -- for GrAnSim only -- HWL  partain committed May 17, 1996 285  | GRAN_YIELD -- for GrAnSim only -- HWL  partain committed Jan 08, 1996 286 287 \end{code}  simonm committed Dec 02, 1998 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 Heap/Stack checks. There are far too many of these. \begin{code} data CCheckMacro = HP_CHK_NP -- heap/stack checks when | STK_CHK_NP -- node points to the closure | HP_STK_CHK_NP | HP_CHK_SEQ_NP -- for 'seq' style case alternatives | HP_CHK -- heap/stack checks when | STK_CHK -- node doesn't point | HP_STK_CHK -- case alternative heap checks: | HP_CHK_NOREGS -- no registers live | HP_CHK_UNPT_R1 -- R1 is boxed/unlifted | HP_CHK_UNBX_R1 -- R1 is unboxed | HP_CHK_F1 -- FloatReg1 (only) is live | HP_CHK_D1 -- DblReg1 (only) is live | HP_CHK_L1 -- LngReg1 (only) is live | HP_CHK_UT_ALT -- unboxed tuple return. | HP_CHK_GEN -- generic heap check \end{code}  partain committed Jan 08, 1996 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 \item[@CCallProfCtrMacro@:] The @String@ names a macro that, if \tr{#define}d, will bump one/some of the STG-event profiling counters. \item[@CCallProfCCMacro@:] The @String@ names a macro that, if \tr{#define}d, will perform some cost-centre-profiling-related action. \end{description} %************************************************************************ %* * \subsection[CAddrMode]{C addressing modes} %* * %************************************************************************ \begin{code} data CAddrMode  partain committed Mar 19, 1996 331  = CVal RegRelative PrimRep  partain committed Jan 08, 1996 332 333 334 335 336 337 338 339 340 341 342 343  -- On RHS of assign: Contents of Magic[n] -- On LHS of assign: location Magic[n] -- (ie at addr Magic+n) | CAddr RegRelative -- On RHS of assign: Address of Magic[n]; ie Magic+n -- n=0 gets the Magic location itself -- (NB: n=0 case superceded by CReg) -- On LHS of assign: only sensible if n=0, -- which gives the magic location itself -- (NB: superceded by CReg)  sewardj committed Feb 06, 2002 344 345 346 347  -- JRS 2002-02-05: CAddr is really scummy and should be fixed. -- The effect is that the semantics of CAddr depend on what the -- contained RegRelative is; it is decidely non-orthogonal.  partain committed Jan 08, 1996 348 349  | CReg MagicId -- To replace (CAddr MagicId 0)  simonm committed Mar 03, 1999 350  | CTemp !Unique !PrimRep -- Temporary locations  partain committed Jan 08, 1996 351 352 353 354  -- Temporaries'' correspond to local variables in C, and registers in -- native code. | CLbl CLabel -- Labels in the runtime system, etc.  partain committed Mar 19, 1996 355  PrimRep -- the kind is so we can generate accurate C decls  partain committed Jan 08, 1996 356   partain committed Mar 19, 1996 357  | CCharLike CAddrMode -- The address of a static char-like closure for  partain committed Jan 08, 1996 358  -- the specified character. It is guaranteed to be in  qrczak committed Aug 07, 2000 359  -- the range mIN_CHARLIKE..mAX_CHARLIKE  partain committed Jan 08, 1996 360 361  | CIntLike CAddrMode -- The address of a static int-like closure for the  simonm committed Dec 02, 1998 362 363  -- specified small integer. It is guaranteed to be in -- the range mIN_INTLIKE..mAX_INTLIKE  partain committed Jan 08, 1996 364   partain committed Mar 19, 1996 365  | CLit Literal  simonmar committed Jun 24, 1999 366   simonm committed Dec 02, 1998 367 368 369 370 371 372 373 374  | CJoinPoint -- This is used as the amode of a let-no-escape-bound -- variable. VirtualSpOffset -- Sp value after any volatile free vars -- of the rhs have been saved on stack. -- Just before the code for the thing is jumped to, -- Sp will be set to this value, -- and then any stack-passed args pushed, -- then the code for this thing will be entered  partain committed Jan 08, 1996 375  | CMacroExpr  simonm committed Dec 02, 1998 376  !PrimRep -- the kind of the result  partain committed Jan 08, 1996 377  CExprMacro -- the macro to generate a value  partain committed Mar 19, 1996 378  [CAddrMode] -- and its arguments  sewardj committed Dec 05, 2001 379   sewardj committed Dec 06, 2001 380  | CBytesPerWord -- Word size, in bytes, on this platform  simonmar committed Jan 02, 2002 381 382  -- required for: half-word loads (used in fishing tags -- out of info tables), and sizeofByteArray#.  partain committed Jan 08, 1996 383 384 385 386 387 388 389 \end{code} Various C macros for values which are dependent on the back-end layout. \begin{code} data CExprMacro  simonm committed Dec 02, 1998 390 391 392  = ENTRY_CODE | ARG_TAG -- stack argument tagging | GET_TAG -- get current constructor tag  simonmar committed Jun 24, 1999 393  | UPD_FRAME_UPDATEE  simonmar committed Jul 06, 2000 394  | CCS_HDR  simonmar committed Aug 02, 2002 395 396 397  | BYTE_ARR_CTS -- used when passing a ByteArray# to a ccall | PTRS_ARR_CTS -- similarly for an Array# | ForeignObj_CLOSURE_DATA -- and again for a ForeignObj#  partain committed Jan 08, 1996 398 399 \end{code}  simonm committed Dec 02, 1998 400 401 Convenience functions:  partain committed Jan 08, 1996 402 403 404 \begin{code} mkIntCLit :: Int -> CAddrMode mkIntCLit i = CLit (mkMachInt (toInteger i))  simonm committed Dec 02, 1998 405   simonmar committed Apr 29, 2002 406 mkCString :: FastString -> CAddrMode  simonmar committed Jun 24, 1999 407 408 mkCString s = CLit (MachStr s)  simonm committed Dec 02, 1998 409 410 411 412 413 mkCCostCentre :: CostCentre -> CAddrMode mkCCostCentre cc = CLbl (mkCC_Label cc) DataPtrRep mkCCostCentreStack :: CostCentreStack -> CAddrMode mkCCostCentreStack ccs = CLbl (mkCCS_Label ccs) DataPtrRep  partain committed Jan 08, 1996 414 415 416 417 418 419 420 421 422 423 \end{code} %************************************************************************ %* * \subsection[RegRelative]{@RegRelatives@: ???} %* * %************************************************************************ \begin{code} data RegRelative  simonmar committed Oct 12, 2000 424 425 426  = HpRel FastInt -- } | SpRel FastInt -- }- offsets in StgWords | NodeRel FastInt -- }  simonmar committed Jun 24, 1999 427 428  | CIndex CAddrMode CAddrMode PrimRep -- pointer arithmetic :-) -- CIndex a b k === (k*)a[b]  partain committed Jan 08, 1996 429 430 431 432 433  data ReturnInfo = DirectReturn -- Jump directly, if possible | StaticVectoredReturn Int -- Fixed tag, starting at zero | DynamicVectoredReturn CAddrMode -- Dynamic tag given by amode, starting at zero  simonm committed Dec 02, 1998 434 435 436 437  hpRel :: VirtualHeapOffset -- virtual offset of Hp -> VirtualHeapOffset -- virtual offset of The Thing -> RegRelative -- integer offset  sewardj committed Oct 12, 2000 438 hpRel hp off = HpRel (iUnbox (hp - off))  simonm committed Dec 02, 1998 439 440 441 442  spRel :: VirtualSpOffset -- virtual offset of Sp -> VirtualSpOffset -- virtual offset of The Thing -> RegRelative -- integer offset  sewardj committed Oct 12, 2000 443 spRel sp off = SpRel (iUnbox (spRelToInt sp off))  simonm committed Dec 02, 1998 444 445 446  nodeRel :: VirtualHeapOffset -> RegRelative  sewardj committed Oct 12, 2000 447 nodeRel off = NodeRel (iUnbox off)  simonm committed Dec 02, 1998 448   partain committed Jan 08, 1996 449 450 451 452 \end{code} %************************************************************************ %* *  simonmar committed Jun 24, 1999 453 \subsection[Liveness]{Liveness Masks}  partain committed Jan 08, 1996 454 455 456 %* * %************************************************************************  simonm committed Dec 02, 1998 457 458 459 We represent liveness bitmaps as a BitSet (whose internal representation really is a bitmap). These are pinned onto case return vectors to indicate the state of the stack for the garbage collector.  partain committed Jan 08, 1996 460   ken committed Jul 24, 2001 461 462 463 464 465 466 467 468 In the compiled program, liveness bitmaps that fit inside a single word (StgWord) are stored as a single word, while larger bitmaps are stored as a pointer to an array of words. When we compile via C (especially when we bootstrap via HC files), we generate identical C code regardless of whether words are 32- or 64-bit on the target machine, by postponing the decision of how to store each liveness bitmap to C compilation time (or rather, C preprocessing time).  simonm committed Dec 02, 1998 469 470 \begin{code} type LivenessMask = [BitSet]  partain committed Jan 08, 1996 471   ken committed Jul 24, 2001 472 data Liveness = Liveness CLabel LivenessMask  simonm committed Dec 02, 1998 473 \end{code}  partain committed Jan 08, 1996 474   simonm committed Dec 02, 1998 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 %************************************************************************ %* * \subsection[HeapOffset]{@Heap Offsets@} %* * %************************************************************************ This used to be a grotesquely complicated datatype in an attempt to hide the details of header sizes from the compiler itself. Now these constants are imported from the RTS, and we deal in real Ints. \begin{code} type HeapOffset = Int -- ToDo: remove type VirtualHeapOffset = HeapOffset type VirtualSpOffset = Int type HpRelOffset = HeapOffset type SpRelOffset = Int \end{code} %************************************************************************ %* * \subsection[MagicId]{@MagicIds@: registers and such} %* * %************************************************************************  partain committed Jan 08, 1996 500 501 502 503 504 505 506  \begin{code} data MagicId = BaseReg -- mentioned only in nativeGen -- Argument and return registers | VanillaReg -- pointers, unboxed ints and chars  simonm committed Dec 02, 1998 507  PrimRep  simonmar committed Oct 12, 2000 508  FastInt -- its number (1 .. mAX_Vanilla_REG)  partain committed Jan 08, 1996 509   simonm committed Dec 02, 1998 510  | FloatReg -- single-precision floating-point registers  simonmar committed Oct 12, 2000 511  FastInt -- its number (1 .. mAX_Float_REG)  partain committed Jan 08, 1996 512   simonm committed Dec 02, 1998 513  | DoubleReg -- double-precision floating-point registers  simonmar committed Oct 12, 2000 514  FastInt -- its number (1 .. mAX_Double_REG)  partain committed Jan 08, 1996 515   simonm committed Dec 02, 1998 516 517 518 519 520 521 522 523 524  -- STG registers | Sp -- Stack ptr; points to last occupied stack location. | Su -- Stack update frame pointer | SpLim -- Stack limit | Hp -- Heap ptr; points to last occupied heap location. | HpLim -- Heap limit register | CurCostCentre -- current cost centre register. | VoidReg -- see "VoidPrim" type; just a placeholder; -- no actual register  sof committed Aug 14, 1998 525 526  | LongReg -- long int registers (64-bit, really) PrimRep -- Int64Rep or Word64Rep  simonmar committed Oct 12, 2000 527  FastInt -- its number (1 .. mAX_Long_REG)  sof committed Aug 14, 1998 528   simonmar committed May 15, 2000 529 530  | CurrentTSO -- pointer to current thread's TSO | CurrentNursery -- pointer to allocation area  simonmar committed Nov 08, 2001 531  | HpAlloc -- allocation count for heap check failure  simonmar committed May 15, 2000 532   partain committed Jan 08, 1996 533   sewardj committed Oct 12, 2000 534 535 node = VanillaReg PtrRep (_ILIT 1) -- A convenient alias for Node tagreg = VanillaReg WordRep (_ILIT 2) -- A convenient alias for TagReg  partain committed Apr 05, 1996 536   simonmar committed Nov 02, 1999 537 nodeReg = CReg node  partain committed Jan 08, 1996 538 539 540 541 542 543 \end{code} We need magical @Eq@ because @VanillaReg@s come in multiple flavors. \begin{code} instance Eq MagicId where  simonmar committed Oct 12, 2000 544  reg1 == reg2 = tag reg1 ==# tag reg2  partain committed Jun 11, 1996 545  where  simonmar committed Oct 12, 2000 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563  tag BaseReg = (_ILIT(0) :: FastInt) tag Sp = _ILIT(1) tag Su = _ILIT(2) tag SpLim = _ILIT(3) tag Hp = _ILIT(4) tag HpLim = _ILIT(5) tag CurCostCentre = _ILIT(6) tag VoidReg = _ILIT(7) tag (VanillaReg _ i) = _ILIT(8) +# i tag (FloatReg i) = _ILIT(8) +# maxv +# i tag (DoubleReg i) = _ILIT(8) +# maxv +# maxf +# i tag (LongReg _ i) = _ILIT(8) +# maxv +# maxf +# maxd +# i maxv = iUnbox mAX_Vanilla_REG maxf = iUnbox mAX_Float_REG maxd = iUnbox mAX_Double_REG  partain committed Jan 08, 1996 564 565 566 567 568 \end{code} Returns True for any register that {\em potentially} dies across C calls (or anything near equivalent). We just say @True@ and let the (machine-specific) registering macros sort things out...  simonm committed Dec 02, 1998 569   partain committed Jan 08, 1996 570 571 \begin{code} isVolatileReg :: MagicId -> Bool  partain committed Mar 19, 1996 572 isVolatileReg any = True  partain committed Jan 08, 1996 573 \end{code}`