[project @ 1999-04-29 11:53:12 by simonpj]
[ghc-hetmet.git] / ghc / tests / programs / jeff-bug / Cell.hs
1 module Cell where
2
3 import Register
4 import Words
5
6 -- Begin Signature: Cell ----------------------------------------------
7 {-
8
9 Cells are intended to be used to represent the source and destination
10 operands in machine instructions.  Consider, for example:
11         
12         r1=? <- r20=15 + 8
13
14 Here the first cell (r1=?) is a register reference, and its value is
15 not known yet.  The source cell r20=15 is a register reference with 
16 its value calculated.  8 is the other source operand --- in this 
17 case a constant.  The Cell class hopes to capture this notion, while
18 allowing you freedom to define richer Cell-like structures.
19
20 The Cell's interface supports register references, constants,
21 PCs, speculative PCs and predicates.
22
23 See the DLX_Cell module for a concrete instance
24
25 Currently several of the Cell methods overlap with each other ---- 
26 Eventually we will slim the methods to the minimum set.
27 -}
28
29
30 class Cell c where
31
32   -- return a PC register reference with no value
33   pcNothing     :: (Register r,Word w) => c r w
34
35   -- return the value within the cell (undefined if no value exists)
36   getVal        :: (Register r,Word w) => c r w -> w
37
38   -- update the value within the cell
39   putVal        :: (Register r,Word w) => c r w -> Maybe w -> c r w
40
41   -- place the cell in an invalid state 
42   invalidate    :: (Register r,Word w) => c r w -> c r w
43
44   -- is the cell a register reference?
45   isReg         :: (Register r,Word w) => c r w -> Bool
46
47   -- is the cell a PC register reference?
48   isPC          :: (Register r,Word w) => c r w -> Bool
49
50   -- is the cell a speculative PC register reference?
51   isSpecPC      :: (Register r,Word w) => c r w -> Bool
52
53   -- is the cell indicates a location in memory?
54   isLoc         :: (Register r,Word w) => c r w -> Bool
55
56   -- is the cell  a constant value?
57   isVal         :: (Register r,Word w) => c r w -> Bool
58
59   -- is the cell in an invalide state?
60   isInv         :: (Register r,Word w) => c r w -> Bool
61
62   -- is the value of the cell is known?
63   --    isVal (r2=6) = True
64   --    isVal (r2=?) = False
65   isAss         :: (Register r,Word w) => c r w -> Bool
66
67   -- is the cell a predicate register reference?
68   isPred        :: (Register r,Word w) => c r w -> Bool
69
70   -- has the value been calculated?  (ie. isAss || isInv)
71   isComputed    :: (Register r,Word w) => c r w -> Bool
72
73   -- are the two cells both refering to the same register?
74   sameLoc       :: (Register r,Word w) => c r w -> c r w -> Bool
75
76   -- true if sameLoc is true and neither cell is invalid
77   cellHazard    :: (Register r,Word w) => c r w -> c r w -> Bool
78
79   -- get the register reference
80   getReg        :: (Register r,Word w) => c r w -> r
81
82   -- construct a cell with a memory reference
83   loc           :: Word w => w -> c r w
84
85   isPred x = False
86
87 -- End Signature: Cell ----------------------------------------------
88
89
90
91